libdballe  9.14
importer.h
1 #ifndef DBALLE_IMPORTER_H
2 #define DBALLE_IMPORTER_H
3 
4 #include <cstdio>
5 #include <dballe/fwd.h>
6 #include <functional>
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace wreport {
12 struct Bulletin;
13 }
14 
15 namespace dballe {
16 
25 {
26 public:
27  bool simplified = true;
28 
29  enum class DomainErrors {
30  THROW = 0,
31  UNSET = 1,
32  CLAMP = 2,
33  TAG = 3,
34  } domain_errors = DomainErrors::THROW;
35 
36  bool operator==(const ImporterOptions&) const;
37  bool operator!=(const ImporterOptions&) const;
38 
40  void print(FILE* out);
41 
43  std::string to_string() const;
44 
46  static std::unique_ptr<ImporterOptions> create();
47 
49  static std::unique_ptr<ImporterOptions> create(const std::string& s);
50 
52  static const ImporterOptions defaults;
53 
54  friend class Importer;
55 
56 protected:
57  ImporterOptions() = default;
58  ImporterOptions(const std::string& s);
59  ImporterOptions(const ImporterOptions&) = default;
60  ImporterOptions(ImporterOptions&&) = default;
61  ImporterOptions& operator=(const ImporterOptions&) = default;
62  ImporterOptions& operator=(ImporterOptions&&) = default;
63 };
64 
68 class Importer
69 {
70 protected:
71  ImporterOptions opts;
72 
73  Importer(const ImporterOptions& opts);
74 
75 public:
76  Importer(const Importer&) = delete;
77  Importer(Importer&&) = delete;
78  virtual ~Importer();
79 
80  Importer& operator=(const Importer&) = delete;
81  Importer& operator=(Importer&&) = delete;
82 
86  virtual Encoding encoding() const = 0;
87 
96  std::vector<std::shared_ptr<Message>>
97  from_binary(const BinaryMessage& msg) const;
98 
102  virtual std::vector<std::shared_ptr<Message>>
103  from_bulletin(const wreport::Bulletin& msg) const;
104 
118  virtual bool foreach_decoded(
119  const BinaryMessage& msg,
120  std::function<bool(std::shared_ptr<Message>)> dest) const = 0;
121 
130  static std::unique_ptr<Importer>
131  create(Encoding type,
133 
142  static std::unique_ptr<Importer> create(Encoding type,
143  const std::string& opts);
144 };
145 
147 {
148 public:
149  using Importer::Importer;
150 
154  std::vector<std::shared_ptr<Message>>
155  from_bulletin(const wreport::Bulletin& msg) const override = 0;
156 };
157 
158 } // namespace dballe
159 
160 #endif
std::vector< std::shared_ptr< Message > > from_binary(const BinaryMessage &msg) const
Decode a message from its raw encoded representation.
Binary message.
Definition: file.h:134
void print(FILE *out)
Print a summary of the options to out.
virtual std::vector< std::shared_ptr< Message > > from_bulletin(const wreport::Bulletin &msg) const
Import a decoded BUFR/CREX message.
Message importer interface.
Definition: importer.h:68
static std::unique_ptr< ImporterOptions > create()
Create with default values.
Definition: cmdline.h:18
Definition: importer.h:146
static std::unique_ptr< Importer > create(Encoding type, const ImporterOptions &opts=ImporterOptions::defaults)
Instantiate an importer.
Options to control message import.
Definition: importer.h:24
std::string to_string() const
Generate a string summary of import options.
virtual Encoding encoding() const =0
Return the encoding for this importer.
static const ImporterOptions defaults
Default importer options.
Definition: importer.h:52
virtual bool foreach_decoded(const BinaryMessage &msg, std::function< bool(std::shared_ptr< Message >)> dest) const =0
Decode a message from its raw encoded representation, calling dest on each resulting Message...
std::vector< std::shared_ptr< Message > > from_bulletin(const wreport::Bulletin &msg) const override=0
Import a decoded BUFR/CREX message.