libdballe  7.7
msg.h
Go to the documentation of this file.
1 /*
2  * dballe/msg - Hold an interpreted weather bulletin
3  *
4  * Copyright (C) 2005--2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBA_MSG_H
23 #define DBA_MSG_H
24 
67 #include <dballe/message.h>
68 #include <dballe/var.h>
69 #include <dballe/core/defs.h>
70 #include <dballe/core/matcher.h>
71 #include <dballe/msg/vars.h>
72 #include <stdio.h>
73 #include <vector>
74 #include <memory>
75 #include <iosfwd>
76 
77 struct lua_State;
78 
79 namespace dballe {
80 
81 struct Record;
82 struct CSVReader;
83 
84 namespace msg {
85 struct Context;
86 
92 Messages messages_from_csv(CSVReader& in);
93 
97 void messages_to_csv(const Messages& msgs, std::ostream& out);
98 
99 }
100 
104 enum MsgType {
118 };
119 
128 const char* msg_type_name(MsgType type);
129 
133 class Msg : public Message
134 {
135 protected:
139  int find_index(const Level& lev, const Trange& tr) const;
140 
142  std::string m_network;
149 
150 public:
153 
155  std::vector<msg::Context*> data;
156 
162  Msg();
163  ~Msg();
164 
165  Msg(const Msg& m);
166  Msg& operator=(const Msg& m);
167 
173  static const Msg& downcast(const Message& o);
174 
180  static Msg& downcast(Message& o);
181 
182 
183  std::unique_ptr<Message> clone() const override;
184  Datetime get_datetime() const override { return m_datetime; }
185 
186  const wreport::Var* get(wreport::Varcode code, const Level& lev, const Trange& tr) const override;
187 
188  void print(FILE* out) const override;
189  unsigned diff(const Message& msg) const override;
190 
191  void set_datetime(const Datetime& dt) { m_datetime = dt; }
192 
194  void clear();
195 
201  void add_context(std::unique_ptr<msg::Context>&& ctx);
202 
208  bool remove_context(const Level& lev, const Trange& tr);
209 
220  const msg::Context* find_context(const Level& lev, const Trange& tr) const;
221 
228  const msg::Context* find_station_context() const;
229 
240  msg::Context* edit_context(const Level& lev, const Trange& tr);
241 
253  msg::Context& obtain_context(const Level& lev, const Trange& tr);
254 
256  msg::Context& obtain_station_context();
257 
270  wreport::Var* edit(wreport::Varcode code, const Level& lev, const Trange& tr);
271 
284  bool remove(wreport::Varcode code, const Level& lev, const Trange& tr);
285 
296  const wreport::Var* find_by_id(int id) const;
297 
308  const msg::Context* find_context_by_id(int id) const;
309 
320  wreport::Var* edit_by_id(int id);
321 
335  void set(const wreport::Var& var, wreport::Varcode code, const Level& lev, const Trange& tr);
336 
345  void set_by_id(const wreport::Var& var, int shortcut);
346 
359  void set(std::unique_ptr<wreport::Var>&& var, const Level& lev, const Trange& tr);
360 
377  void seti(wreport::Varcode code, int val, int conf, const Level& lev, const Trange& tr);
378 
395  void setd(wreport::Varcode code, double val, int conf, const Level& lev, const Trange& tr);
396 
413  void setc(wreport::Varcode code, const char* val, int conf, const Level& lev, const Trange& tr);
414 
419  //void filter(const Record& filter, Msg& dest) const;
420 
429  void sounding_pack_levels(Msg& dst) const;
430 
431 #if 0
432 
441  void sounding_unpack_levels(Msg& dst) const;
442 #endif
443 
451  bool from_csv(CSVReader& in);
452 
456  void to_csv(std::ostream& out) const;
457 
459  static void csv_header(std::ostream& out);
460 
464  static MsgType type_from_repmemo(const char* repmemo);
465 
469  static const char* repmemo_from_type(MsgType type);
470 
471 #include <dballe/msg/msg-extravars.h>
472 
473 
477  void lua_push(struct lua_State* L);
478 
484  static Msg* lua_check(struct lua_State* L, int idx);
485 };
486 
490 struct MatchedMsg : public Matched
491 {
492  const Msg& m;
493 
494  MatchedMsg(const Msg& r);
495  ~MatchedMsg();
496 
497  matcher::Result match_var_id(int val) const override;
498  matcher::Result match_station_id(int val) const override;
499  matcher::Result match_station_wmo(int block, int station=-1) const override;
500  matcher::Result match_datetime(const DatetimeRange& range) const override;
501  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
502  matcher::Result match_rep_memo(const char* memo) const override;
503 };
504 
508 struct MatchedMessages : public Matched
509 {
510  const Messages& m;
511 
512  MatchedMessages(const Messages& m);
513  ~MatchedMessages();
514 
515  matcher::Result match_var_id(int val) const override;
516  matcher::Result match_station_id(int val) const override;
517  matcher::Result match_station_wmo(int block, int station=-1) const override;
518  matcher::Result match_datetime(const DatetimeRange& range) const override;
519  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
520  matcher::Result match_rep_memo(const char* memo) const override;
521 };
522 
523 }
524 #endif
matcher::Result match_rep_memo(const char *memo) const override
Match rep_memo.
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:106
Metar data.
Definition: msg.h:115
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:109
void to_csv(std::ostream &out) const
Output in CSV format.
Match adapter for Messages.
Definition: msg.h:508
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:105
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:133
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:107
Shortcut IDs and functions to quickly refer to commonly used values inside a ::dba_msg.
Coordinates.
Definition: types.h:320
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:565
A bulletin that has been decoded and physically interpreted.
Definition: message.h:25
MsgType type
Source of the data.
Definition: msg.h:152
Acars airplane data.
Definition: msg.h:112
std::vector< msg::Context * > data
Context in the message.
Definition: msg.h:155
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.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
matcher::Result match_datetime(const DatetimeRange &range) const override
Match datetime.
Airep airplane data.
Definition: msg.h:110
Ident m_ident
Identifier of the contents originator.
Definition: msg.h:146
matcher::Result match_station_id(int val) const override
Match station ID.
static void csv_header(std::ostream &out)
Output the CSV header.
const wreport::Var * find_by_id(int id) const
Find a datum given its shortcut ID.
Vertical level or layer.
Definition: types.h:515
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:490
Buoy measured data.
Definition: msg.h:114
Range of datetimes.
Definition: types.h:255
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:390
void clear()
Remove all information from Msg.
Coords m_coords
Reference coordinates for the Msg contents.
Definition: msg.h:144
Ordered collection of messages.
Definition: message.h:64
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:148
Satellite data.
Definition: msg.h:116
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:147
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:108
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:117
Ship measured data.
Definition: msg.h:113
std::string m_network
Sensor network of origin of the Msg contents.
Definition: msg.h:142
Range of longitudes.
Definition: types.h:464
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:184
Amdar airplane data.
Definition: msg.h:111
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:104