libdballe  5.18
codec.h
Go to the documentation of this file.
1 /*
2  * msg/codec - General codec options
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 DBA_MSG_CODEC_H
23 #define DBA_MSG_CODEC_H
24 
25 #include <dballe/core/rawmsg.h>
26 #include <dballe/core/defs.h>
27 #include <memory>
28 #include <string>
29 #include <stdio.h>
30 
36 namespace wreport {
37 struct Bulletin;
38 }
39 
40 namespace dballe {
41 struct Rawmsg;
42 struct Msgs;
43 
44 namespace msg {
45 
53 class Importer
54 {
55 public:
56  struct Options
57  {
58  bool simplified;
59 
62  : simplified(true) {}
63 
65  void print(FILE* out);
66 
68  std::string to_string() const;
69  };
70 
71 protected:
72  Options opts;
73 
74 public:
75  Importer(const Options& opts);
76  virtual ~Importer();
77 
86  virtual void from_rawmsg(const Rawmsg& msg, Msgs& msgs) const = 0;
87 
91  virtual void from_bulletin(const wreport::Bulletin& msg, Msgs& msgs) const = 0;
92 
93 
95  static std::auto_ptr<Importer> create(Encoding type, const Options& opts=Options());
96 };
97 
105 class Exporter
106 {
107 public:
108  struct Options
109  {
111  std::string template_name;
113  int centre;
118 
121  : centre(MISSING_INT), subcentre(MISSING_INT), application(MISSING_INT) {}
122 
124  void print(FILE* out);
125 
127  std::string to_string() const;
128  };
129 
130 protected:
131  Options opts;
132 
133 public:
134  Exporter(const Options& opts);
135  virtual ~Exporter();
136 
145  virtual void to_rawmsg(const Msgs& msgs, Rawmsg& msg) const = 0;
146 
150  virtual void to_bulletin(const Msgs& msgs, wreport::Bulletin& msg) const = 0;
151 
158  virtual std::auto_ptr<wreport::Bulletin> make_bulletin() const;
159 
160 
162  static std::auto_ptr<Exporter> create(Encoding type, const Options& opts=Options());
163 };
164 
165 } // namespace msg
166 } // namespace dballe
167 
168 /* vim:set ts=4 sw=4: */
169 #endif