libdballe  5.18
processor.h
1 /*
2  * Copyright (C) 2005--2011 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/msg/codec.h>
26 #include <list>
27 #include <string>
28 
29 namespace wreport {
30 struct Bulletin;
31 }
32 
33 namespace dballe {
34 struct Rawmsg;
35 struct Msgs;
36 struct Matcher;
37 
38 namespace cmdline {
39 
40 struct Item
41 {
42  unsigned idx;
43  Rawmsg* rmsg;
44  wreport::Bulletin* bulletin;
45  Msgs* msgs;
46 
47  Item();
48  ~Item();
49 
51  void decode(msg::Importer& imp, bool print_errors=false);
52 
54  void set_msgs(Msgs* new_msgs);
55 };
56 
57 struct Action
58 {
59  virtual ~Action() {}
60  virtual void operator()(const Item& item) = 0;
61 };
62 
63 struct Filter
64 {
65  msg::Exporter::Options export_opts;
66  int category;
67  int subcategory;
68  int checkdigit;
69  int unparsable;
70  int parsable;
71  const char* index;
72  Matcher* matcher;
73 
74  Filter();
75  ~Filter();
76 
78  void matcher_reset();
79 
81  void matcher_from_record(const Record& query);
82 
83  bool match_index(int idx) const;
84  bool match_common(const Rawmsg& rmsg, const Msgs* msgs) const;
85  bool match_msgs(const Msgs& msgs) const;
86  bool match_bufrex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
87  bool match_bufr(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
88  bool match_crex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const;
89  bool match_aof(const Rawmsg& rmsg, const Msgs* msgs) const;
90  bool match_item(const Item& item) const;
91 };
92 
93 class Reader
94 {
95 protected:
96  void read_csv(const std::list<std::string>& fnames, Action& action);
97  void read_file(const std::list<std::string>& fnames, Action& action);
98 
99 public:
100  const char* input_type;
101  msg::Importer::Options import_opts;
102  Filter filter;
103 
104  Reader();
105 
106  void read(const std::list<std::string>& fnames, Action& action);
107 };
108 
109 } // namespace cmdline
110 } // namespace dballe
111 
112 #endif