libdballe  6.8
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 
64  bool operator==(const Options& o) const { return simplified == o.simplified; }
65  bool operator!=(const Options& o) const { return simplified != o.simplified; }
66 
68  void print(FILE* out);
69 
71  std::string to_string() const;
72 
74  static Options from_string(const std::string& s);
75  };
76 
77 protected:
78  Options opts;
79 
80 public:
81  Importer(const Options& opts);
82  virtual ~Importer();
83 
92  virtual void from_rawmsg(const Rawmsg& msg, Msgs& msgs) const = 0;
93 
97  virtual void from_bulletin(const wreport::Bulletin& msg, Msgs& msgs) const = 0;
98 
99 
101  static std::auto_ptr<Importer> create(Encoding type, const Options& opts=Options());
102 };
103 
111 class Exporter
112 {
113 public:
114  struct Options
115  {
117  std::string template_name;
119  int centre;
124 
127  : centre(MISSING_INT), subcentre(MISSING_INT), application(MISSING_INT) {}
128 
130  void print(FILE* out);
131 
133  std::string to_string() const;
134  };
135 
136 protected:
137  Options opts;
138 
139 public:
140  Exporter(const Options& opts);
141  virtual ~Exporter();
142 
151  virtual void to_rawmsg(const Msgs& msgs, Rawmsg& msg) const = 0;
152 
156  virtual void to_bulletin(const Msgs& msgs, wreport::Bulletin& msg) const = 0;
157 
164  virtual std::auto_ptr<wreport::Bulletin> make_bulletin() const;
165 
166 
168  static std::auto_ptr<Exporter> create(Encoding type, const Options& opts=Options());
169 };
170 
171 } // namespace msg
172 } // namespace dballe
173 
174 /* vim:set ts=4 sw=4: */
175 #endif
virtual void from_rawmsg(const Rawmsg &msg, Msgs &msgs) const =0
Decode a message from its raw encoded representation.
Definition: codec.h:114
static Options from_string(const std::string &s)
Opposite of to_string: create an Options from a string.
static std::auto_ptr< Importer > create(Encoding type, const Options &opts=Options())
Instantiate the right importer for the given type.
Options()
Create new Options initialised with default values.
Definition: codec.h:126
Definition: codec.h:56
Common definitions.
Message importer.
Definition: codec.h:53
std::string to_string() const
Generate a string summary of export options.
void print(FILE *out)
Print a summary of the options to out.
virtual void to_rawmsg(const Msgs &msgs, Rawmsg &msg) const =0
Encode a message.
Definition: cmdline.h:34
int centre
Originating centre.
Definition: codec.h:119
std::string template_name
Name of template to use for output (leave empty to autodetect)
Definition: codec.h:117
int subcentre
Originating subcentre.
Definition: codec.h:121
void print(FILE *out)
Print a summary of the options to out.
virtual std::auto_ptr< wreport::Bulletin > make_bulletin() const
Create a bulletin that works with this exporter.
static std::auto_ptr< Exporter > create(Encoding type, const Options &opts=Options())
Instantiate the right importer for the given type.
virtual void to_bulletin(const Msgs &msgs, wreport::Bulletin &msg) const =0
Export to a Bulletin.
In-memory storage of an encoded weather report.
Definition: conversion.h:31
Dynamic array of dba_msg.
Definition: msgs.h:38
Annotated string buffer for encoded messages.
Definition: rawmsg.h:38
int application
Originating application ID.
Definition: codec.h:123
Options()
Create new Options initialised with default values.
Definition: codec.h:61
Message exporter.
Definition: codec.h:111
std::string to_string() const
Generate a string summary of import options.
virtual void from_bulletin(const wreport::Bulletin &msg, Msgs &msgs) const =0
Import a decoded BUFR/CREX message.