libdballe  7.21
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 
119 {
120  std::vector<std::pair<int, int>> ranges;
121 
122  void parse(const std::string& str);
123 
124  bool match(int val) const;
125 };
126 
128 {
129  int category = -1;
130  int subcategory = -1;
131  int checkdigit = -1;
132  int unparsable = 0;
133  int parsable = 0;
134  const char* index_filter = nullptr;
135  const char* input_type = "auto";
136  const char* fail_file_name = nullptr;
137 };
138 
139 struct Filter
140 {
141  msg::Exporter::Options export_opts;
142  int category = -1;
143  int subcategory = -1;
144  int checkdigit = -1;
145  int unparsable = 0;
146  int parsable = 0;
147  IndexMatcher imatcher;
148  Matcher* matcher = nullptr;
149 
150  Filter();
151  Filter(const ReaderOptions& opts);
152  ~Filter();
153 
154  void set_index_filter(const std::string& val);
155 
157  void matcher_reset();
158 
160  void matcher_from_record(const Query& query);
161 
162  bool match_index(int idx) const;
163  bool match_common(const BinaryMessage& rmsg, const Messages* msgs) const;
164  bool match_msgs(const Messages& msgs) const;
165  bool match_bufrex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
166  bool match_bufr(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
167  bool match_crex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
168  bool match_aof(const BinaryMessage& rmsg, const Messages* msgs) const;
169  bool match_item(const Item& item) const;
170 };
171 
172 class Reader
173 {
174 protected:
175  std::string input_type;
176  const char* fail_file_name;
177 
178  void read_csv(const std::list<std::string>& fnames, Action& action);
179  void read_json(const std::list<std::string>& fnames, Action& action);
180  void read_file(const std::list<std::string>& fnames, Action& action);
181 
182 public:
183  msg::Importer::Options import_opts;
184  Filter filter;
185  bool verbose;
186 
187  Reader(const ReaderOptions& opts);
188 
189  void read(const std::list<std::string>& fnames, Action& action);
190 };
191 
192 }
193 }
194 #endif
Definition: codec.h:107
Definition: processor.h:118
Definition: processor.h:112
Definition: codec.h:35
Definition: processor.h:172
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:139
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
Definition: processor.h:127
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