libdballe 9.6
core/query.h
1#ifndef DBALLE_CORE_QUERY_H
2#define DBALLE_CORE_QUERY_H
3
4#include <dballe/query.h>
5#include <dballe/core/defs.h>
6#include <dballe/core/fwd.h>
7#include <wreport/varinfo.h>
8#include <set>
9
15#define DBA_DB_MODIFIER_BEST (1 << 0)
17#define DBA_DB_MODIFIER_UNSORTED (1 << 5)
19#define DBA_DB_MODIFIER_SORT_FOR_EXPORT (1 << 7)
21#define DBA_DB_MODIFIER_SUMMARY_DETAILS (1 << 8)
23#define DBA_DB_MODIFIER_WITH_ATTRIBUTES (1 << 9)
26#define DBA_DB_MODIFIER_LAST (1 << 10)
27
28namespace dballe {
29namespace core {
30
31struct JSONWriter;
32
34struct Query : public dballe::Query
35{
36 static const uint32_t WANT_MISSING_IDENT = (1 << 0);
37 static const uint32_t WANT_MISSING_LTYPE1 = (1 << 1);
38 static const uint32_t WANT_MISSING_L1 = (1 << 2);
39 static const uint32_t WANT_MISSING_LTYPE2 = (1 << 3);
40 static const uint32_t WANT_MISSING_L2 = (1 << 4);
41 static const uint32_t WANT_MISSING_PIND = (1 << 5);
42 static const uint32_t WANT_MISSING_P1 = (1 << 6);
43 static const uint32_t WANT_MISSING_P2 = (1 << 7);
44
50 uint32_t want_missing = 0;
51 int ana_id = MISSING_INT;
52 int priomin = MISSING_INT;
53 int priomax = MISSING_INT;
54 std::string report;
55 int mobile = MISSING_INT;
56 Ident ident;
57 LatRange latrange;
58 LonRange lonrange;
59 DatetimeRange dtrange;
60 Level level;
61 Trange trange;
62 std::set<wreport::Varcode> varcodes;
63 std::string query;
64 std::string ana_filter;
65 std::string data_filter;
66 std::string attr_filter;
67 int limit = MISSING_INT;
68 int block = MISSING_INT;
69 int station = MISSING_INT;
70
71 bool operator==(const Query& o) const
72 {
73 return std::tie(want_missing, ana_id, priomin, priomax, report, mobile, ident, latrange, lonrange, dtrange, level, trange, varcodes, query, ana_filter, data_filter, attr_filter, limit, block, station)
74 == std::tie(o.want_missing, o.ana_id, o.priomin, o.priomax, o.report, o.mobile, o.ident, o.latrange, o.lonrange, o.dtrange, o.level, o.trange, o.varcodes, o.query, o.ana_filter, o.data_filter, o.attr_filter, o.limit, o.block, o.station);
75 }
76
86 void validate();
87
88 std::unique_ptr<dballe::Query> clone() const override;
89
90 unsigned get_modifiers() const;
91
92 DatetimeRange get_datetimerange() const override { return dtrange; }
93 void set_datetimerange(const DatetimeRange& dt) override { dtrange = dt; }
94 LatRange get_latrange() const override { return latrange; }
95 void set_latrange(const LatRange& lr) override { latrange = lr; }
96 LonRange get_lonrange() const override { return lonrange; }
97 void set_lonrange(const LonRange& lr) override { lonrange = lr; }
98 Level get_level() const override { return level; }
99 void set_level(const Level& level) override { this->level = level; }
100 Trange get_trange() const override { return trange; }
101 void set_trange(const Trange& trange) override { this->trange = trange; }
102
103 void clear() override;
104 bool empty() const override;
105
118 void set_from_string(const char* str);
119
127 void set_from_test_string(const std::string& s);
128
135 bool is_subquery(const dballe::Query& other) const override;
136
138 void print(FILE* out) const override;
139
141 void serialize(JSONWriter& out) const;
142
147 static unsigned parse_modifiers(const char* str);
148
154 static const Query& downcast(const dballe::Query& query);
155
161 static Query& downcast(dballe::Query& query);
162
163 static Query from_json(core::json::Stream& in);
164
165protected:
166 void setf(const char* key, unsigned len, const char* val);
167 void unset(const char* key, unsigned len);
168};
169
170}
171}
172#endif
A station identifier, that can be any string (including the empty string) or a missing value.
Definition: types.h:748
Query used to filter DB-All.e data.
Definition: query.h:15
JSON serializer.
Definition: json.h:30
Common definitions.
Range of datetimes.
Definition: types.h:295
Range of latitudes.
Definition: types.h:468
Vertical level or layer.
Definition: types.h:625
Range of longitudes.
Definition: types.h:552
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:687
Standard dballe::Query implementation.
Definition: core/query.h:35
bool empty() const override
Check if the query is empty, that is, it queries everything.
LonRange get_lonrange() const override
Get the range of longitudes to be matched.
Definition: core/query.h:96
static Query & downcast(dballe::Query &query)
Return a reference to query downcasted as core::Query.
DatetimeRange get_datetimerange() const override
Get the Datetime bounds set in this query.
Definition: core/query.h:92
void set_level(const Level &level) override
Set the level to be matched.
Definition: core/query.h:99
void set_datetimerange(const DatetimeRange &dt) override
Set the Datetime range for this query.
Definition: core/query.h:93
static unsigned parse_modifiers(const char *str)
Parse the modifiers specification given a query=* string, returning the ORed flags.
void validate()
Check the query fields for consistency, and fill in missing values:
void set_from_test_string(const std::string &s)
Set a record from a ", "-separated string of assignments.
void set_latrange(const LatRange &lr) override
Set the range of latitudes to be matched.
Definition: core/query.h:95
void serialize(JSONWriter &out) const
Send the contents to a JSONWriter.
std::unique_ptr< dballe::Query > clone() const override
Return a copy of this query.
void clear() override
Clear the contents of the query, making it match all data.
void set_trange(const Trange &trange) override
Set the level to be matched.
Definition: core/query.h:101
LatRange get_latrange() const override
Get the range of latitudes to be matched.
Definition: core/query.h:94
void print(FILE *out) const override
Print the query contents to stderr.
void set_lonrange(const LonRange &lr) override
Set the range of longitudes to be matched.
Definition: core/query.h:97
void set_from_string(const char *str)
Set a value in the record according to an assignment encoded in a string.
static const Query & downcast(const dballe::Query &query)
Return a reference to query downcasted as core::Query.
uint32_t want_missing
Set a bit a 1 with WANT_MISSING_* constants to specify that the query wants results in which the corr...
Definition: core/query.h:50
Trange get_trange() const override
Get the time range to be matched.
Definition: core/query.h:100
bool is_subquery(const dballe::Query &other) const override
Return true if this query matches a subset of the given query.
Level get_level() const override
Get the level to be matched.
Definition: core/query.h:98
Definition: json.h:166