libdballe 9.6
wr_codec.h
1#ifndef DBALLE_MSG_WR_CODEC_H
2#define DBALLE_MSG_WR_CODEC_H
3
4#include <dballe/importer.h>
5#include <dballe/exporter.h>
6#include <dballe/core/fwd.h>
7#include <dballe/msg/msg.h>
8#include <wreport/varinfo.h>
9#include <stdint.h>
10#include <map>
11#include <string>
12#include <functional>
13
14namespace wreport {
15struct Bulletin;
16struct Subset;
17}
18
19namespace dballe {
20namespace impl {
21namespace msg {
22
24{
25public:
27
31 std::vector<std::shared_ptr<dballe::Message>> from_bulletin(const wreport::Bulletin& msg) const override;
32
45 bool foreach_decoded_bulletin(const wreport::Bulletin& msg, std::function<bool(std::shared_ptr<dballe::Message>)> dest) const;
46};
47
49{
50public:
52 virtual ~BufrImporter();
53
54 Encoding encoding() const override { return Encoding::BUFR; }
55
56 bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::shared_ptr<dballe::Message>)> dest) const override;
57};
58
60{
61public:
63 virtual ~CrexImporter();
64
65 Encoding encoding() const override { return Encoding::CREX; }
66
67 bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::shared_ptr<dballe::Message>)> dest) const override;
68};
69
70namespace wr {
71class Template;
72}
73
75{
76public:
78
82 std::unique_ptr<wreport::Bulletin> to_bulletin(const std::vector<std::shared_ptr<dballe::Message>>& msgs) const override;
83
87 std::unique_ptr<wr::Template> infer_template(const Messages& msgs) const;
88};
89
91{
92public:
93 BufrExporter(const dballe::ExporterOptions& opts=dballe::ExporterOptions::defaults);
94 virtual ~BufrExporter();
95
96 virtual std::string to_binary(const Messages& msgs) const;
97 virtual std::unique_ptr<wreport::Bulletin> make_bulletin() const;
98};
99
101{
102public:
103 CrexExporter(const dballe::ExporterOptions& opts=dballe::ExporterOptions::defaults);
104 virtual ~CrexExporter();
105
106 virtual std::string to_binary(const Messages& msgs) const;
107 virtual std::unique_ptr<wreport::Bulletin> make_bulletin() const;
108};
109
110namespace wr {
111
112struct TemplateRegistry;
113
115{
116protected:
117 virtual void setupBulletin(wreport::Bulletin& bulletin);
118 virtual void to_subset(const Message& msg, wreport::Subset& subset);
119
120 void add(wreport::Varcode code, const msg::Context* ctx, const Shortcut& shortcut) const;
121 void add(wreport::Varcode code, const msg::Context* ctx, wreport::Varcode srccode) const;
122 void add(wreport::Varcode code, const msg::Context* ctx) const;
123 void add(wreport::Varcode code, const Values& values) const;
124 void add(wreport::Varcode code, const Values& values, const Shortcut& shortcut) const;
125 void add(wreport::Varcode code, const Shortcut& shortcut) const;
126 void add(wreport::Varcode code, wreport::Varcode srccode, const Level& level, const Trange& trange) const;
127 void add(wreport::Varcode code, const wreport::Var* var) const;
128 // Set station name, truncating it if it's too long
129 void do_station_name(wreport::Varcode dstcode) const;
130
133
134 void do_ecmwf_past_wtr() const;
135 void do_station_height() const;
136 // WMO block and station numbers
137 void do_D01001() const;
138 void do_D01004() const;
139 // Date (year, month, day)
140 void do_D01011() const;
141 // Time (hour and minute), return the hour
142 int do_D01012() const;
143 // Time (hour, minute, second)
144 void do_D01013() const;
145 // Latitude and longitude, high accuracy
146 void do_D01021() const;
147 void do_D01022() const;
148 // Latitude and longitude, coarse accuracy
149 void do_D01023() const;
150
151public:
152 const dballe::ExporterOptions& opts;
153 const Messages& msgs;
154 const Message* msg = 0; // Message being read
155 const msg::Context* c_gnd_instant = 0;
156 wreport::Subset* subset = 0; // Subset being written
157
158 Template(const dballe::ExporterOptions& opts, const Messages& msgs)
159 : opts(opts), msgs(msgs) {}
160 virtual ~Template() {}
161
162 virtual const char* name() const = 0;
163 virtual const char* description() const = 0;
164 virtual void to_bulletin(wreport::Bulletin& bulletin);
165};
166
168{
169 typedef std::function<std::unique_ptr<Template>(const dballe::ExporterOptions& opts, const Messages& msgs)> factory_func;
170
171 unsigned data_category = MISSING_INT;
172 std::string name;
173 std::string description;
174 factory_func factory;
175
176 TemplateFactory(unsigned data_category, std::string name, std::string description, factory_func factory)
177 : data_category(data_category), name(name), description(description), factory(factory) {}
178};
179
180struct TemplateRegistry : public std::map<std::string, TemplateFactory>
181{
182 static const TemplateRegistry& get();
183 static const TemplateFactory& get(const std::string& name);
184
185 void register_factory(
186 unsigned data_category,
187 const std::string& name,
188 const std::string& desc,
189 TemplateFactory::factory_func fac);
190};
191
192}
193}
194}
195}
196#endif
Binary message.
Definition: file.h:131
Definition: exporter.h:110
Definition: importer.h:143
Options to control message export.
Definition: exporter.h:25
Options to control message import.
Definition: importer.h:25
static const ImporterOptions defaults
Default importer options.
Definition: importer.h:54
Storage for related physical data.
Definition: msg.h:131
Definition: wr_codec.h:91
virtual std::unique_ptr< wreport::Bulletin > make_bulletin() const
Create a bulletin that works with this exporter.
Definition: wr_codec.h:49
Encoding encoding() const override
Return the encoding for this importer.
Definition: wr_codec.h:54
Store an array of physical data all on the same level.
Definition: context.h:24
Definition: wr_codec.h:101
virtual std::unique_ptr< wreport::Bulletin > make_bulletin() const
Create a bulletin that works with this exporter.
Definition: wr_codec.h:60
Encoding encoding() const override
Return the encoding for this importer.
Definition: wr_codec.h:65
Definition: wr_codec.h:75
std::unique_ptr< wreport::Bulletin > to_bulletin(const std::vector< std::shared_ptr< dballe::Message > > &msgs) const override
Import a decoded BUFR/CREX message.
std::unique_ptr< wr::Template > infer_template(const Messages &msgs) const
Infer a template name from the message contents.
Definition: wr_codec.h:24
std::vector< std::shared_ptr< dballe::Message > > from_bulletin(const wreport::Bulletin &msg) const override
Import a decoded BUFR/CREX message.
bool foreach_decoded_bulletin(const wreport::Bulletin &msg, std::function< bool(std::shared_ptr< dballe::Message >)> dest) const
Build Message objects a decoded bulletin, calling dest on each resulting Message.
Definition: wr_codec.h:115
const wreport::Var * find_station_var(wreport::Varcode code) const
Find a variable in c_station, or nullptr if not found.
uint16_t Varcode
Vertical level or layer.
Definition: types.h:625
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:687
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:177
Definition: shortcuts.h:12
Definition: wr_codec.h:168
Definition: wr_codec.h:181