libdballe 9.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
11namespace wreport {
12struct Bulletin;
13}
14
15namespace dballe {
16
25{
26public:
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
55
56 friend class Importer;
57
58protected:
59 ImporterOptions() = default;
60 ImporterOptions(const std::string& s);
61 ImporterOptions(const ImporterOptions&) = default;
63 ImporterOptions& operator=(const ImporterOptions&) = default;
64 ImporterOptions& operator=(ImporterOptions&&) = default;
65};
66
67
72{
73protected:
74 ImporterOptions opts;
75
76 Importer(const ImporterOptions& opts);
77
78public:
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{
144public:
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
Binary message.
Definition: file.h:131
Definition: importer.h:143
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:54
std::string to_string() const
Generate a string summary of import options.
Message importer interface.
Definition: importer.h:72
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.