libdballe 9.13
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
11namespace wreport {
12struct Bulletin;
13}
14
15namespace dballe {
16
24class ImporterOptions
25{
26public:
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
56protected:
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
68class Importer
69{
70protected:
71 ImporterOptions opts;
72
73 Importer(const ImporterOptions& opts);
74
75public:
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>>
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
146class BulletinImporter : public Importer
147{
148public:
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
Binary message.
Definition file.h:135
Definition importer.h:147
std::vector< std::shared_ptr< Message > > from_bulletin(const wreport::Bulletin &msg) const override=0
Import a decoded BUFR/CREX message.
Options to control message import.
Definition importer.h:25
static std::unique_ptr< ImporterOptions > create()
Create with default values.
void print(FILE *out)
Print a summary of the options to out.
static std::unique_ptr< ImporterOptions > create(const std::string &s)
Opposite of to_string: create an Options from a string.
static const ImporterOptions defaults
Default importer options.
Definition importer.h:52
std::string to_string() const
Generate a string summary of import options.
std::vector< std::shared_ptr< Message > > from_binary(const BinaryMessage &msg) const
Decode a message from its raw encoded representation.
static std::unique_ptr< Importer > create(Encoding type, const ImporterOptions &opts=ImporterOptions::defaults)
Instantiate an importer.
static std::unique_ptr< Importer > create(Encoding type, const std::string &opts)
Instantiate an importer.
virtual std::vector< std::shared_ptr< Message > > from_bulletin(const wreport::Bulletin &msg) const
Import a decoded BUFR/CREX message.
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.
virtual Encoding encoding() const =0
Return the encoding for this importer.