libdballe  7.19
codec.h
Go to the documentation of this file.
1 #ifndef DBA_MSG_CODEC_H
2 #define DBA_MSG_CODEC_H
3 
4 #include <dballe/file.h>
5 #include <dballe/message.h>
6 #include <memory>
7 #include <string>
8 #include <cstdio>
9 
15 namespace wreport {
16 struct Bulletin;
17 }
18 
19 namespace dballe {
20 struct Messages;
21 struct Message;
22 
23 namespace msg {
24 
32 class Importer
33 {
34 public:
35  struct Options
36  {
37  bool simplified;
38 
41  : simplified(true) {}
42 
43  bool operator==(const Options& o) const { return simplified == o.simplified; }
44  bool operator!=(const Options& o) const { return simplified != o.simplified; }
45 
47  void print(FILE* out);
48 
50  std::string to_string() const;
51 
53  static Options from_string(const std::string& s);
54  };
55 
56 protected:
57  Options opts;
58 
59 public:
60  Importer(const Options& opts);
61  virtual ~Importer();
62 
71  Messages from_binary(const BinaryMessage& msg) const;
72 
85  virtual bool foreach_decoded(const BinaryMessage& msg, std::function<bool(std::unique_ptr<Message>&&)> dest) const = 0;
86 
90  virtual Messages from_bulletin(const wreport::Bulletin& msg) const = 0;
91 
92 
94  static std::unique_ptr<Importer> create(File::Encoding type, const Options& opts=Options());
95 };
96 
104 class Exporter
105 {
106 public:
107  struct Options
108  {
110  std::string template_name;
112  int centre;
117 
120  : centre(MISSING_INT), subcentre(MISSING_INT), application(MISSING_INT) {}
121 
123  void print(FILE* out);
124 
126  std::string to_string() const;
127  };
128 
129 protected:
130  Options opts;
131 
132 public:
133  Exporter(const Options& opts);
134  virtual ~Exporter();
135 
144  virtual std::string to_binary(const Messages& msgs) const = 0;
145 
149  virtual std::unique_ptr<wreport::Bulletin> to_bulletin(const Messages& msgs) const = 0;
150 
157  virtual std::unique_ptr<wreport::Bulletin> make_bulletin() const;
158 
159 
161  static std::unique_ptr<Exporter> create(File::Encoding type, const Options& opts=Options());
162 };
163 
164 }
165 }
166 
167 #endif
Encoding
Supported encodings.
Definition: file.h:20
Definition: codec.h:107
Options()
Create new Options initialised with default values.
Definition: codec.h:119
Definition: codec.h:35
Message importer.
Definition: codec.h:32
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
int centre
Originating centre.
Definition: codec.h:112
std::string template_name
Name of template to use for output (leave empty to autodetect)
Definition: codec.h:110
int subcentre
Originating subcentre.
Definition: codec.h:114
Binary message.
Definition: file.h:131
Ordered collection of messages.
Definition: message.h:67
int application
Originating application ID.
Definition: codec.h:116
Options()
Create new Options initialised with default values.
Definition: codec.h:40
Message exporter.
Definition: codec.h:104