libdballe  7.21
core/record.h
Go to the documentation of this file.
1 #ifndef DBALLE_CORE_RECORD_H
2 #define DBALLE_CORE_RECORD_H
3 
9 #include <dballe/record.h>
10 #include <dballe/core/defs.h>
11 #include <dballe/var.h>
12 #include <dballe/core/matcher.h>
13 #include <vector>
14 
15 namespace dballe {
16 namespace core {
17 
21 typedef enum {
22  DBA_KEY_ERROR = -1,
23  DBA_KEY_PRIORITY = 0,
24  DBA_KEY_PRIOMAX = 1,
25  DBA_KEY_PRIOMIN = 2,
26  DBA_KEY_REP_MEMO = 3,
27  DBA_KEY_ANA_ID = 4,
28  DBA_KEY_MOBILE = 5,
29  DBA_KEY_IDENT = 6,
30  DBA_KEY_LAT = 7,
31  DBA_KEY_LON = 8,
32  DBA_KEY_LATMAX = 9,
33  DBA_KEY_LATMIN = 10,
34  DBA_KEY_LONMAX = 11,
35  DBA_KEY_LONMIN = 12,
36  DBA_KEY_YEAR = 13,
37  DBA_KEY_MONTH = 14,
38  DBA_KEY_DAY = 15,
39  DBA_KEY_HOUR = 16,
40  DBA_KEY_MIN = 17,
41  DBA_KEY_SEC = 18,
42  DBA_KEY_YEARMAX = 19,
43  DBA_KEY_YEARMIN = 20,
44  DBA_KEY_MONTHMAX = 21,
45  DBA_KEY_MONTHMIN = 22,
46  DBA_KEY_DAYMAX = 23,
47  DBA_KEY_DAYMIN = 24,
48  DBA_KEY_HOURMAX = 25,
49  DBA_KEY_HOURMIN = 26,
50  DBA_KEY_MINUMAX = 27,
51  DBA_KEY_MINUMIN = 28,
52  DBA_KEY_SECMAX = 29,
53  DBA_KEY_SECMIN = 30,
54  DBA_KEY_LEVELTYPE1 = 31,
55  DBA_KEY_L1 = 32,
56  DBA_KEY_LEVELTYPE2 = 33,
57  DBA_KEY_L2 = 34,
58  DBA_KEY_PINDICATOR = 35,
59  DBA_KEY_P1 = 36,
60  DBA_KEY_P2 = 37,
61  DBA_KEY_VAR = 38,
62  DBA_KEY_VARLIST = 39,
63  DBA_KEY_CONTEXT_ID = 40,
64  DBA_KEY_QUERY = 41,
65  DBA_KEY_ANA_FILTER = 42,
66  DBA_KEY_DATA_FILTER = 43,
67  DBA_KEY_ATTR_FILTER = 44,
68  DBA_KEY_LIMIT = 45,
69  DBA_KEY_VAR_RELATED = 46,
70  DBA_KEY_COUNT = 47,
71 } dba_keyword;
72 
73 std::ostream& operator<<(std::ostream& o, dba_keyword k);
74 
81 class Record : public dballe::Record
82 {
83 protected:
84  /* The storage for the core keyword data */
85  wreport::Var* keydata[DBA_KEY_COUNT];
86 
87  // The variables, sorted by varcode
88  std::vector<wreport::Var*> m_vars;
89 
91  int find_item(wreport::Varcode code) const throw ();
92 
95 
97  const wreport::Var& get_item(wreport::Varcode code) const;
98 
100  void remove_item(wreport::Varcode code);
101 
109  const wreport::Var* key_peek(dba_keyword parameter) const throw ();
110 
118  const wreport::Var* var_peek(wreport::Varcode code) const throw ();
119 
126  void key_unset(dba_keyword parameter);
127 
134  void var_unset(wreport::Varcode code);
135 
137  wreport::Var& obtain(const char* key);
138 
141 
144 
145 public:
146  Record();
147  Record(const Record& rec);
148  ~Record();
149 
150  std::unique_ptr<dballe::Record> clone() const override;
151 
152  Record& operator=(const Record& rec);
153 
154  void clear() override;
155  void clear_vars() override;
156  void seti(const char* key, int val) override;
157  void setd(const char* key, double val) override;
158  void setc(const char* key, const char* val) override;
159  void sets(const char* key, const std::string& val) override;
160  void setf(const char* key, const char* val) override;
161  void set_datetime(const Datetime& dt) override;
162  void set_datetimerange(const DatetimeRange& range) override;
163  void set_coords(const Coords& c) override;
164  void set_latrange(const LatRange& lr) override;
165  void set_lonrange(const LonRange& lr) override;
166  void set_level(const Level& lev) override;
167  void set_trange(const Trange& tr) override;
168  void set_var(const wreport::Var& var) override;
169  void set_var_acquire(std::unique_ptr<wreport::Var>&& var) override;
170  void unset(const char* name) override;
171  const wreport::Var* get(const char* key) const override;
172  void add(const dballe::Record& source) override;
173  bool contains(const dballe::Record& subset) const override;
174  bool equals(const dballe::Record& rec) const override;
175  void foreach_key_ref(std::function<void(const char*, const wreport::Var&)> dest) const override;
176  void foreach_key_copy(std::function<void(const char*, std::unique_ptr<wreport::Var>&&)> dest) const override;
177  void print(FILE* out) const override;
178 
184  static const Record& downcast(const dballe::Record& query);
185 
191  static Record& downcast(dballe::Record& query);
192 
204  void set_to_difference(const Record& source1, const Record& source2);
205 
207  Level get_level() const;
209  Trange get_trange() const;
211  Datetime get_datetime() const;
214 
223  bool iter_keys(std::function<bool(dba_keyword, const wreport::Var&)> f) const;
224 
226  const std::vector<wreport::Var*>& vars() const;
227 
240  void set_from_string(const char* str);
241 
249  void set_from_test_string(const std::string& s);
250 
254  std::string to_string() const;
255 
262  static const char* keyword_name(dba_keyword keyword);
263 
270  static wreport::Varinfo keyword_info(dba_keyword keyword);
271 
279  static dba_keyword keyword_byname(const char* tag);
280 
292  static dba_keyword keyword_byname_len(const char* tag, int len);
293 };
294 
295 
296 struct MatchedRecord : public Matched
297 {
298  const Record& r;
299 
300  MatchedRecord(const Record& r);
301  ~MatchedRecord();
302 
303  matcher::Result match_var_id(int val) const override;
304  matcher::Result match_station_id(int val) const override;
305  matcher::Result match_station_wmo(int block, int station=-1) const override;
306  matcher::Result match_datetime(const DatetimeRange& range) const override;
307  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
308  matcher::Result match_rep_memo(const char* memo) const override;
309 };
310 
311 }
312 }
313 #endif
const std::vector< wreport::Var * > & vars() const
Return the varcode-sorted vector with the variables.
std::unique_ptr< dballe::Record > clone() const override
Return a copy of this record.
static const Record & downcast(const dballe::Record &query)
Return a reference to record downcasted as core::Record.
void set_datetime(const Datetime &dt) override
Set year, month, day, hour, min, sec.
void set_level(const Level &lev) override
Set leveltype1, l1, leveltype2, l2.
Definition: core/record.h:296
void setc(const char *key, const char *val) override
Set a key to a string value.
Common interface for things that are matched.
Definition: matcher.h:31
void set_from_test_string(const std::string &s)
Set a record from a ", "-separated string of assignments.
bool contains(const dballe::Record &subset) const override
Return true if all elements of subset are present in this record, with the same value.
void set_from_string(const char *str)
Set a value in the record according to an assignment encoded in a string.
Create wreport variables from the DB-All.e B table.
Coordinates.
Definition: types.h:337
bool iter_keys(std::function< bool(dba_keyword, const wreport::Var &)> f) const
Iterate all keys in the record, calling f on them.
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
static wreport::Varinfo keyword_info(dba_keyword keyword)
Return informations about a keyword.
static dba_keyword keyword_byname(const char *tag)
Get the dba_keyword corresponding to the given name.
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
void set_to_difference(const Record &source1, const Record &source2)
Set the record to contain only those fields that change source1 into source2.
void print(FILE *out) const override
Print the contents of this record to the given stream.
void set_lonrange(const LonRange &lr) override
Set lonmin, lonmax.
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
void unset(const char *name) override
Remove/unset a key from the record.
void sets(const char *key, const std::string &val) override
Set a key to a string value.
void set_coords(const Coords &c) override
Set lat, lon.
DB-All.E record.
Definition: core/record.h:81
void remove_item(wreport::Varcode code)
Remove an item by wreport::Varcode.
void setd(const char *key, double val) override
Set a key to a double value.
Vertical level or layer.
Definition: types.h:532
wreport::Var & get_item(wreport::Varcode code)
Find an item by wreport::Varcode, raising an exception if not found.
dba_keyword
Keyword used to quickly access context and query information from a record.
Definition: core/record.h:21
void add(const dballe::Record &source) override
Copy all data from the record source into dest.
void set_latrange(const LatRange &lr) override
Set latmin, latmax.
int find_item(wreport::Varcode code) const
Find an item by wreport::Varcode, returning -1 if not found.
uint16_t Varcode
Range of datetimes.
Definition: types.h:272
void set_var(const wreport::Var &var) override
Set var.code() == var.value()
void seti(const char *key, int val) override
Set a key to an integer value.
Trange get_trange() const
Compose a Trange out of the pindicator...p2 values.
Range of latitudes.
Definition: types.h:407
std::string to_string() const
Encode in a one-liner of comma-separated assignments.
bool equals(const dballe::Record &rec) const override
Check if two records are the same.
void clear() override
Remove all contents from the record.
const wreport::Var * var_peek(wreport::Varcode code) const
Look at the value of a variable.
wreport::Var & obtain(const char *key)
Return the Var for a key, creating it if it is missing.
Date and time.
Definition: types.h:158
const wreport::Var * key_peek(dba_keyword parameter) const
Look at the value of a parameter.
void set_datetimerange(const DatetimeRange &range) override
Set datetime-min and datetime-max values.
void setf(const char *key, const char *val) override
Set a key to a string value.
DatetimeRange get_datetimerange() const
Compose a DatetimeRange out of the yearmin...secmax values.
void var_unset(wreport::Varcode code)
Remove a parameter from the record.
void set_var_acquire(std::unique_ptr< wreport::Var > &&var) override
Set var.code() == var.
Range of longitudes.
Definition: types.h:481
Common definitions.
Level get_level() const
Compose a Level out of the leveltype1...l2 values.
static dba_keyword keyword_byname_len(const char *tag, int len)
Get the dba_keyword corresponding to the given name.
static const char * keyword_name(dba_keyword keyword)
Return the name of a dba_keyword.
void key_unset(dba_keyword parameter)
Remove a parameter from the record.
Datetime get_datetime() const
Compose a Datetime out of the year...sec values.
void set_trange(const Trange &tr) override
Set pindicator, p1, p2.
void clear_vars() override
Remove all Bxxyyy keys from the record, leaving the rest intact.