libdballe  7.19
processor.h
1 #ifndef DBALLE_CMDLINE_PROCESSOR_H
2 #define DBALLE_CMDLINE_PROCESSOR_H
3 
4 #include <dballe/msg/codec.h>
5 #include <stdexcept>
6 #include <list>
7 #include <string>
8 
9 #define DBALLE_JSON_VERSION "0.1"
10 
11 namespace wreport {
12 struct Bulletin;
13 }
14 
15 namespace dballe {
16 struct Query;
17 struct BinaryMessage;
18 struct Matcher;
19 
20 namespace cmdline {
21 
29 struct ProcessingException : public std::exception
30 {
31  std::string msg;
32 
41  const std::string& filename,
42  unsigned index,
43  const std::string& msg)
44  {
45  initmsg(filename, index, msg.c_str());
46  }
47 
57  const std::string& filename,
58  unsigned index,
59  const std::exception& original)
60  {
61  initmsg(filename, index, original.what());
62  }
63 
74  const std::string& filename,
75  unsigned index,
76  const std::string& msg,
77  const std::exception& original)
78  {
79  initmsg(filename, index, msg.c_str());
80  this->msg += ": ";
81  this->msg += original.what();
82  }
83 
84  virtual ~ProcessingException() throw() {}
85 
86  virtual const char* what() const throw ()
87  {
88  return msg.c_str();
89  }
90 
91 protected:
92  void initmsg(const std::string& fname, unsigned index, const char* msg);
93 };
94 
95 struct Item
96 {
97  unsigned idx;
98  BinaryMessage* rmsg;
99  wreport::Bulletin* bulletin;
100  Messages* msgs;
101 
102  Item();
103  ~Item();
104 
106  void decode(msg::Importer& imp, bool print_errors=false);
107 
109  void set_msgs(Messages* new_msgs);
110 };
111 
112 struct Action
113 {
114  virtual ~Action() {}
115  virtual bool operator()(const Item& item) = 0;
116 };
117 
118 struct Filter
119 {
120  msg::Exporter::Options export_opts;
121  int category;
122  int subcategory;
123  int checkdigit;
124  int unparsable;
125  int parsable;
126  const char* index;
127  Matcher* matcher;
128 
129  Filter();
130  ~Filter();
131 
133  void matcher_reset();
134 
136  void matcher_from_record(const Query& query);
137 
138  bool match_index(int idx) const;
139  bool match_common(const BinaryMessage& rmsg, const Messages* msgs) const;
140  bool match_msgs(const Messages& msgs) const;
141  bool match_bufrex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
142  bool match_bufr(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
143  bool match_crex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
144  bool match_aof(const BinaryMessage& rmsg, const Messages* msgs) const;
145  bool match_item(const Item& item) const;
146 };
147 
148 class Reader
149 {
150 protected:
151  void read_csv(const std::list<std::string>& fnames, Action& action);
152  void read_json(const std::list<std::string>& fnames, Action& action);
153  void read_file(const std::list<std::string>& fnames, Action& action);
154 
155 public:
156  const char* input_type;
157  msg::Importer::Options import_opts;
158  Filter filter;
159  bool verbose;
160  const char* fail_file_name;
161 
162  Reader();
163 
164  void read(const std::list<std::string>& fnames, Action& action);
165 };
166 
167 }
168 }
169 #endif
Definition: codec.h:107
Definition: processor.h:112
Definition: codec.h:35
Definition: processor.h:148
General codec options.
Message importer.
Definition: codec.h:32
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
ProcessingException(const std::string &filename, unsigned index, const std::string &msg, const std::exception &original)
Create a new exception.
Definition: processor.h:73
Definition: processor.h:118
Definition: processor.h:95
Match DB-All.e objects using the same queries that can be made on DB-All.e databases.
Definition: matcher.h:92
Binary message.
Definition: file.h:131
ProcessingException(const std::string &filename, unsigned index, const std::exception &original)
Create a new exception.
Definition: processor.h:56
Ordered collection of messages.
Definition: message.h:67
Query used to filter DB-All.e data.
Definition: query.h:14
Exception used to embed processing issues that mean that processing of the current element can safely...
Definition: processor.h:29
ProcessingException(const std::string &filename, unsigned index, const std::string &msg)
Create a new exception.
Definition: processor.h:40