libdballe  5.18
base.h
1 /*
2  * dballe/wr_importers/base - Base infrastructure for wreport importers
3  *
4  * Copyright (C) 2005--2010 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 DBALLE_MSG_WRIMPORTER_BASE_H
23 #define DBALLE_MSG_WRIMPORTER_BASE_H
24 
25 #include <dballe/msg/wr_codec.h>
26 #include <dballe/msg/msg.h>
27 #include <stdint.h>
28 
29 namespace wreport {
30 struct Subset;
31 struct Bulletin;
32 struct Var;
33 }
34 
35 namespace dballe {
36 namespace msg {
37 namespace wr {
38 
39 class Importer
40 {
41 protected:
42  const msg::Importer::Options& opts;
43  const wreport::Subset* subset;
44  Msg* msg;
45 
46  virtual void init() {}
47  virtual void run() = 0;
48 
49 public:
50  Importer(const msg::Importer::Options& opts) : opts(opts) {}
51  virtual ~Importer() {}
52 
53  virtual MsgType scanType(const wreport::Bulletin& bulletin) const = 0;
54 
55  void import(const wreport::Subset& subset, Msg& msg)
56  {
57  this->subset = &subset;
58  this->msg = &msg;
59  init();
60  run();
61  }
62 
63  static std::auto_ptr<Importer> createSynop(const msg::Importer::Options&);
64  static std::auto_ptr<Importer> createMetar(const msg::Importer::Options&);
65  static std::auto_ptr<Importer> createTemp(const msg::Importer::Options&);
66  static std::auto_ptr<Importer> createPilot(const msg::Importer::Options&);
67  static std::auto_ptr<Importer> createFlight(const msg::Importer::Options&);
68  static std::auto_ptr<Importer> createSat(const msg::Importer::Options&);
69  static std::auto_ptr<Importer> createPollution(const msg::Importer::Options&);
70  static std::auto_ptr<Importer> createGeneric(const msg::Importer::Options&);
71 };
72 
73 class WMOImporter : public Importer
74 {
75 protected:
76  unsigned pos;
77 
78  void import_var(const wreport::Var& var);
79 
80  virtual void init()
81  {
82  pos = 0;
83  Importer::init();
84  }
85 
86 public:
87  WMOImporter(const msg::Importer::Options& opts) : Importer(opts) {}
88  virtual ~WMOImporter() {}
89 };
90 
91 } // namespace wr
92 } // namespace msg
93 } // namespace dballe
94 
95 /* vim:set ts=4 sw=4: */
96 #endif