libwreport  2.4
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 
00063 struct Bulletin
00064 {
00072     const char* fname;
00073 
00081     size_t offset;
00082 
00084     int type;
00086     int subtype;
00088     int localsubtype;
00089 
00091     int edition;
00092 
00094     int master_table_number;
00095 
00098     int rep_year;   
00099     int rep_month;  
00100     int rep_day;    
00101     int rep_hour;   
00102     int rep_minute; 
00103     int rep_second; 
00107     const Vartable* btable;
00109     const DTable* dtable;
00110 
00112     std::vector<Varcode> datadesc;
00113 
00115     std::vector<Subset> subsets;
00116 
00117     Bulletin();
00118     virtual ~Bulletin();
00119 
00121     virtual void clear();
00122 
00124     virtual const char* encoding_name() const throw () = 0;
00125 
00135     Subset& obtain_subset(unsigned subsection);
00136 
00145     const Subset& subset(unsigned subsection) const;
00146 
00148     virtual void load_tables() = 0;
00149 
00161     virtual void decode_header(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
00162 
00174     virtual void decode(const std::string& buf, const char* fname="(memory)", size_t offset=0) = 0;
00175 
00179     virtual void encode(std::string& buf) const = 0;
00180 
00185     void visit_datadesc(opcode::Visitor& e) const;
00186 
00191     void visit(bulletin::Visitor& out) const;
00192 
00196     void print(FILE* out) const;
00197 
00201     void print_structured(FILE* out) const;
00202 
00204     virtual void print_details(FILE* out) const;
00205 
00214     void print_datadesc(FILE* out, unsigned indent=0) const;
00215 
00227     virtual unsigned diff(const Bulletin& msg) const;
00228 
00230     virtual unsigned diff_details(const Bulletin& msg) const;
00231 };
00232 
00233 
00237 struct BufrCodecOptions
00238 {
00248     bool decode_adds_undef_attrs;
00249 
00257     static std::auto_ptr<BufrCodecOptions> create();
00258 
00259 protected:
00260     BufrCodecOptions();
00261 };
00262 
00266 struct BufrBulletin : public Bulletin
00267 {
00271     int centre;
00273     int subcentre;
00275     int master_table;
00277     int local_table;
00278 
00280     int compression;
00282     int update_sequence_number;
00285     int optional_section_length;
00287     char* optional_section;
00288 
00295     bulletin::BufrInput* raw_details;
00296 
00306     const BufrCodecOptions* codec_options;
00307 
00308 
00309     virtual ~BufrBulletin();
00310 
00311     void clear();
00312     virtual const char* encoding_name() const throw () { return "BUFR"; }
00313     virtual void load_tables();
00314     virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00315     virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00316     virtual void encode(std::string& buf) const;
00317     virtual void print_details(FILE* out) const;
00318     virtual unsigned diff_details(const Bulletin& msg) const;
00319 
00325     bulletin::BufrInput& reset_raw_details(const std::string& buf);
00326 
00341     static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
00342 
00353     static void write(const std::string& buf, FILE* out, const char* fname = 0);
00354 
00359     static std::auto_ptr<BufrBulletin> create();
00360 
00361 protected:
00362     BufrBulletin();
00363 };
00364 
00368 struct CrexBulletin : public Bulletin
00369 {
00373     int table;
00375     bool has_check_digit;
00376 
00377     void clear();
00378     virtual const char* encoding_name() const throw () { return "CREX"; }
00379     virtual void load_tables();
00380     virtual void decode_header(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00381     virtual void decode(const std::string& raw, const char* fname="(memory)", size_t offset=0);
00382     virtual void encode(std::string& buf) const;
00383     virtual void print_details(FILE* out) const;
00384     virtual unsigned diff_details(const Bulletin& msg) const;
00385 
00400     static bool read(FILE* in, std::string& buf, const char* fname = 0, long* offset = 0);
00401 
00412     static void write(const std::string& buf, FILE* out, const char* fname = 0);
00413 
00418     static std::auto_ptr<CrexBulletin> create();
00419 
00420 protected:
00421     CrexBulletin();
00422 };
00423 
00428 namespace bulletin {
00429 }
00430 
00431 }
00432 
00433 /* vim:set ts=4 sw=4: */
00434 #endif