libdballe 5.10
msg.h
Go to the documentation of this file.
00001 /*
00002  * dballe/msg - Hold an interpreted weather bulletin
00003  *
00004  * Copyright (C) 2005--2011  ARPA-SIM <urpsim@smr.arpa.emr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00018  *
00019  * Author: Enrico Zini <enrico@enricozini.com>
00020  */
00021 
00022 #ifndef DBA_MSG_H
00023 #define DBA_MSG_H
00024 
00067 #include <dballe/core/var.h>
00068 #include <dballe/core/defs.h>
00069 #include <dballe/core/matcher.h>
00070 #include <dballe/msg/vars.h>
00071 #include <stdio.h>
00072 #include <vector>
00073 #include <memory>
00074 #include <iosfwd>
00075 
00076 struct lua_State;
00077 
00078 namespace dballe {
00079 
00080 struct Record;
00081 struct CSVReader;
00082 
00083 namespace msg {
00084 struct Context;
00085 }
00086 
00090 enum MsgType {
00091     MSG_GENERIC,    
00092     MSG_SYNOP,      
00093     MSG_PILOT,      
00094     MSG_TEMP,       
00095     MSG_TEMP_SHIP,  
00096     MSG_AIREP,      
00097     MSG_AMDAR,      
00098     MSG_ACARS,      
00099     MSG_SHIP,       
00100     MSG_BUOY,       
00101     MSG_METAR,      
00102     MSG_SAT,        
00103     MSG_POLLUTION   
00104 };
00105 
00114 const char* msg_type_name(MsgType type);
00115 
00119 class Msg
00120 {
00121 protected:
00125     int find_index(const Level& lev, const Trange& tr) const;
00126 
00127 public:
00129     MsgType type;
00130 
00132     std::vector<msg::Context*> data;
00133 
00139     Msg();
00140     ~Msg();
00141 
00142     Msg(const Msg& m);
00143     Msg& operator=(const Msg& m);
00144 
00146     void clear();
00147 
00153     void add_context(std::auto_ptr<msg::Context> ctx);
00154 
00160     bool remove_context(const Level& lev, const Trange& tr);
00161 
00172     const msg::Context* find_context(const Level& lev, const Trange& tr) const;
00173 
00180     const msg::Context* find_station_context() const;
00181 
00192     msg::Context* edit_context(const Level& lev, const Trange& tr);
00193 
00205     msg::Context& obtain_context(const Level& lev, const Trange& tr);
00206 
00219     const wreport::Var* find(wreport::Varcode code, const Level& lev, const Trange& tr) const;
00220 
00233     wreport::Var* edit(wreport::Varcode code, const Level& lev, const Trange& tr);
00234 
00245     const wreport::Var* find_by_id(int id) const;
00246 
00257     const msg::Context* find_context_by_id(int id) const;
00258 
00269     wreport::Var* edit_by_id(int id);
00270 
00284     void set(const wreport::Var& var, wreport::Varcode code, const Level& lev, const Trange& tr);
00285 
00294     void set_by_id(const wreport::Var& var, int shortcut);
00295 
00308     void set(std::auto_ptr<wreport::Var> var, const Level& lev, const Trange& tr);
00309 
00326     void seti(wreport::Varcode code, int val, int conf, const Level& lev, const Trange& tr);
00327 
00344     void setd(wreport::Varcode code, double val, int conf, const Level& lev, const Trange& tr);
00345 
00362     void setc(wreport::Varcode code, const char* val, int conf, const Level& lev, const Trange& tr);
00363 
00365     void set_date(const char* date);
00366 
00371     //void filter(const Record& filter, Msg& dest) const;
00372 
00381     void sounding_pack_levels(Msg& dst) const;
00382 
00383 #if 0
00384 
00393     void sounding_unpack_levels(Msg& dst) const;
00394 #endif
00395 
00406     void parse_date(int* values) const;
00407 
00415     bool from_csv(CSVReader& in);
00416 
00420     void to_csv(std::ostream& out) const;
00421 
00423     static void csv_header(std::ostream& out);
00424 
00431     void print(FILE* out) const;
00432 
00444     unsigned diff(const Msg& msg) const;
00445 
00449     static MsgType type_from_repmemo(const char* repmemo);
00450 
00454     static const char* repmemo_from_type(MsgType type);
00455 
00456 #include <dballe/msg/msg-extravars.h>
00457 
00458 
00462     void lua_push(struct lua_State* L);
00463 
00469     static Msg* lua_check(struct lua_State* L, int idx);
00470 };
00471 
00475 struct MsgConsumer
00476 {
00477     virtual ~MsgConsumer() {}
00478     virtual void operator()(std::auto_ptr<Msg>) = 0;
00479 };
00480 
00484 struct MatchedMsg : public Matched
00485 {
00486     const Msg& m;
00487 
00488     MatchedMsg(const Msg& r);
00489     ~MatchedMsg();
00490 
00491     virtual matcher::Result match_var_id(int val) const;
00492     virtual matcher::Result match_station_id(int val) const;
00493     virtual matcher::Result match_station_wmo(int block, int station=-1) const;
00494     virtual matcher::Result match_date(const int* min, const int* max) const;
00495     virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const;
00496     virtual matcher::Result match_rep_memo(const char* memo) const;
00497 };
00498 
00499 #if 0
00500 
00512 dba_err dba_msg_set_by_id(dba_msg msg, dba_var var, int id);
00513 
00528 dba_err dba_msg_set_nocopy_by_id(dba_msg msg, dba_var var, int id);
00529 
00538 dba_msg_type dba_msg_get_type(dba_msg msg);
00539 #endif
00540 
00541 }
00542 
00543 // vim:set ts=4 sw=4:
00544 #endif