libdballe  7.29
msg.h
1 #ifndef DBA_MSG_H
2 #define DBA_MSG_H
3 
4 #include <dballe/message.h>
5 #include <dballe/var.h>
6 #include <dballe/core/defs.h>
7 #include <dballe/core/matcher.h>
8 #include <dballe/msg/vars.h>
9 #include <stdio.h>
10 #include <vector>
11 #include <memory>
12 #include <iosfwd>
13 
14 struct lua_State;
15 
16 namespace dballe {
17 struct Record;
18 struct CSVReader;
19 struct CSVWriter;
20 
21 namespace msg {
22 struct Context;
23 
29 Messages messages_from_csv(CSVReader& in);
30 
34 void messages_to_csv(const Messages& msgs, CSVWriter& out);
35 
36 }
37 
41 enum MsgType {
55 };
56 
65 const char* msg_type_name(MsgType type);
66 
70 class Msg : public Message
71 {
72 protected:
76  int find_index(const Level& lev, const Trange& tr) const;
77 
79  std::string m_rep_memo;
86 
87 public:
90 
92  std::vector<msg::Context*> data;
93 
99  Msg();
100  ~Msg();
101 
102  Msg(const Msg& m);
103  Msg& operator=(const Msg& m);
104 
110  static const Msg& downcast(const Message& o);
111 
117  static Msg& downcast(Message& o);
118 
119 
120  std::unique_ptr<Message> clone() const override;
121  Datetime get_datetime() const override { return m_datetime; }
122 
123  const wreport::Var* get(wreport::Varcode code, const Level& lev, const Trange& tr) const override;
124 
125  void print(FILE* out) const override;
126  unsigned diff(const Message& msg) const override;
127 
128  void set_rep_memo(const std::string& r) { m_rep_memo = r; }
129  void set_coords(const Coords& c) { m_coords = c; }
130  void set_ident(const Ident& i) { m_ident = i; }
131  void set_datetime(const Datetime& dt) { m_datetime = dt; }
132 
134  void clear();
135 
141  void add_context(std::unique_ptr<msg::Context>&& ctx);
142 
148  bool remove_context(const Level& lev, const Trange& tr);
149 
160  const msg::Context* find_context(const Level& lev, const Trange& tr) const;
161 
168  const msg::Context* find_station_context() const;
169 
180  msg::Context* edit_context(const Level& lev, const Trange& tr);
181 
193  msg::Context& obtain_context(const Level& lev, const Trange& tr);
194 
196  msg::Context& obtain_station_context();
197 
210  wreport::Var* edit(wreport::Varcode code, const Level& lev, const Trange& tr);
211 
224  bool remove(wreport::Varcode code, const Level& lev, const Trange& tr);
225 
234  const wreport::Var* find_by_id(int id) const;
235 
244  const msg::Context* find_context_by_id(int id) const;
245 
254  wreport::Var* edit_by_id(int id);
255 
269  void set(const wreport::Var& var, wreport::Varcode code, const Level& lev, const Trange& tr);
270 
279  void set_by_id(const wreport::Var& var, int shortcut);
280 
293  void set(std::unique_ptr<wreport::Var>&& var, const Level& lev, const Trange& tr);
294 
311  void seti(wreport::Varcode code, int val, int conf, const Level& lev, const Trange& tr);
312 
329  void setd(wreport::Varcode code, double val, int conf, const Level& lev, const Trange& tr);
330 
347  void setc(wreport::Varcode code, const char* val, int conf, const Level& lev, const Trange& tr);
348 
353  //void filter(const Record& filter, Msg& dest) const;
354 
363  void sounding_pack_levels(Msg& dst) const;
364 
365 #if 0
366 
375  void sounding_unpack_levels(Msg& dst) const;
376 #endif
377 
385  bool from_csv(CSVReader& in);
386 
388  void to_csv(CSVWriter& out) const;
389 
391  static void csv_header(CSVWriter& out);
392 
396  static MsgType type_from_repmemo(const char* repmemo);
397 
401  static const char* repmemo_from_type(MsgType type);
402 
403 #include <dballe/msg/msg-extravars.h>
404 
405 
409  void lua_push(struct lua_State* L);
410 
416  static Msg* lua_check(struct lua_State* L, int idx);
417 };
418 
422 struct MatchedMsg : public Matched
423 {
424  const Msg& m;
425 
426  MatchedMsg(const Msg& r);
427  ~MatchedMsg();
428 
429  matcher::Result match_var_id(int val) const override;
430  matcher::Result match_station_id(int val) const override;
431  matcher::Result match_station_wmo(int block, int station=-1) const override;
432  matcher::Result match_datetime(const DatetimeRange& range) const override;
433  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
434  matcher::Result match_rep_memo(const char* memo) const override;
435 };
436 
440 struct MatchedMessages : public Matched
441 {
442  const Messages& m;
443 
444  MatchedMessages(const Messages& m);
445  ~MatchedMessages();
446 
447  matcher::Result match_var_id(int val) const override;
448  matcher::Result match_station_id(int val) const override;
449  matcher::Result match_station_wmo(int block, int station=-1) const override;
450  matcher::Result match_datetime(const DatetimeRange& range) const override;
451  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
452  matcher::Result match_rep_memo(const char* memo) const override;
453 };
454 
455 }
456 #endif
matcher::Result match_rep_memo(const char *memo) const override
Match rep_memo.
static void csv_header(CSVWriter &out)
Output the CSV header.
void sounding_pack_levels(Msg &dst) const
Copy to dest all the variable in this message that match filter TODO: to be implemented.
Synop measured data.
Definition: msg.h:43
Metar data.
Definition: msg.h:52
wreport::Var * edit(wreport::Varcode code, const Level &lev, const Trange &tr)
Find a variable given its description.
void seti(wreport::Varcode code, int val, int conf, const Level &lev, const Trange &tr)
Add or replace an integer value in the dba_msg.
Temp ship sounding data.
Definition: msg.h:46
Match adapter for Messages.
Definition: msg.h:440
void setc(wreport::Varcode code, const char *val, int conf, const Level &lev, const Trange &tr)
Add or replace a string value in the dba_msg.
Data from unspecified source.
Definition: msg.h:42
matcher::Result match_coords(const LatRange &latrange, const LonRange &lonrange) const override
Match coordinates, with bounds in 1/100000 of degree.
Common interface for things that are matched.
Definition: matcher.h:31
Storage for related physical data.
Definition: msg.h:70
msg::Context * edit_context(const Level &lev, const Trange &tr)
Find a msg::Context given its description.
Create wreport variables from the DB-All.e B table.
Pilot sounding data.
Definition: msg.h:44
Shortcut IDs and functions to quickly refer to commonly used values inside a dballe::msg::Msg.
Coordinates.
Definition: types.h:337
unsigned diff(const Message &msg) const override
Compute the differences between two Messages.
wreport::Var * edit_by_id(int id)
Find a datum given its shortcut ID.
matcher::Result match_coords(const LatRange &latrange, const LonRange &lonrange) const override
Match coordinates, with bounds in 1/100000 of degree.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
A bulletin that has been decoded and physically interpreted.
Definition: message.h:28
MsgType type
Source of the data.
Definition: msg.h:89
Acars airplane data.
Definition: msg.h:49
std::vector< msg::Context * > data
Context in the message.
Definition: msg.h:92
static Msg * lua_check(struct lua_State *L, int idx)
Check that the element at idx is a dba_msg.
static const char * repmemo_from_type(MsgType type)
Get the report code corresponding to the given message source type.
const msg::Context * find_context(const Level &lev, const Trange &tr) const
Find a msg::Context given its description.
msg::Context & obtain_station_context()
Shortcut to obtain_context(Level(), Trange());.
void set_by_id(const wreport::Var &var, int shortcut)
Add or replace a value.
matcher::Result match_datetime(const DatetimeRange &range) const override
Match datetime.
Airep airplane data.
Definition: msg.h:47
Ident m_ident
Identifier of the contents originator.
Definition: msg.h:83
matcher::Result match_station_id(int val) const override
Match station ID.
const wreport::Var * find_by_id(int id) const
Find a datum given its shortcut ID.
std::string m_rep_memo
Sensor network of origin of the Msg contents.
Definition: msg.h:79
Vertical level or layer.
Definition: types.h:532
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: core/defs.h:19
matcher::Result match_rep_memo(const char *memo) const override
Match rep_memo.
Msg()
Create a new dba_msg.
Match adapter for Msg.
Definition: msg.h:422
Buoy measured data.
Definition: msg.h:51
uint16_t Varcode
Range of datetimes.
Definition: types.h:272
matcher::Result match_station_wmo(int block, int station=-1) const override
Match station WMO code.
int find_index(const Level &lev, const Trange &tr) const
Return the index of the given context, or -1 if it was not found.
std::unique_ptr< Message > clone() const override
Return a copy of this message.
void print(FILE *out) const override
Print all the contents of this message to an output stream.
const msg::Context * find_context_by_id(int id) const
Find a contexts given level and timerange found in a shortcut ID.
matcher::Result match_station_wmo(int block, int station=-1) const override
Match station WMO code.
void lua_push(struct lua_State *L)
Push the variable as an object in the lua stack.
bool remove_context(const Level &lev, const Trange &tr)
Remove a context from the message.
Range of latitudes.
Definition: types.h:407
void clear()
Remove all information from Msg.
Coords m_coords
Reference coordinates for the Msg contents.
Definition: msg.h:81
Ordered collection of messages.
Definition: message.h:67
const char * msg_type_name(MsgType type)
Return a string with the name of a dba_msg_type.
matcher::Result match_var_id(int val) const override
Match variable ID.
matcher::Result match_station_id(int val) const override
Match station ID.
Datetime m_datetime
Reference time for the Msg contents.
Definition: msg.h:85
Satellite data.
Definition: msg.h:53
void set(const wreport::Var &var, wreport::Varcode code, const Level &lev, const Trange &tr)
Add or replace a value.
Date and time.
Definition: types.h:158
static const Msg & downcast(const Message &o)
Return a reference to o downcasted as a Msg.
bool from_csv(CSVReader &in)
Read data from a CSV input.
const msg::Context * find_station_context() const
Find the station info context.
Temp sounding data.
Definition: msg.h:45
void to_csv(CSVWriter &out) const
Output in CSV format.
msg::Context & obtain_context(const Level &lev, const Trange &tr)
Find a msg::Context given its description, creating it if it does not exist.
Pollution data.
Definition: msg.h:54
Ship measured data.
Definition: msg.h:50
Range of longitudes.
Definition: types.h:481
Common definitions.
static MsgType type_from_repmemo(const char *repmemo)
Get the message source type corresponding to the given report code.
Datetime get_datetime() const override
Get the reference Datetime for this message.
Definition: msg.h:121
Amdar airplane data.
Definition: msg.h:48
matcher::Result match_datetime(const DatetimeRange &range) const override
Match datetime.
matcher::Result match_var_id(int val) const override
Match variable ID.
void setd(wreport::Varcode code, double val, int conf, const Level &lev, const Trange &tr)
Add or replace a double value in the dba_msg.
void add_context(std::unique_ptr< msg::Context > &&ctx)
Add a missing context, taking care of its memory management.
MsgType
Source of the data.
Definition: msg.h:41