libdballe  9.11
message.h
1 #ifndef DBALLE_MESSAGE_H
2 #define DBALLE_MESSAGE_H
3 
4 #include <dballe/fwd.h>
5 #include <dballe/types.h>
6 #include <wreport/varinfo.h>
7 #include <memory>
8 #include <iosfwd>
9 
10 namespace wreport {
11 struct Var;
12 }
13 
14 namespace dballe {
15 
28 class Message : public std::enable_shared_from_this<Message>
29 {
30 public:
31  Message() {}
32  Message(const Message&) = default;
33  virtual ~Message();
34 
35  Message& operator=(const Message& o) = default;
36  Message& operator=(Message&& o) = default;
37 
39  virtual MessageType get_type() const = 0;
40 
42  virtual Datetime get_datetime() const = 0;
43 
45  virtual Coords get_coords() const = 0;
46 
48  virtual Ident get_ident() const = 0;
49 
51  virtual std::string get_report() const = 0;
52 
54  virtual std::shared_ptr<Message> clone() const = 0;
55 
62  const wreport::Var* get(const Level& lev, const Trange& tr, wreport::Varcode code) const;
63 
70  const wreport::Var* get(const char* shortcut) const;
71 
78  const wreport::Var* get(const std::string& shortcut) const;
79 
93  void set(const Level& lev, const Trange& tr, wreport::Varcode code, const wreport::Var& var);
94 
105  void set(const Level& lev, const Trange& tr, const wreport::Var& var);
106 
119  void set(const Level& lev, const Trange& tr, std::unique_ptr<wreport::Var> var);
120 
131  void set(const char* shortcut, std::unique_ptr<wreport::Var> var);
132 
142  void set(const char* shortcut, const wreport::Var& var);
143 
147  virtual bool foreach_var(std::function<bool(const Level&, const Trange&, const wreport::Var&)>) const = 0;
148 
160  virtual std::shared_ptr<CursorStation> query_stations(const Query& query) const = 0;
161 
170  virtual std::shared_ptr<CursorStationData> query_station_data(const Query& query) const = 0;
171 
180  virtual std::shared_ptr<CursorData> query_data(const Query& query) const = 0;
181 
183  virtual void print(FILE* out) const = 0;
184 
194  virtual unsigned diff(const Message& msg) const = 0;
195 
199  static std::shared_ptr<Message> create(MessageType type);
200 
201 protected:
203  virtual const wreport::Var* get_impl(const Level& lev, const Trange& tr, wreport::Varcode code) const = 0;
204 
206  virtual void set_impl(const Level& lev, const Trange& tr, std::unique_ptr<wreport::Var> var) = 0;
207 };
208 
209 
218 const char* format_message_type(MessageType type);
219 
220 
222 std::ostream& operator<<(std::ostream&, const dballe::MessageType&);
223 
224 }
225 #endif
virtual std::string get_report() const =0
Get the report for this message.
virtual const wreport::Var * get_impl(const Level &lev, const Trange &tr, wreport::Varcode code) const =0
Implementation of get(const Level&, const Trange&, wreport::Varcode)
Common base types used by most of DB-All.e code.
virtual void print(FILE *out) const =0
Print all the contents of this message to an output stream.
virtual MessageType get_type() const =0
Return the type of the data in the message.
Coordinates.
Definition: types.h:368
virtual std::shared_ptr< CursorStationData > query_station_data(const Query &query) const =0
Query the station variables in the message.
virtual Datetime get_datetime() const =0
Get the reference Datetime for this message.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
virtual bool foreach_var(std::function< bool(const Level &, const Trange &, const wreport::Var &)>) const =0
Iterate the contents of the message.
Definition: cmdline.h:18
virtual std::shared_ptr< Message > clone() const =0
Return a copy of this message.
virtual void set_impl(const Level &lev, const Trange &tr, std::unique_ptr< wreport::Var > var)=0
Implementation of set(const Level& const Trange&, std::unique_ptr<wreport::Var>)
Vertical level or layer.
Definition: types.h:624
virtual std::shared_ptr< CursorStation > query_stations(const Query &query) const =0
Return a Cursor to access the station information in the message.
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: types.h:747
virtual Coords get_coords() const =0
Get the reference coordinates for this message.
A bulletin that has been decoded and physically interpreted.
Definition: message.h:28
uint16_t Varcode
virtual std::shared_ptr< CursorData > query_data(const Query &query) const =0
Query the variables in the message.
static std::shared_ptr< Message > create(MessageType type)
Create a new empty message.
Date and time.
Definition: types.h:164
virtual unsigned diff(const Message &msg) const =0
Compute the differences between two Messages.
virtual Ident get_ident() const =0
Get the station identifier for this message.
Query used to filter DB-All.e data.
Definition: query.h:14