libdballe  6.8
msgs.h
Go to the documentation of this file.
1 /*
2  * msg/msgs - Hold a group of similar Msg
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_MSGS_H
23 #define DBA_MSG_MSGS_H
24 
30 #include <dballe/msg/msg.h>
31 #include <vector>
32 #include <memory>
33 
34 namespace dballe {
35 struct CSVReader;
36 
38 struct Msgs : public std::vector<Msg*>
39 {
40  Msgs();
41  Msgs(const Msgs& msgs);
42  ~Msgs();
43 
44  Msgs& operator=(const Msgs& msgs);
45 
52  void acquire(const Msg& msg);
53 
61  void acquire(std::auto_ptr<Msg> msg);
62 
66  void clear();
67 
75  bool from_csv(CSVReader& in);
76 
80  void to_csv(std::ostream& out) const;
81 
88  void print(FILE* out) const;
89 
101  unsigned diff(const Msgs& msgs) const;
102 };
103 
104 namespace msg {
106 {
107  Msgs& out;
108 
109  AcquireMessages(Msgs& out) : out(out) {}
110 
111  void operator()(std::auto_ptr<Msg> msg)
112  {
113  out.acquire(msg);
114  }
115 };
116 }
117 
121 struct MatchedMsgs : public Matched
122 {
123  const Msgs& m;
124 
125  MatchedMsgs(const Msgs& m);
126  ~MatchedMsgs();
127 
128  virtual matcher::Result match_var_id(int val) const;
129  virtual matcher::Result match_station_id(int val) const;
130  virtual matcher::Result match_station_wmo(int block, int station=-1) const;
131  virtual matcher::Result match_date(const int* min, const int* max) const;
132  virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const;
133  virtual matcher::Result match_rep_memo(const char* memo) const;
134 };
135 
136 }
137 
138 /* vim:set ts=4 sw=4: */
139 #endif
void print(FILE *out) const
Dump all the contents of the message to the given stream.
Common interface for things that are matched.
Definition: matcher.h:48
Storage for related physical data.
Definition: msg.h:119
Match adapter for Msgs.
Definition: msgs.h:121
void to_csv(std::ostream &out) const
Output in CSV format.
void clear()
Remove all messages.
virtual matcher::Result match_date(const int *min, const int *max) const
Match date.
virtual matcher::Result match_rep_memo(const char *memo) const
Match rep_memo.
Definition: cmdline.h:34
virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const
Match coordinates, with bounds in 1/100000 of degree.
bool from_csv(CSVReader &in)
Read data from a CSV input.
Abstraction for a weather report message which is independent from the encoding, used to make sense o...
unsigned diff(const Msgs &msgs) const
Compute the differences between two Msgs.
virtual matcher::Result match_station_id(int val) const
Match station ID.
virtual matcher::Result match_station_wmo(int block, int station=-1) const
Match station WMO code.
Dynamic array of dba_msg.
Definition: msgs.h:38
Consumer interface used to stream messages as they are produced.
Definition: msg.h:478
virtual matcher::Result match_var_id(int val) const
Match variable ID.
Definition: csv.h:51
Definition: msgs.h:105
void acquire(const Msg &msg)
Append a copy of the message to the array.