libdballe
5.18
|
00001 /* 00002 * dballe/wr_codec - BUFR/CREX import and export 00003 * 00004 * Copyright (C) 2005--2010 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 DBALLE_MSG_WR_CODEC_H 00023 #define DBALLE_MSG_WR_CODEC_H 00024 00025 #include <dballe/msg/codec.h> 00026 #include <dballe/msg/msg.h> 00027 #include <wreport/varinfo.h> 00028 #include <stdint.h> 00029 #include <map> 00030 #include <string> 00031 00032 namespace wreport { 00033 struct Bulletin; 00034 struct Subset; 00035 } 00036 00037 namespace dballe { 00038 struct Msg; 00039 00040 namespace msg { 00041 00042 class WRImporter : public Importer 00043 { 00044 public: 00045 WRImporter(const Options& opts); 00046 00050 virtual void from_bulletin(const wreport::Bulletin& msg, Msgs& msgs) const; 00051 }; 00052 00053 class BufrImporter : public WRImporter 00054 { 00055 public: 00056 BufrImporter(const Options& opts=Options()); 00057 virtual ~BufrImporter(); 00058 00059 virtual void from_rawmsg(const Rawmsg& msg, Msgs& msgs) const; 00060 }; 00061 00062 class CrexImporter : public WRImporter 00063 { 00064 public: 00065 CrexImporter(const Options& opts=Options()); 00066 virtual ~CrexImporter(); 00067 00068 virtual void from_rawmsg(const Rawmsg& msg, Msgs& msgs) const; 00069 }; 00070 00071 00072 class WRExporter : public Exporter 00073 { 00074 public: 00075 WRExporter(const Options& opts); 00076 00080 virtual void to_bulletin(const Msgs& msgs, wreport::Bulletin& msg) const; 00081 00085 std::string infer_template(const Msgs& msgs) const; 00086 }; 00087 00088 class BufrExporter : public WRExporter 00089 { 00090 public: 00091 BufrExporter(const Options& opts=Options()); 00092 virtual ~BufrExporter(); 00093 00094 virtual void to_rawmsg(const Msgs& msgs, Rawmsg& msg) const; 00095 virtual std::auto_ptr<wreport::Bulletin> make_bulletin() const; 00096 }; 00097 00098 class CrexExporter : public WRExporter 00099 { 00100 public: 00101 CrexExporter(const Options& opts=Options()); 00102 virtual ~CrexExporter(); 00103 00104 virtual void to_rawmsg(const Msgs& msgs, Rawmsg& msg) const; 00105 virtual std::auto_ptr<wreport::Bulletin> make_bulletin() const; 00106 }; 00107 00108 namespace wr { 00109 00110 struct TemplateRegistry; 00111 00112 class Template 00113 { 00114 protected: 00115 virtual void setupBulletin(wreport::Bulletin& bulletin); 00116 virtual void to_subset(const Msg& msg, wreport::Subset& subset); 00117 00118 void add(wreport::Varcode code, const msg::Context* ctx, int shortcut) const; 00119 void add(wreport::Varcode code, const msg::Context* ctx, wreport::Varcode srccode) const; 00120 void add(wreport::Varcode code, const msg::Context* ctx) const; 00121 void add(wreport::Varcode code, int shortcut) const; 00122 void add(wreport::Varcode code, wreport::Varcode srccode, const Level& level, const Trange& trange) const; 00123 void add(wreport::Varcode code, const wreport::Var* var) const; 00124 // Set station name, truncating it if it's too long 00125 void add_st_name(wreport::Varcode dstcode, const msg::Context* ctx) const; 00126 00127 void do_ecmwf_past_wtr() const; 00128 void do_D01001() const; 00129 void do_D01004() const; 00130 void do_D01011() const; 00131 int do_D01012() const; // Return the number of hours 00132 void do_D01013() const; 00133 void do_D01021() const; 00134 00135 public: 00136 const Exporter::Options& opts; 00137 const Msgs& msgs; 00138 const Msg* msg; // Msg being read 00139 const msg::Context* c_station; 00140 const msg::Context* c_gnd_instant; 00141 wreport::Subset* subset; // Subset being written 00142 00143 Template(const Exporter::Options& opts, const Msgs& msgs) 00144 : opts(opts), msgs(msgs), msg(0), subset(0) {} 00145 virtual ~Template() {} 00146 00147 virtual const char* name() const = 0; 00148 virtual const char* description() const = 0; 00149 virtual void to_bulletin(wreport::Bulletin& bulletin); 00150 }; 00151 00152 struct TemplateFactory 00153 { 00154 std::string name; 00155 std::string description; 00156 00157 virtual ~TemplateFactory() {} 00158 virtual std::auto_ptr<Template> make(const Exporter::Options& opts, const Msgs& msgs) const = 0; 00159 }; 00160 00161 struct TemplateRegistry : public std::map<std::string, const TemplateFactory*> 00162 { 00163 static const TemplateRegistry& get(); 00164 static const TemplateFactory& get(const std::string& name); 00165 00166 void register_factory(const TemplateFactory* fac); 00167 }; 00168 00169 } // namespace wr 00170 00171 00172 #if 0 00173 00179 #include <dballe/core/rawmsg.h> 00180 #include <dballe/msg/msgs.h> 00181 #include <dballe/msg/codec.h> 00182 #include <dballe/bufrex/msg.h> 00183 00198 dba_err bufrex_encode_bufr(dba_msgs msgs, int type, int subtype, int localsubtype, dba_rawmsg* raw); 00199 00214 dba_err bufrex_encode_crex(dba_msgs msgs, int type, int subtype, dba_rawmsg* raw); 00215 00216 00227 dba_err bufrex_msg_from_dba_msg(bufrex_msg raw, dba_msg msg); 00228 00239 dba_err bufrex_msg_from_dba_msgs(bufrex_msg raw, dba_msgs msgs); 00240 00253 dba_err bufrex_msg_to_dba_msgs(bufrex_msg raw, dba_msg_codec_options opts, dba_msgs* msgs); 00254 00255 00268 dba_err bufrex_infer_type_subtype(dba_msg msg, int* type, int* subtype, int* localsubtype); 00269 00270 00271 #endif 00272 00273 } // namespace msg 00274 } // namespace dballe 00275 00276 /* vim:set ts=4 sw=4: */ 00277 #endif