libdballe  5.18
msg.h
Go to the documentation of this file.
1 /*
2  * dballe/msg - Hold an interpreted weather bulletin
3  *
4  * Copyright (C) 2005--2011 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/core/var.h>
68 #include <dballe/core/defs.h>
69 #include <dballe/core/matcher.h>
70 #include <dballe/msg/vars.h>
71 #include <stdio.h>
72 #include <vector>
73 #include <memory>
74 #include <iosfwd>
75 
76 struct lua_State;
77 
78 namespace dballe {
79 
80 struct Record;
81 struct CSVReader;
82 
83 namespace msg {
84 struct Context;
85 }
86 
90 enum MsgType {
91  MSG_GENERIC,
92  MSG_SYNOP,
93  MSG_PILOT,
94  MSG_TEMP,
95  MSG_TEMP_SHIP,
96  MSG_AIREP,
97  MSG_AMDAR,
98  MSG_ACARS,
99  MSG_SHIP,
100  MSG_BUOY,
101  MSG_METAR,
102  MSG_SAT,
103  MSG_POLLUTION
104 };
105 
114 const char* msg_type_name(MsgType type);
115 
119 class Msg
120 {
121 protected:
125  int find_index(const Level& lev, const Trange& tr) const;
126 
127 public:
129  MsgType type;
130 
132  std::vector<msg::Context*> data;
133 
139  Msg();
140  ~Msg();
141 
142  Msg(const Msg& m);
143  Msg& operator=(const Msg& m);
144 
146  void clear();
147 
153  void add_context(std::auto_ptr<msg::Context> ctx);
154 
160  bool remove_context(const Level& lev, const Trange& tr);
161 
172  const msg::Context* find_context(const Level& lev, const Trange& tr) const;
173 
180  const msg::Context* find_station_context() const;
181 
192  msg::Context* edit_context(const Level& lev, const Trange& tr);
193 
205  msg::Context& obtain_context(const Level& lev, const Trange& tr);
206 
219  const wreport::Var* find(wreport::Varcode code, const Level& lev, const Trange& tr) const;
220 
233  wreport::Var* edit(wreport::Varcode code, const Level& lev, const Trange& tr);
234 
245  const wreport::Var* find_by_id(int id) const;
246 
257  const msg::Context* find_context_by_id(int id) const;
258 
269  wreport::Var* edit_by_id(int id);
270 
284  void set(const wreport::Var& var, wreport::Varcode code, const Level& lev, const Trange& tr);
285 
294  void set_by_id(const wreport::Var& var, int shortcut);
295 
308  void set(std::auto_ptr<wreport::Var> var, const Level& lev, const Trange& tr);
309 
326  void seti(wreport::Varcode code, int val, int conf, const Level& lev, const Trange& tr);
327 
344  void setd(wreport::Varcode code, double val, int conf, const Level& lev, const Trange& tr);
345 
362  void setc(wreport::Varcode code, const char* val, int conf, const Level& lev, const Trange& tr);
363 
365  void set_date(const char* date);
366 
371  //void filter(const Record& filter, Msg& dest) const;
372 
381  void sounding_pack_levels(Msg& dst) const;
382 
383 #if 0
384 
393  void sounding_unpack_levels(Msg& dst) const;
394 #endif
395 
406  void parse_date(int* values) const;
407 
415  bool from_csv(CSVReader& in);
416 
420  void to_csv(std::ostream& out) const;
421 
423  static void csv_header(std::ostream& out);
424 
431  void print(FILE* out) const;
432 
444  unsigned diff(const Msg& msg) const;
445 
449  static MsgType type_from_repmemo(const char* repmemo);
450 
454  static const char* repmemo_from_type(MsgType type);
455 
456 #include <dballe/msg/msg-extravars.h>
457 
458 
462  void lua_push(struct lua_State* L);
463 
469  static Msg* lua_check(struct lua_State* L, int idx);
470 };
471 
476 {
477  virtual ~MsgConsumer() {}
478  virtual void operator()(std::auto_ptr<Msg>) = 0;
479 };
480 
484 struct MatchedMsg : public Matched
485 {
486  const Msg& m;
487 
488  MatchedMsg(const Msg& r);
489  ~MatchedMsg();
490 
491  virtual matcher::Result match_var_id(int val) const;
492  virtual matcher::Result match_station_id(int val) const;
493  virtual matcher::Result match_station_wmo(int block, int station=-1) const;
494  virtual matcher::Result match_date(const int* min, const int* max) const;
495  virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const;
496  virtual matcher::Result match_rep_memo(const char* memo) const;
497 };
498 
499 #if 0
500 
512 dba_err dba_msg_set_by_id(dba_msg msg, dba_var var, int id);
513 
528 dba_err dba_msg_set_nocopy_by_id(dba_msg msg, dba_var var, int id);
529 
538 dba_msg_type dba_msg_get_type(dba_msg msg);
539 #endif
540 
541 }
542 
543 // vim:set ts=4 sw=4:
544 #endif