libdballe  5.18
base.h
00001 /*
00002  * dballe/wr_importers/base - Base infrastructure for wreport importers
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_WRIMPORTER_BASE_H
00023 #define DBALLE_MSG_WRIMPORTER_BASE_H
00024 
00025 #include <dballe/msg/wr_codec.h>
00026 #include <dballe/msg/msg.h>
00027 #include <stdint.h>
00028 
00029 namespace wreport {
00030 struct Subset;
00031 struct Bulletin;
00032 struct Var;
00033 }
00034 
00035 namespace dballe {
00036 namespace msg {
00037 namespace wr {
00038 
00039 class Importer
00040 {
00041 protected:
00042     const msg::Importer::Options& opts;
00043     const wreport::Subset* subset;
00044     Msg* msg;
00045 
00046     virtual void init() {}
00047     virtual void run() = 0;
00048 
00049 public:
00050     Importer(const msg::Importer::Options& opts) : opts(opts) {}
00051     virtual ~Importer() {}
00052 
00053     virtual MsgType scanType(const wreport::Bulletin& bulletin) const = 0;
00054 
00055     void import(const wreport::Subset& subset, Msg& msg)
00056     {
00057         this->subset = &subset;
00058         this->msg = &msg;
00059         init();
00060         run();
00061     }
00062 
00063     static std::auto_ptr<Importer> createSynop(const msg::Importer::Options&);
00064     static std::auto_ptr<Importer> createMetar(const msg::Importer::Options&);
00065     static std::auto_ptr<Importer> createTemp(const msg::Importer::Options&);
00066     static std::auto_ptr<Importer> createPilot(const msg::Importer::Options&);
00067     static std::auto_ptr<Importer> createFlight(const msg::Importer::Options&);
00068     static std::auto_ptr<Importer> createSat(const msg::Importer::Options&);
00069     static std::auto_ptr<Importer> createPollution(const msg::Importer::Options&);
00070     static std::auto_ptr<Importer> createGeneric(const msg::Importer::Options&);
00071 };
00072 
00073 class WMOImporter : public Importer
00074 {
00075 protected:
00076     unsigned pos;
00077 
00078     void import_var(const wreport::Var& var);
00079 
00080     virtual void init()
00081     {
00082         pos = 0;
00083         Importer::init();
00084     }
00085 
00086 public:
00087     WMOImporter(const msg::Importer::Options& opts) : Importer(opts) {}
00088     virtual ~WMOImporter() {}
00089 };
00090 
00091 } // namespace wr
00092 } // namespace msg
00093 } // namespace dballe
00094 
00095 /* vim:set ts=4 sw=4: */
00096 #endif