libdballe  9.14
exporter.h
1 #ifndef DBALLE_EXPORTER_H
2 #define DBALLE_EXPORTER_H
3 
4 #include <cstdio>
5 #include <dballe/fwd.h>
6 #include <functional>
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace wreport {
12 struct Bulletin;
13 }
14 
15 namespace dballe {
16 
25 {
26 public:
28  std::string template_name;
30  int centre = MISSING_INT;
32  int subcentre = MISSING_INT;
34  int application = MISSING_INT;
35 
36  bool operator==(const ExporterOptions&) const;
37  bool operator!=(const ExporterOptions&) const;
38 
40  void print(FILE* out);
41 
43  std::string to_string() const;
44 
46  static std::unique_ptr<ExporterOptions> create();
47 
48  static const ExporterOptions defaults;
49 
50  friend class Exporter;
51 
52 protected:
54  ExporterOptions() = default;
55  ExporterOptions(const ExporterOptions&) = default;
56  ExporterOptions(ExporterOptions&&) = default;
57  ExporterOptions& operator=(const ExporterOptions&) = default;
58  ExporterOptions& operator=(ExporterOptions&&) = default;
59 };
60 
64 class Exporter
65 {
66 protected:
67  ExporterOptions opts;
68 
69  Exporter(const ExporterOptions& opts);
70 
71 public:
72  Exporter(const Exporter&) = delete;
73  Exporter(Exporter&&) = delete;
74  virtual ~Exporter();
75 
76  Exporter& operator=(const Exporter&) = delete;
77  Exporter& operator=(Exporter&&) = delete;
78 
87  virtual std::string
88  to_binary(const std::vector<std::shared_ptr<Message>>& messages) const = 0;
89 
93  virtual std::unique_ptr<wreport::Bulletin>
94  to_bulletin(const std::vector<std::shared_ptr<Message>>& msgs) const;
95 
102  virtual std::unique_ptr<wreport::Bulletin> make_bulletin() const;
103 
105  static std::unique_ptr<Exporter>
106  create(Encoding type,
107  const ExporterOptions& opts = ExporterOptions::defaults);
108 };
109 
111 {
112 public:
113  using Exporter::Exporter;
114 
118  std::unique_ptr<wreport::Bulletin> to_bulletin(
119  const std::vector<std::shared_ptr<Message>>& msgs) const override = 0;
120 };
121 
122 } // namespace dballe
123 
124 #endif
void print(FILE *out)
Print a summary of the options to out.
int subcentre
Originating subcentre.
Definition: exporter.h:32
std::string template_name
Name of template to use for output (leave empty to autodetect)
Definition: exporter.h:28
virtual std::string to_binary(const std::vector< std::shared_ptr< Message >> &messages) const =0
Encode a message.
Message exporter interface.
Definition: exporter.h:64
Definition: cmdline.h:18
Options to control message export.
Definition: exporter.h:24
ExporterOptions()=default
Create new Options initialised with default values.
int centre
Originating centre.
Definition: exporter.h:30
int application
Originating application ID.
Definition: exporter.h:34
static std::unique_ptr< Exporter > create(Encoding type, const ExporterOptions &opts=ExporterOptions::defaults)
Instantiate the right importer for the given type.
virtual std::unique_ptr< wreport::Bulletin > make_bulletin() const
Create a bulletin that works with this exporter.
static std::unique_ptr< ExporterOptions > create()
Create with default values.
Definition: exporter.h:110
virtual std::unique_ptr< wreport::Bulletin > to_bulletin(const std::vector< std::shared_ptr< Message >> &msgs) const
Export to a Bulletin.
std::unique_ptr< wreport::Bulletin > to_bulletin(const std::vector< std::shared_ptr< Message >> &msgs) const override=0
Export to a Bulletin.
std::string to_string() const
Generate a string summary of export options.