libdballe  8.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)
16 
17 #define DBA_DB_MODIFIER_UNSORTED (1 << 5)
18 
19 #define DBA_DB_MODIFIER_SORT_FOR_EXPORT (1 << 7)
20 #define DBA_DB_MODIFIER_SUMMARY_DETAILS (1 << 8)
22 #define DBA_DB_MODIFIER_WITH_ATTRIBUTES (1 << 9)
24 
25 namespace dballe {
26 namespace core {
27 
28 struct JSONWriter;
29 
31 struct Query : public dballe::Query
32 {
33  static const uint32_t WANT_MISSING_IDENT = (1 << 0);
34  static const uint32_t WANT_MISSING_LTYPE1 = (1 << 1);
35  static const uint32_t WANT_MISSING_L1 = (1 << 2);
36  static const uint32_t WANT_MISSING_LTYPE2 = (1 << 3);
37  static const uint32_t WANT_MISSING_L2 = (1 << 4);
38  static const uint32_t WANT_MISSING_PIND = (1 << 5);
39  static const uint32_t WANT_MISSING_P1 = (1 << 6);
40  static const uint32_t WANT_MISSING_P2 = (1 << 7);
41 
47  uint32_t want_missing = 0;
48  int ana_id = MISSING_INT;
49  int priomin = MISSING_INT;
50  int priomax = MISSING_INT;
51  std::string report;
52  int mobile = MISSING_INT;
53  Ident ident;
54  LatRange latrange;
55  LonRange lonrange;
56  DatetimeRange dtrange;
57  Level level;
58  Trange trange;
59  std::set<wreport::Varcode> varcodes;
60  std::string query;
61  std::string ana_filter;
62  std::string data_filter;
63  std::string attr_filter;
64  int limit = MISSING_INT;
65  int block = MISSING_INT;
66  int station = MISSING_INT;
67 
68  bool operator==(const Query& o) const
69  {
70  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)
71  == 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);
72  }
73 
83  void validate();
84 
85  std::unique_ptr<dballe::Query> clone() const override;
86 
87  unsigned get_modifiers() const;
88 
89  DatetimeRange get_datetimerange() const override { return dtrange; }
90  void set_datetimerange(const DatetimeRange& dt) override { dtrange = dt; }
91  LatRange get_latrange() const override { return latrange; }
92  void set_latrange(const LatRange& lr) override { latrange = lr; }
93  LonRange get_lonrange() const override { return lonrange; }
94  void set_lonrange(const LonRange& lr) override { lonrange = lr; }
95  Level get_level() const override { return level; }
96  void set_level(const Level& level) override { this->level = level; }
97  Trange get_trange() const override { return trange; }
98  void set_trange(const Trange& trange) override { this->trange = trange; }
99 
100  void clear() override;
101 
114  void set_from_string(const char* str);
115 
123  void set_from_test_string(const std::string& s);
124 
131  bool is_subquery(const dballe::Query& other) const override;
132 
134  void print(FILE* out) const override;
135 
137  void serialize(JSONWriter& out) const;
138 
143  static unsigned parse_modifiers(const char* str);
144 
150  static const Query& downcast(const dballe::Query& query);
151 
157  static Query& downcast(dballe::Query& query);
158 
159  static Query from_json(core::json::Stream& in);
160 
161 protected:
162  void setf(const char* key, unsigned len, const char* val);
163  void unset(const char* key, unsigned len);
164 };
165 
166 }
167 }
168 #endif
void set_level(const Level &level) override
Set the level to be matched.
Definition: core/query.h:96
LatRange get_latrange() const override
Get the range of latitudes to be matched.
Definition: core/query.h:91
Definition: json.h:165
DatetimeRange get_datetimerange() const override
Get the Datetime bounds set in this query.
Definition: core/query.h:89
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:47
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
static unsigned parse_modifiers(const char *str)
Parse the modifiers specification given a query=* string, returning the ORed flags.
Standard dballe::Query implementation.
Definition: core/query.h:31
Definition: cmdline.h:18
static const Query & downcast(const dballe::Query &query)
Return a reference to query downcasted as core::Query.
Vertical level or layer.
Definition: types.h:624
void validate()
Check the query fields for consistency, and fill in missing values:
void clear() override
Clear the contents of the query, making it match all data.
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: types.h:747
Range of datetimes.
Definition: types.h:294
Range of latitudes.
Definition: types.h:467
Trange get_trange() const override
Get the time range to be matched.
Definition: core/query.h:97
void print(FILE *out) const override
Print the query contents to stderr.
void set_datetimerange(const DatetimeRange &dt) override
Set the Datetime range for this query.
Definition: core/query.h:90
void set_latrange(const LatRange &lr) override
Set the range of latitudes to be matched.
Definition: core/query.h:92
Level get_level() const override
Get the level to be matched.
Definition: core/query.h:95
JSON serializer.
Definition: json.h:29
void set_from_string(const char *str)
Set a value in the record according to an assignment encoded in a string.
std::unique_ptr< dballe::Query > clone() const override
Return a copy of this query.
Range of longitudes.
Definition: types.h:551
Common definitions.
Query used to filter DB-All.e data.
Definition: query.h:14
void set_trange(const Trange &trange) override
Set the level to be matched.
Definition: core/query.h:98
void set_from_test_string(const std::string &s)
Set a record from a ", "-separated string of assignments.
bool is_subquery(const dballe::Query &other) const override
Return true if this query matches a subset of the given query.
LonRange get_lonrange() const override
Get the range of longitudes to be matched.
Definition: core/query.h:93
void serialize(JSONWriter &out) const
Send the contents to a JSONWriter.
void set_lonrange(const LonRange &lr) override
Set the range of longitudes to be matched.
Definition: core/query.h:94