libdballe  8.6
importer.h
1 #ifndef DBALLE_IMPORTER_H
2 #define DBALLE_IMPORTER_H
3 
4 #include <dballe/fwd.h>
5 #include <vector>
6 #include <memory>
7 #include <string>
8 #include <cstdio>
9 #include <functional>
10 
11 namespace wreport {
12 struct Bulletin;
13 }
14 
15 namespace dballe {
16 
25 {
26 public:
27  bool simplified = true;
28 
29  bool operator==(const ImporterOptions&) const;
30  bool operator!=(const ImporterOptions&) const;
31 
33  void print(FILE* out);
34 
36  std::string to_string() const;
37 
39  static std::unique_ptr<ImporterOptions> create();
40 
42  static std::unique_ptr<ImporterOptions> create(const std::string& s);
43 
45  static const ImporterOptions defaults;
46 
47  friend class Importer;
48 
49 protected:
50  ImporterOptions() = default;
51  ImporterOptions(const std::string& s);
52  ImporterOptions(const ImporterOptions&) = default;
53  ImporterOptions(ImporterOptions&&) = default;
54  ImporterOptions& operator=(const ImporterOptions&) = default;
55  ImporterOptions& operator=(ImporterOptions&&) = default;
56 };
57 
58 
62 class Importer
63 {
64 protected:
65  ImporterOptions opts;
66 
67  Importer(const ImporterOptions& opts);
68 
69 public:
70  Importer(const Importer&) = delete;
71  Importer(Importer&&) = delete;
72  virtual ~Importer();
73 
74  Importer& operator=(const Importer&) = delete;
75  Importer& operator=(Importer&&) = delete;
76 
80  virtual Encoding encoding() const = 0;
81 
90  std::vector<std::shared_ptr<Message>> from_binary(const BinaryMessage& msg) const;
91 
95  virtual std::vector<std::shared_ptr<Message>> from_bulletin(const wreport::Bulletin& msg) const = 0;
96 
109  virtual bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::unique_ptr<Message>)> dest) const = 0;
110 
119  static std::unique_ptr<Importer> create(Encoding type, const ImporterOptions& opts=ImporterOptions::defaults);
120 
129  static std::unique_ptr<Importer> create(Encoding type, const std::string& opts);
130 };
131 
132 }
133 
134 #endif
dballe::ImporterOptions::create
static std::unique_ptr< ImporterOptions > create()
Create with default values.
dballe::Importer
Message importer interface.
Definition: importer.h:62
dballe::Importer::encoding
virtual Encoding encoding() const =0
Return the encoding for this importer.
dballe::Importer::from_binary
std::vector< std::shared_ptr< Message > > from_binary(const BinaryMessage &msg) const
Decode a message from its raw encoded representation.
wreport::Bulletin
dballe::Importer::from_bulletin
virtual std::vector< std::shared_ptr< Message > > from_bulletin(const wreport::Bulletin &msg) const =0
Import a decoded BUFR/CREX message.
dballe::BinaryMessage
Binary message.
Definition: file.h:130
dballe::Importer::foreach_decoded
virtual bool foreach_decoded(const BinaryMessage &msg, std::function< bool(std::unique_ptr< Message >)> dest) const =0
Decode a message from its raw encoded representation, calling dest on each resulting Message.
dballe::ImporterOptions::to_string
std::string to_string() const
Generate a string summary of import options.
dballe::ImporterOptions::defaults
static const ImporterOptions defaults
Default importer options.
Definition: importer.h:45
dballe::ImporterOptions::print
void print(FILE *out)
Print a summary of the options to out.
dballe::Importer::create
static std::unique_ptr< Importer > create(Encoding type, const ImporterOptions &opts=ImporterOptions::defaults)
Instantiate an importer.
dballe::ImporterOptions
Options to control message import.
Definition: importer.h:24