libdballe  8.3
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  bool simplified = true;
27 
28  bool operator==(const ImporterOptions&) const;
29  bool operator!=(const ImporterOptions&) const;
30 
32  void print(FILE* out);
33 
35  std::string to_string() const;
36 
38  static std::unique_ptr<ImporterOptions> create();
39 
41  static std::unique_ptr<ImporterOptions> create(const std::string& s);
42 
44  static const ImporterOptions defaults;
45 
46  friend class Importer;
47 
48 protected:
49  ImporterOptions() = default;
50  ImporterOptions(const std::string& s);
51  ImporterOptions(const ImporterOptions&) = default;
52  ImporterOptions(ImporterOptions&&) = default;
53  ImporterOptions& operator=(const ImporterOptions&) = default;
54  ImporterOptions& operator=(ImporterOptions&&) = default;
55 };
56 
57 
61 class Importer
62 {
63 protected:
64  ImporterOptions opts;
65 
66  Importer(const ImporterOptions& opts);
67 
68 public:
69  Importer(const Importer&) = delete;
70  Importer(Importer&&) = delete;
71  virtual ~Importer();
72 
73  Importer& operator=(const Importer&) = delete;
74  Importer& operator=(Importer&&) = delete;
75 
79  virtual Encoding encoding() const = 0;
80 
89  std::vector<std::shared_ptr<Message>> from_binary(const BinaryMessage& msg) const;
90 
94  virtual std::vector<std::shared_ptr<Message>> from_bulletin(const wreport::Bulletin& msg) const = 0;
95 
108  virtual bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::unique_ptr<Message>)> dest) const = 0;
109 
118  static std::unique_ptr<Importer> create(Encoding type, const ImporterOptions& opts=ImporterOptions::defaults);
119 
128  static std::unique_ptr<Importer> create(Encoding type, const std::string& opts);
129 };
130 
131 }
132 
133 #endif
Message importer interface.
Definition: importer.h:61
static const ImporterOptions defaults
Default importer options.
Definition: importer.h:44
Definition: cmdline.h:18
Options to control message import.
Definition: importer.h:24
Binary message.
Definition: file.h:129