libdballe  7.6
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 
43  const std::string& filename,
44  unsigned index,
45  const std::string& msg)
46  {
47  initmsg(filename, index, msg.c_str());
48  }
49 
51  const std::string& filename,
52  unsigned index,
53  const std::exception& original)
54  {
55  initmsg(filename, index, original.what());
56  }
57 
59  const std::string& filename,
60  unsigned index,
61  const std::string& msg,
62  const std::exception& original)
63  {
64  initmsg(filename, index, msg.c_str());
65  this->msg += ": ";
66  this->msg += original.what();
67  }
68 
69  virtual ~ProcessingException() throw() {}
70 
71  virtual const char* what() const throw ()
72  {
73  return msg.c_str();
74  }
75 
76 protected:
77  void initmsg(const std::string& fname, unsigned index, const char* msg);
78 };
79 
80 struct Item
81 {
82  unsigned idx;
83  BinaryMessage* rmsg;
84  wreport::Bulletin* bulletin;
85  Messages* msgs;
86 
87  Item();
88  ~Item();
89 
91  void decode(msg::Importer& imp, bool print_errors=false);
92 
94  void set_msgs(Messages* new_msgs);
95 };
96 
97 struct Action
98 {
99  virtual ~Action() {}
100  virtual bool operator()(const Item& item) = 0;
101 };
102 
103 struct Filter
104 {
105  msg::Exporter::Options export_opts;
106  int category;
107  int subcategory;
108  int checkdigit;
109  int unparsable;
110  int parsable;
111  const char* index;
112  Matcher* matcher;
113 
114  Filter();
115  ~Filter();
116 
118  void matcher_reset();
119 
121  void matcher_from_record(const Query& query);
122 
123  bool match_index(int idx) const;
124  bool match_common(const BinaryMessage& rmsg, const Messages* msgs) const;
125  bool match_msgs(const Messages& msgs) const;
126  bool match_bufrex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
127  bool match_bufr(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
128  bool match_crex(const BinaryMessage& rmsg, const wreport::Bulletin* rm, const Messages* msgs) const;
129  bool match_aof(const BinaryMessage& rmsg, const Messages* msgs) const;
130  bool match_item(const Item& item) const;
131 };
132 
133 class Reader
134 {
135 protected:
136  void read_csv(const std::list<std::string>& fnames, Action& action);
137  void read_json(const std::list<std::string>& fnames, Action& action);
138  void read_file(const std::list<std::string>& fnames, Action& action);
139 
140 public:
141  const char* input_type;
142  msg::Importer::Options import_opts;
143  Filter filter;
144  bool verbose;
145  const char* fail_file_name;
146 
147  Reader();
148 
149  void read(const std::list<std::string>& fnames, Action& action);
150 };
151 
152 }
153 }
154 #endif
Definition: codec.h:107
Definition: processor.h:97
Definition: codec.h:35
Definition: processor.h:133
General codec options.
Message importer.
Definition: codec.h:32
void matcher_reset()
Reset to the empty matcher.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
Definition: processor.h:103
Definition: processor.h:80
Match DB-All.e objects using the same queries that can be made on DB-All.e databases.
Definition: matcher.h:92
void decode(msg::Importer &imp, bool print_errors=false)
Decode all that can be decoded.
Binary message.
Definition: file.h:131
Ordered collection of messages.
Definition: message.h:64
Definition: conversion.h:6
Query used to filter DB-All.e data.
Definition: query.h:14
void matcher_from_record(const Query &query)
Initialise the matcher from a record.
Exception used to embed processing issues that mean that processing of the current element can safely...
Definition: processor.h:29
void set_msgs(Messages *new_msgs)
Set the value of msgs, possibly replacing the previous one.
ProcessingException(const std::string &filename, unsigned index, const std::string &msg)
Create a new exception.
Definition: processor.h:42