libdballe  9.11
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  enum class DomainErrors
30  {
31  THROW = 0,
32  UNSET = 1,
33  CLAMP = 2,
34  TAG = 3,
35  } domain_errors = DomainErrors::THROW;
36 
37 
38  bool operator==(const ImporterOptions&) const;
39  bool operator!=(const ImporterOptions&) const;
40 
42  void print(FILE* out);
43 
45  std::string to_string() const;
46 
48  static std::unique_ptr<ImporterOptions> create();
49 
51  static std::unique_ptr<ImporterOptions> create(const std::string& s);
52 
54  static const ImporterOptions defaults;
55 
56  friend class Importer;
57 
58 protected:
59  ImporterOptions() = default;
60  ImporterOptions(const std::string& s);
61  ImporterOptions(const ImporterOptions&) = default;
62  ImporterOptions(ImporterOptions&&) = default;
63  ImporterOptions& operator=(const ImporterOptions&) = default;
64  ImporterOptions& operator=(ImporterOptions&&) = default;
65 };
66 
67 
71 class Importer
72 {
73 protected:
74  ImporterOptions opts;
75 
76  Importer(const ImporterOptions& opts);
77 
78 public:
79  Importer(const Importer&) = delete;
80  Importer(Importer&&) = delete;
81  virtual ~Importer();
82 
83  Importer& operator=(const Importer&) = delete;
84  Importer& operator=(Importer&&) = delete;
85 
89  virtual Encoding encoding() const = 0;
90 
99  std::vector<std::shared_ptr<Message>> from_binary(const BinaryMessage& msg) const;
100 
104  virtual std::vector<std::shared_ptr<Message>> from_bulletin(const wreport::Bulletin& msg) const;
105 
118  virtual bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::shared_ptr<Message>)> dest) const = 0;
119 
128  static std::unique_ptr<Importer> create(Encoding type, const ImporterOptions& opts=ImporterOptions::defaults);
129 
138  static std::unique_ptr<Importer> create(Encoding type, const std::string& opts);
139 };
140 
141 
143 {
144 public:
145  using Importer::Importer;
146 
150  std::vector<std::shared_ptr<Message>> from_bulletin(const wreport::Bulletin& msg) const override = 0;
151 };
152 
153 }
154 
155 #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:130
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:71
static std::unique_ptr< ImporterOptions > create()
Create with default values.
Definition: cmdline.h:18
Definition: importer.h:142
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:54
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.