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
Options used to configure BUFR decoding.
Definition: bulletin.h:237
char * optional_section
Raw contents of the optional section.
Definition: bulletin.h:287
virtual void print_details(FILE *out) const
Print format-specific details.
Binary buffer with bit-level read operations.
Definition: buffers.h:56
int master_table_number
Master table number.
Definition: bulletin.h:94
int rep_hour
Hour.
Definition: bulletin.h:101
virtual unsigned diff(const Bulletin &msg) const
Compute the differences between two bulletins.
size_t offset
File offset of the start of the message.
Definition: bulletin.h:81
Implement wreport::Var, an encapsulation of a measured variable.
bulletin::BufrInput * raw_details
Raw details about the message that has been decoded.
Definition: bulletin.h:295
std::vector< Subset > subsets
Decoded variables.
Definition: bulletin.h:115
const char * fname
Input file name (optional).
Definition: bulletin.h:72
void visit_datadesc(opcode::Visitor &e) const
Walk the structure of the data descriptor section sending events to an opcode::Explorer.
int rep_minute
Minute.
Definition: bulletin.h:102
int localsubtype
Local message subcategory.
Definition: bulletin.h:88
virtual void load_tables()=0
Load a new set of tables to use for encoding this message.
int table
CREX-specific encoding options.
Definition: bulletin.h:373
virtual void clear()
Reset the bulletin.
void print_structured(FILE *out) const
Dump the contents of this bulletin, in a more structured way.
int subcentre
Centre-specific subcentre code.
Definition: bulletin.h:273
virtual const char * encoding_name() const
Type of source/target encoding.
Definition: bulletin.h:312
virtual const char * encoding_name() const
Type of source/target encoding.
Definition: bulletin.h:378
void print_datadesc(FILE *out, unsigned indent=0) const
Pretty-print the data descriptor section.
Storage for the decoded data of a BUFR or CREX message.
Definition: bulletin.h:63
Holds a variable information table.
Definition: vartable.h:84
int update_sequence_number
Update sequence number from octet 7 in section 1.
Definition: bulletin.h:282
virtual void encode(std::string &buf) const =0
Encode the message.
const Subset & subset(unsigned subsection) const
Get a Subset from the message.
int rep_day
Day.
Definition: bulletin.h:100
int subtype
International message subcategory.
Definition: bulletin.h:86
D-table with Dxxyyy aggregate code expansions.
Definition: dtable.h:59
Handling of a BUFR/CREX data subset as a list of decoded variables.
bool decode_adds_undef_attrs
By default (false) undefined attributes are not added to variables, and there is no difference betwee...
Definition: bulletin.h:248
CREX bulletin implementation.
Definition: bulletin.h:368
int rep_month
Month.
Definition: bulletin.h:99
bool has_check_digit
True if the CREX message uses the check digit feature.
Definition: bulletin.h:375
int centre
BUFR-specific encoding options.
Definition: bulletin.h:271
int compression
1 if the BUFR message uses compression, else 0
Definition: bulletin.h:280
virtual unsigned diff_details(const Bulletin &msg) const
Diff format-specific details.
const Vartable * btable
vartable used to lookup B table codes
Definition: bulletin.h:107
int local_table
Version number of local tables used to augment the master table.
Definition: bulletin.h:277
virtual void decode(const std::string &buf, const char *fname="(memory)", size_t offset=0)=0
Parse an encoded message.
const BufrCodecOptions * codec_options
Options used to customise encoding or decoding.
Definition: bulletin.h:306
int master_table
Version number of master tables used.
Definition: bulletin.h:275
Represent a BUFR/CREX data subset as a list of decoded variables.
Definition: subset.h:40
virtual void decode_header(const std::string &buf, const char *fname="(memory)", size_t offset=0)=0
Parse only the header of an encoded message.
int type
Message category.
Definition: bulletin.h:84
int rep_second
Second.
Definition: bulletin.h:103
int rep_year
Representative datetime for this data.
Definition: bulletin.h:98
Subset & obtain_subset(unsigned subsection)
Get a Subset from the message.
BUFR bulletin implementation.
Definition: bulletin.h:266
const DTable * dtable
dtable used to lookup D table codes
Definition: bulletin.h:109
int optional_section_length
0 if the BUFR message does not contain an optional section, else its length in bytes ...
Definition: bulletin.h:285
void print(FILE *out) const
Dump the contents of this bulletin.
std::vector< Varcode > datadesc
Parsed data descriptor section.
Definition: bulletin.h:112
virtual const char * encoding_name() const =0
Type of source/target encoding.
void visit(bulletin::Visitor &out) const
Run the Data Descriptor Section interpreter, sending commands to executor.
int edition
Edition number.
Definition: bulletin.h:91