libdballe  7.29
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 #include <functional>
15 
16 namespace dballe {
17 namespace core {
18 
22 typedef enum {
23  DBA_KEY_ERROR = -1,
24  DBA_KEY_PRIORITY = 0,
25  DBA_KEY_PRIOMAX = 1,
26  DBA_KEY_PRIOMIN = 2,
27  DBA_KEY_REP_MEMO = 3,
28  DBA_KEY_ANA_ID = 4,
29  DBA_KEY_MOBILE = 5,
30  DBA_KEY_IDENT = 6,
31  DBA_KEY_LAT = 7,
32  DBA_KEY_LON = 8,
33  DBA_KEY_LATMAX = 9,
34  DBA_KEY_LATMIN = 10,
35  DBA_KEY_LONMAX = 11,
36  DBA_KEY_LONMIN = 12,
37  DBA_KEY_YEAR = 13,
38  DBA_KEY_MONTH = 14,
39  DBA_KEY_DAY = 15,
40  DBA_KEY_HOUR = 16,
41  DBA_KEY_MIN = 17,
42  DBA_KEY_SEC = 18,
43  DBA_KEY_YEARMAX = 19,
44  DBA_KEY_YEARMIN = 20,
45  DBA_KEY_MONTHMAX = 21,
46  DBA_KEY_MONTHMIN = 22,
47  DBA_KEY_DAYMAX = 23,
48  DBA_KEY_DAYMIN = 24,
49  DBA_KEY_HOURMAX = 25,
50  DBA_KEY_HOURMIN = 26,
51  DBA_KEY_MINUMAX = 27,
52  DBA_KEY_MINUMIN = 28,
53  DBA_KEY_SECMAX = 29,
54  DBA_KEY_SECMIN = 30,
55  DBA_KEY_LEVELTYPE1 = 31,
56  DBA_KEY_L1 = 32,
57  DBA_KEY_LEVELTYPE2 = 33,
58  DBA_KEY_L2 = 34,
59  DBA_KEY_PINDICATOR = 35,
60  DBA_KEY_P1 = 36,
61  DBA_KEY_P2 = 37,
62  DBA_KEY_VAR = 38,
63  DBA_KEY_VARLIST = 39,
64  DBA_KEY_CONTEXT_ID = 40,
65  DBA_KEY_QUERY = 41,
66  DBA_KEY_ANA_FILTER = 42,
67  DBA_KEY_DATA_FILTER = 43,
68  DBA_KEY_ATTR_FILTER = 44,
69  DBA_KEY_LIMIT = 45,
70  DBA_KEY_VAR_RELATED = 46,
71  DBA_KEY_COUNT = 47,
72 } dba_keyword;
73 
74 std::ostream& operator<<(std::ostream& o, dba_keyword k);
75 
82 class Record : public dballe::Record
83 {
84 protected:
85  /* The storage for the core keyword data */
86  wreport::Var* keydata[DBA_KEY_COUNT];
87 
88  // The variables, sorted by varcode
89  std::vector<wreport::Var*> m_vars;
90 
92  int find_item(wreport::Varcode code) const throw ();
93 
96 
98  const wreport::Var& get_item(wreport::Varcode code) const;
99 
101  void remove_item(wreport::Varcode code);
102 
110  const wreport::Var* key_peek(dba_keyword parameter) const throw ();
111 
119  const wreport::Var* var_peek(wreport::Varcode code) const throw ();
120 
127  void key_unset(dba_keyword parameter);
128 
135  void var_unset(wreport::Varcode code);
136 
138  wreport::Var& obtain(const char* key);
139 
141  wreport::Var& obtain(dba_keyword key);
142 
145 
146 public:
147  Record();
148  Record(const Record& rec);
149  ~Record();
150 
151  std::unique_ptr<dballe::Record> clone() const override;
152 
153  Record& operator=(const Record& rec);
154 
155  void clear() override;
156  void clear_vars() override;
157  void seti(const char* key, int val) override;
158  void setd(const char* key, double val) override;
159  void setc(const char* key, const char* val) override;
160  void sets(const char* key, const std::string& val) override;
161  void setf(const char* key, const char* val) override;
162  void set_datetime(const Datetime& dt) override;
163  void set_datetimerange(const DatetimeRange& range) override;
164  void set_coords(const Coords& c) override;
165  void set_latrange(const LatRange& lr) override;
166  void set_lonrange(const LonRange& lr) override;
167  void set_level(const Level& lev) override;
168  void set_trange(const Trange& tr) override;
169  void set_var(const wreport::Var& var) override;
170  void set_var_acquire(std::unique_ptr<wreport::Var>&& var) override;
171  void unset(const char* name) override;
172  const wreport::Var* get(const char* key) const override;
173  void add(const dballe::Record& source) override;
174  bool contains(const dballe::Record& subset) const override;
175  bool equals(const dballe::Record& rec) const override;
176  void foreach_key_ref(std::function<void(const char*, const wreport::Var&)> dest) const override;
177  void foreach_key_copy(std::function<void(const char*, std::unique_ptr<wreport::Var>&&)> dest) const override;
178  void print(FILE* out) const override;
179 
185  static const Record& downcast(const dballe::Record& query);
186 
192  static Record& downcast(dballe::Record& query);
193 
205  void set_to_difference(const Record& source1, const Record& source2);
206 
208  Level get_level() const;
210  Trange get_trange() const;
212  Datetime get_datetime() const;
215 
224  bool iter_keys(std::function<bool(dba_keyword, const wreport::Var&)> f) const;
225 
227  const std::vector<wreport::Var*>& vars() const;
228 
241  void set_from_string(const char* str);
242 
250  void set_from_test_string(const std::string& s);
251 
255  std::string to_string() const;
256 
263  static const char* keyword_name(dba_keyword keyword);
264 
271  static wreport::Varinfo keyword_info(dba_keyword keyword);
272 
280  static dba_keyword keyword_byname(const char* tag);
281 
293  static dba_keyword keyword_byname_len(const char* tag, int len);
294 };
295 
296 
297 struct MatchedRecord : public Matched
298 {
299  const Record& r;
300 
301  MatchedRecord(const Record& r);
302  ~MatchedRecord();
303 
304  matcher::Result match_var_id(int val) const override;
305  matcher::Result match_station_id(int val) const override;
306  matcher::Result match_station_wmo(int block, int station=-1) const override;
307  matcher::Result match_datetime(const DatetimeRange& range) const override;
308  matcher::Result match_coords(const LatRange& latrange, const LonRange& lonrange) const override;
309  matcher::Result match_rep_memo(const char* memo) const override;
310 };
311 
312 }
313 }
314 #endif
std::string to_string() const
Encode in a one-liner of comma-separated assignments.
std::unique_ptr< dballe::Record > clone() const override
Return a copy of this record.
matcher::Result match_coords(const LatRange &latrange, const LonRange &lonrange) const override
Match coordinates, with bounds in 1/100000 of degree.
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:297
void setc(const char *key, const char *val) override
Set a key to a string value.
matcher::Result match_station_id(int val) const override
Match station ID.
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 &quot;, &quot;-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.
int find_item(wreport::Varcode code) const
Find an item by wreport::Varcode, returning -1 if not found.
Create wreport variables from the DB-All.e B table.
Coordinates.
Definition: types.h:337
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:17
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.
Level get_level() const
Compose a Level out of the leveltype1...l2 values.
bool iter_keys(std::function< bool(dba_keyword, const wreport::Var &)> f) const
Iterate all keys in the record, calling f on them.
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.
const wreport::Var * key_peek(dba_keyword parameter) const
Look at the value of a parameter.
DB-All.E record.
Definition: core/record.h:82
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.
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.
uint16_t Varcode
Range of datetimes.
Definition: types.h:272
matcher::Result match_station_wmo(int block, int station=-1) const override
Match station WMO code.
Trange get_trange() const
Compose a Trange out of the pindicator...p2 values.
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.
Range of latitudes.
Definition: types.h:407
bool equals(const dballe::Record &rec) const override
Check if two records are the same.
const wreport::Var * var_peek(wreport::Varcode code) const
Look at the value of a variable.
void clear() override
Remove all contents from the record.
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
DatetimeRange get_datetimerange() const
Compose a DatetimeRange out of the yearmin...secmax values.
matcher::Result match_rep_memo(const char *memo) const override
Match rep_memo.
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.
const std::vector< wreport::Var * > & vars() const
Return the varcode-sorted vector with the variables.
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.
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.
matcher::Result match_datetime(const DatetimeRange &range) const override
Match datetime.
void key_unset(dba_keyword parameter)
Remove a parameter from the record.
matcher::Result match_var_id(int val) const override
Match variable ID.
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.
Datetime get_datetime() const
Compose a Datetime out of the year...sec values.