libdballe  6.8
matcher.h
1 /*
2  * dballe/matcher - Local query match infrastructure
3  *
4  * Copyright (C) 2009--2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Author: Enrico Zini <enrico@enricozini.com>
21  */
22 
23 #ifndef DBALLE_CORE_MATCHER_H
24 #define DBALLE_CORE_MATCHER_H
25 
26 #include <memory>
27 
28 namespace dballe {
29 struct Record;
30 
31 namespace matcher {
32 
33 enum Result {
34  MATCH_YES, // Item matches
35  MATCH_NO, // Item does not match
36  MATCH_NA // Match not applicable to this item
37 };
38 
39 }
40 
48 struct Matched
49 {
50  virtual ~Matched() {}
51 
57  virtual matcher::Result match_var_id(int val) const;
58 
64  virtual matcher::Result match_station_id(int val) const;
65 
71  virtual matcher::Result match_station_wmo(int block, int station=-1) const;
72 
79  virtual matcher::Result match_date(const int* min, const int* max) const;
80 
87  virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const;
88 
94  virtual matcher::Result match_rep_memo(const char* memo) const;
95 
102  static matcher::Result date_in_range(const int* date, const int* min, const int* max);
103 
110  static matcher::Result int_in_range(int val, int min, int max);
111 };
112 
113 struct Matcher
114 {
115  virtual ~Matcher() {}
116 
117  virtual matcher::Result match(const Matched& item) const = 0;
118  virtual void to_record(dballe::Record& query) const = 0;
119 
120  static std::auto_ptr<Matcher> create(const dballe::Record& query);
121 };
122 
123 }
124 
125 /* vim:set ts=4 sw=4: */
126 #endif
virtual matcher::Result match_date(const int *min, const int *max) const
Match date.
static matcher::Result int_in_range(int val, int min, int max)
Match if min <= val <= max.
Common interface for things that are matched.
Definition: matcher.h:48
DB-All.E record.
Definition: record.h:102
Definition: cmdline.h:34
virtual matcher::Result match_var_id(int val) const
Match variable ID.
virtual matcher::Result match_station_wmo(int block, int station=-1) const
Match station WMO code.
virtual matcher::Result match_station_id(int val) const
Match station ID.
Definition: matcher.h:113
static matcher::Result date_in_range(const int *date, const int *min, const int *max)
Match if min <= date <= max.
virtual matcher::Result match_rep_memo(const char *memo) const
Match rep_memo.
virtual matcher::Result match_coords(int latmin, int latmax, int lonmin, int lonmax) const
Match coordinates, with bounds in 1/100000 of degree.