libdballe
5.18
|
00001 /* 00002 * Copyright (C) 2005--2011 ARPA-SIM <urpsim@smr.arpa.emr.it> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License. 00007 * 00008 * This program is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 * GNU General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU General Public License 00014 * along with this program; if not, write to the Free Software 00015 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00016 * 00017 * Author: Enrico Zini <enrico@enricozini.com> 00018 */ 00019 00020 #ifndef PROCESSOR_H 00021 #define PROCESSOR_H 00022 00023 #include <dballe/core/rawmsg.h> 00024 #include <dballe/core/record.h> 00025 #include <dballe/msg/codec.h> 00026 #include <list> 00027 #include <string> 00028 00029 namespace wreport { 00030 struct Bulletin; 00031 } 00032 00033 namespace dballe { 00034 struct Rawmsg; 00035 struct Msgs; 00036 struct Matcher; 00037 00038 namespace cmdline { 00039 00040 struct Item 00041 { 00042 unsigned idx; 00043 Rawmsg* rmsg; 00044 wreport::Bulletin* bulletin; 00045 Msgs* msgs; 00046 00047 Item(); 00048 ~Item(); 00049 00051 void decode(msg::Importer& imp, bool print_errors=false); 00052 00054 void set_msgs(Msgs* new_msgs); 00055 }; 00056 00057 struct Action 00058 { 00059 virtual ~Action() {} 00060 virtual void operator()(const Item& item) = 0; 00061 }; 00062 00063 struct Filter 00064 { 00065 msg::Exporter::Options export_opts; 00066 int category; 00067 int subcategory; 00068 int checkdigit; 00069 int unparsable; 00070 int parsable; 00071 const char* index; 00072 Matcher* matcher; 00073 00074 Filter(); 00075 ~Filter(); 00076 00078 void matcher_reset(); 00079 00081 void matcher_from_record(const Record& query); 00082 00083 bool match_index(int idx) const; 00084 bool match_common(const Rawmsg& rmsg, const Msgs* msgs) const; 00085 bool match_msgs(const Msgs& msgs) const; 00086 bool match_bufrex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00087 bool match_bufr(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00088 bool match_crex(const Rawmsg& rmsg, const wreport::Bulletin* rm, const Msgs* msgs) const; 00089 bool match_aof(const Rawmsg& rmsg, const Msgs* msgs) const; 00090 bool match_item(const Item& item) const; 00091 }; 00092 00093 class Reader 00094 { 00095 protected: 00096 void read_csv(const std::list<std::string>& fnames, Action& action); 00097 void read_file(const std::list<std::string>& fnames, Action& action); 00098 00099 public: 00100 const char* input_type; 00101 msg::Importer::Options import_opts; 00102 Filter filter; 00103 00104 Reader(); 00105 00106 void read(const std::list<std::string>& fnames, Action& action); 00107 }; 00108 00109 } // namespace cmdline 00110 } // namespace dballe 00111 00112 #endif