libwreport 2.1
bulletin.h
Go to the documentation of this file.
00001 /*
00002  * wreport/bulletin - Decoded 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 WREPORT_BULLETIN_H
00023 #define WREPORT_BULLETIN_H
00024 
00031 #include <wreport/var.h>
00032 #include <wreport/subset.h>
00033 #include <vector>
00034 #include <memory>
00035 
00039 namespace wreport {
00040 
00041 namespace bulletin {
00042 struct Visitor;
00043 struct BufrInput;
00044 }
00045 
00046 struct DTable;
00047 
00051 struct Bulletin
00052 {
00060     const char* fname;
00061 
00069     size_t offset;
00070 
00072     int type;
00074     int subtype;
00076     int localsubtype;
00077 
00079     int edition;
00080 
00082     int master_table_number;
00083 
00086     int rep_year;   
00087     int rep_month;  
00088     int rep_day;    
00089     int rep_hour;   
00090     int rep_minute; 
00091     int rep_second; 
00095     const Vartable* btable;
00097     const DTable* dtable;
00098 
00100     std::vector<Varcode> datadesc;
00101 
00103     std::vector<Subset> subsets;
00104 
00105     Bulletin();
00106     virtual ~Bulletin();
00107 
00109     virtual void clear();
00110 
00112     virtual const char* encoding_name() const throw () = 0;
00113 
00123     Subset& obtain_subset(unsigned subsection);
00124 
00133     const Subset& subset(unsigned subsection) const;
00134 
00136     virtual void load_tables() = 0;
00137 
00149     virtual void decode_header(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
00150 
00162     virtual void decode(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
00163 
00167     virtual void encode(std::string& buf) const = 0;
00168 
00173     void visit_datadesc(opcode::Visitor& e) const;
00174 
00179     void visit(bulletin::Visitor& out) const;
00180 
00184     void print(FILE* out) const;
00185 
00189     void print_structured(FILE* out) const;
00190 
00192     virtual void print_details(FILE* out) const;
00193 
00202     void print_datadesc(FILE* out, unsigned indent=0) const;
00203 
00215     virtual unsigned diff(const Bulletin& msg) const;
00216 
00218     virtual unsigned diff_details(const Bulletin& msg) const;
00219 };
00220 
00221 
00225 struct BufrCodecOptions
00226 {
00236     bool decode_adds_undef_attrs;
00237 
00245     static std::auto_ptr<BufrCodecOptions> create();
00246 
00247 protected:
00248     BufrCodecOptions();
00249 };
00250 
00254 struct BufrBulletin : public Bulletin
00255 {
00259     int centre;
00261     int subcentre;
00263     int master_table;
00265     int local_table;
00266 
00268     int compression;
00270     int update_sequence_number;
00273     int optional_section_length;
00275     char* optional_section;
00276 
00283     bulletin::BufrInput* raw_details;
00284 
00294     const BufrCodecOptions* codec_options;
00295 
00296 
00297     virtual ~BufrBulletin();
00298 
00299     void clear();
00300     virtual const char* encoding_name() const throw () { return "BUFR"; }
00301     virtual void load_tables();
00302     virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00303     virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00304     virtual void encode(std::string& buf) const;
00305     virtual void print_details(FILE* out) const;
00306     virtual unsigned diff_details(const Bulletin& msg) const;
00307 
00313     bulletin::BufrInput& reset_raw_details(const std::string& buf);
00314 
00329     static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
00330 
00341     static void write(const std::string& buf, FILE* out, const char* fname = 0);
00342 
00347     static std::auto_ptr<BufrBulletin> create();
00348 
00349 protected:
00350     BufrBulletin();
00351 };
00352 
00356 struct CrexBulletin : public Bulletin
00357 {
00361     int table;
00363     bool has_check_digit;
00364 
00365     void clear();
00366     virtual const char* encoding_name() const throw () { return "CREX"; }
00367     virtual void load_tables();
00368     virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00369     virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00370     virtual void encode(std::string& buf) const;
00371     virtual void print_details(FILE* out) const;
00372     virtual unsigned diff_details(const Bulletin& msg) const;
00373 
00388     static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
00389 
00400     static void write(const std::string& buf, FILE* out, const char* fname = 0);
00401 
00406     static std::auto_ptr<CrexBulletin> create();
00407 
00408 protected:
00409     CrexBulletin();
00410 };
00411 
00416 namespace bulletin {
00417 }
00418 
00419 }
00420 
00421 /* vim:set ts=4 sw=4: */
00422 #endif