libwreport  2.9
bulletin.h
Go to the documentation of this file.
1 /*
2  * wreport/bulletin - Decoded 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 WREPORT_BULLETIN_H
23 #define WREPORT_BULLETIN_H
24 
31 #include <wreport/var.h>
32 #include <wreport/subset.h>
33 #include <vector>
34 #include <memory>
35 
39 namespace wreport {
40 
41 namespace bulletin {
42 struct Visitor;
43 struct BufrInput;
44 }
45 
46 struct DTable;
47 
63 struct Bulletin
64 {
72  const char* fname;
73 
81  size_t offset;
82 
84  int type;
86  int subtype;
89 
91  int edition;
92 
95 
98  int rep_year;
99  int rep_month;
100  int rep_day;
101  int rep_hour;
107  const Vartable* btable;
109  const DTable* dtable;
110 
112  std::vector<Varcode> datadesc;
113 
115  std::vector<Subset> subsets;
116 
117  Bulletin();
118  virtual ~Bulletin();
119 
121  virtual void clear();
122 
124  virtual const char* encoding_name() const throw () = 0;
125 
135  Subset& obtain_subset(unsigned subsection);
136 
145  const Subset& subset(unsigned subsection) const;
146 
148  virtual void load_tables() = 0;
149 
161  virtual void decode_header(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
162 
174  virtual void decode(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
175 
179  virtual void encode(std::string& buf) const = 0;
180 
185  void visit_datadesc(opcode::Visitor& e) const;
186 
191  void visit(bulletin::Visitor& out) const;
192 
196  void print(FILE* out) const;
197 
201  void print_structured(FILE* out) const;
202 
204  virtual void print_details(FILE* out) const;
205 
214  void print_datadesc(FILE* out, unsigned indent=0) const;
215 
227  virtual unsigned diff(const Bulletin& msg) const;
228 
230  virtual unsigned diff_details(const Bulletin& msg) const;
231 };
232 
233 
238 {
249 
257  static std::auto_ptr<BufrCodecOptions> create();
258 
259 protected:
260  BufrCodecOptions();
261 };
262 
266 struct BufrBulletin : public Bulletin
267 {
271  int centre;
278 
288 
296 
307 
308 
309  virtual ~BufrBulletin();
310 
311  void clear();
312  virtual const char* encoding_name() const throw () { return "BUFR"; }
313  virtual void load_tables();
314  virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
315  virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
316  virtual void encode(std::string& buf) const;
317  virtual void print_details(FILE* out) const;
318  virtual unsigned diff_details(const Bulletin& msg) const;
319 
325  bulletin::BufrInput& reset_raw_details(const std::string& buf);
326 
341  static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
342 
353  static void write(const std::string& buf, FILE* out, const char* fname = 0);
354 
359  static std::auto_ptr<BufrBulletin> create();
360 
361 protected:
362  BufrBulletin();
363 };
364 
368 struct CrexBulletin : public Bulletin
369 {
373  int table;
376 
377  void clear();
378  virtual const char* encoding_name() const throw () { return "CREX"; }
379  virtual void load_tables();
380  virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
381  virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
382  virtual void encode(std::string& buf) const;
383  virtual void print_details(FILE* out) const;
384  virtual unsigned diff_details(const Bulletin& msg) const;
385 
400  static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
401 
412  static void write(const std::string& buf, FILE* out, const char* fname = 0);
413 
418  static std::auto_ptr<CrexBulletin> create();
419 
420 protected:
421  CrexBulletin();
422 };
423 
428 namespace bulletin {
429 }
430 
431 }
432 
433 /* vim:set ts=4 sw=4: */
434 #endif