libdballe 9.13
core/query.h
1#ifndef DBALLE_CORE_QUERY_H
2#define DBALLE_CORE_QUERY_H
3
4#include <dballe/core/defs.h>
5#include <dballe/core/fwd.h>
6#include <dballe/query.h>
7#include <set>
8#include <wreport/varinfo.h>
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)
22#define DBA_DB_MODIFIER_SUMMARY_DETAILS (1 << 8)
24#define DBA_DB_MODIFIER_WITH_ATTRIBUTES (1 << 9)
27#define DBA_DB_MODIFIER_LAST (1 << 10)
28
29namespace dballe {
30namespace core {
31
32struct JSONWriter;
33
35struct Query : public dballe::Query
36{
37 static const uint32_t WANT_MISSING_IDENT = (1 << 0);
38 static const uint32_t WANT_MISSING_LTYPE1 = (1 << 1);
39 static const uint32_t WANT_MISSING_L1 = (1 << 2);
40 static const uint32_t WANT_MISSING_LTYPE2 = (1 << 3);
41 static const uint32_t WANT_MISSING_L2 = (1 << 4);
42 static const uint32_t WANT_MISSING_PIND = (1 << 5);
43 static const uint32_t WANT_MISSING_P1 = (1 << 6);
44 static const uint32_t WANT_MISSING_P2 = (1 << 7);
45
51 uint32_t want_missing = 0;
52 int ana_id = MISSING_INT;
53 int priomin = MISSING_INT;
54 int priomax = MISSING_INT;
55 Report report;
56 int mobile = MISSING_INT;
57 Ident ident;
58 LatRange latrange;
59 LonRange lonrange;
60 DatetimeRange dtrange;
61 Level level;
62 Trange trange;
63 std::set<wreport::Varcode> varcodes;
64 std::string query;
65 std::string ana_filter;
66 std::string data_filter;
67 std::string attr_filter;
68 int limit = MISSING_INT;
69 int block = MISSING_INT;
70 int station = MISSING_INT;
71
72 bool operator==(const Query& o) const
73 {
74 return std::tie(want_missing, ana_id, priomin, priomax, report, mobile,
75 ident, latrange, lonrange, dtrange, level, trange,
76 varcodes, query, ana_filter, data_filter, attr_filter,
77 limit, block, station) ==
78 std::tie(o.want_missing, o.ana_id, o.priomin, o.priomax,
79 o.report, o.mobile, o.ident, o.latrange, o.lonrange,
80 o.dtrange, o.level, o.trange, o.varcodes, o.query,
81 o.ana_filter, o.data_filter, o.attr_filter, o.limit,
82 o.block, o.station);
83 }
84
94 void validate();
95
96 std::unique_ptr<dballe::Query> clone() const override;
97
98 unsigned get_modifiers() const;
99
100 DatetimeRange get_datetimerange() const override { return dtrange; }
101 void set_datetimerange(const DatetimeRange& dt) override { dtrange = dt; }
102 LatRange get_latrange() const override { return latrange; }
103 void set_latrange(const LatRange& lr) override { latrange = lr; }
104 LonRange get_lonrange() const override { return lonrange; }
105 void set_lonrange(const LonRange& lr) override { lonrange = lr; }
106 Level get_level() const override { return level; }
107 void set_level(const Level& level) override { this->level = level; }
108 Trange get_trange() const override { return trange; }
109 void set_trange(const Trange& trange) override { this->trange = trange; }
110
111 void clear() override;
112 bool empty() const override;
113
126 void set_from_string(const char* str);
127
135 void set_from_test_string(const std::string& s);
136
143 bool is_subquery(const dballe::Query& other) const override;
144
146 void print(FILE* out) const override;
147
149 void serialize(JSONWriter& out) const;
150
155 static unsigned parse_modifiers(const char* str);
156
162 static const Query& downcast(const dballe::Query& query);
163
169 static Query& downcast(dballe::Query& query);
170
171 static Query from_json(core::json::Stream& in);
172
173protected:
174 void setf(const char* key, unsigned len, const char* val);
175 void unset(const char* key, unsigned len);
176};
177
178} // namespace core
179} // namespace dballe
180#endif
A station identifier, that can be any string (including the empty string) or a missing value.
Definition types.h:751
Query used to filter DB-All.e data.
Definition query.h:17
A report name.
Definition types.h:816
JSON serializer.
Definition json.h:30
Common definitions.
Range of datetimes.
Definition types.h:297
Range of latitudes.
Definition types.h:470
Vertical level or layer.
Definition types.h:625
Range of longitudes.
Definition types.h:553
Information on how a value has been sampled or computed with regards to time.
Definition types.h:689
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:104
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:100
void set_level(const Level &level) override
Set the level to be matched.
Definition core/query.h:107
void set_datetimerange(const DatetimeRange &dt) override
Set the Datetime range for this query.
Definition core/query.h:101
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:103
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:109
LatRange get_latrange() const override
Get the range of latitudes to be matched.
Definition core/query.h:102
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:105
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:51
Trange get_trange() const override
Get the time range to be matched.
Definition core/query.h:108
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:106
Definition json.h:163