libdballe  6.8
processor.h
1 /*
2  * Copyright (C) 2005--2013 ARPA-SIM <urpsim@smr.arpa.emr.it>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Author: Enrico Zini <enrico@enricozini.com>
18  */
19 
20 #ifndef PROCESSOR_H
21 #define PROCESSOR_H
22 
23 #include <dballe/core/rawmsg.h>
24 #include <dballe/core/record.h>
25 #include <dballe/core/file.h>
26 #include <dballe/msg/codec.h>
27 #include <stdexcept>
28 #include <list>
29 #include <string>
30 
31 namespace wreport {
32 struct Bulletin;
33 }
34 
35 namespace dballe {
36 struct Rawmsg;
37 struct Msgs;
38 struct Matcher;
39 
40 namespace cmdline {
41 
49 struct ProcessingException : public std::exception
50 {
51  std::string msg;
52 
63  const std::string& filename,
64  unsigned index,
65  const std::string& msg)
66  {
67  initmsg(filename, index, msg.c_str());
68  }
69 
71  const std::string& filename,
72  unsigned index,
73  const std::exception& original)
74  {
75  initmsg(filename, index, original.what());
76  }
77 
79  const std::string& filename,
80  unsigned index,
81  const std::string& msg,
82  const std::exception& original)
83  {
84  initmsg(filename, index, msg.c_str());
85  this->msg += ": ";
86  this->msg += original.what();
87  }
88 
89  virtual ~ProcessingException() throw() {}
90 
91  virtual const char* what() const throw ()
92  {
93  return msg.c_str();
94  }
95 
96 protected:
97  void initmsg(const std::string& fname, unsigned index, const char* msg);
98 };
99 
100 struct Item
101 {
102  unsigned idx;
103  Rawmsg* rmsg;
104  wreport::Bulletin* bulletin;
105  Msgs* msgs;
106 
107  Item();
108  ~Item();
109 
111  void decode(msg::Importer& imp, bool print_errors=false);
112 
114  void set_msgs(Msgs* new_msgs);
115 };
116 
117 struct Action
118 {
119  virtual ~Action() {}
120  virtual bool operator()(const Item& item) = 0;
121 };
122 
123 struct Filter
124 {
125  msg::Exporter::Options export_opts;
126  int category;
127  int subcategory;
128  int checkdigit;
129  int unparsable;
130  int parsable;
131  const char* index;
132  Matcher* matcher;
133 
134  Filter();
135  ~Filter();
136 
138  void matcher_reset();
139 
141  void matcher_from_record(const Record& query);
142 
143  bool match_index(int idx) const;
144  bool match_common(const Rawmsg& rmsg, const Msgs* msgs) const;
145  bool match_msgs(const Msgs& msgs) const;
146  bool match_bufrex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
147  bool match_bufr(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
148  bool match_crex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
149  bool match_aof(const Rawmsg& rmsg, const Msgs* msgs) const;
150  bool match_item(const Item& item) const;
151 };
152 
153 class Reader
154 {
155 protected:
156  void read_csv(const std::list<std::string>& fnames, Action& action);
157  void read_file(const std::list<std::string>& fnames, Action& action);
158 
159 public:
160  const char* input_type;
161  msg::Importer::Options import_opts;
162  Filter filter;
163  bool verbose;
164  const char* fail_file_name;
165 
166  Reader();
167 
168  void read(const std::list<std::string>& fnames, Action& action);
169 };
170 
171 } // namespace cmdline
172 } // namespace dballe
173 
174 #endif
Definition: codec.h:114
Definition: processor.h:117
Definition: codec.h:56
Definition: processor.h:153
General codec options.
Message importer.
Definition: codec.h:53
File I/O for files containing meterorological messages.
void matcher_reset()
Reset to the empty matcher.
void matcher_from_record(const Record &query)
Initialise the matcher from a record.
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
Definition: processor.h:123
Definition: processor.h:100
Definition: matcher.h:113
void set_msgs(Msgs *new_msgs)
Set the value of msgs, possibly replacing the previous one.
void decode(msg::Importer &imp, bool print_errors=false)
Decode all that can be decoded.
In-memory storage of an encoded weather report.
Implement a storage object for a group of related observation data.
Definition: conversion.h:31
Dynamic array of dba_msg.
Definition: msgs.h:38
Annotated string buffer for encoded messages.
Definition: rawmsg.h:38
Exception used to embed processing issues that mean that processing of the current element can safely...
Definition: processor.h:49
ProcessingException(const std::string &filename, unsigned index, const std::string &msg)
Create a new exception.
Definition: processor.h:62