1#ifndef DBALLE_MSG_CURSOR_H
2#define DBALLE_MSG_CURSOR_H
4#include <dballe/core/cursor.h>
6#include <dballe/msg/msg.h>
15 std::shared_ptr<const impl::Message> msg;
17 const Values& station_values;
20 CursorStation(std::shared_ptr<const impl::Message> msg)
21 : msg(msg), station_values(msg->find_station_context())
23 station.report = msg->get_report();
24 station.coords = msg->get_coords();
25 station.ident = msg->get_ident();
29 bool has_value()
const override {
return !at_start; }
49 void discard()
override { at_start =
false; }
51 void enq(
Enq& enq)
const override;
58 inline static std::shared_ptr<CursorStation>
59 downcast(std::shared_ptr<dballe::CursorStation> c)
61 auto res = std::dynamic_pointer_cast<CursorStation>(c);
63 throw std::runtime_error(
64 "Attempted to downcast the wrong kind of cursor");
71 std::shared_ptr<const impl::Message> msg;
73 const Values& station_values;
75 Values::const_iterator cur;
77 CursorStationData(std::shared_ptr<const impl::Message> msg)
78 : msg(msg), station_values(msg->find_station_context())
80 station.report = msg->get_report();
81 station.coords = msg->get_coords();
82 station.ident = msg->get_ident();
88 return !at_start && cur != station_values.end();
94 return station_values.size();
95 return station_values.end() - cur;
103 cur = station_values.begin();
104 return cur != station_values.end();
106 else if (cur == station_values.end())
111 return cur != station_values.end();
118 cur = station_values.end();
121 void enq(
Enq& enq)
const override;
125 wreport::Varcode
get_varcode()
const override {
return (*cur)->code(); }
129 inline static std::shared_ptr<CursorStationData>
130 downcast(std::shared_ptr<dballe::CursorStationData> c)
132 auto res = std::dynamic_pointer_cast<CursorStationData>(c);
134 throw std::runtime_error(
135 "Attempted to downcast the wrong kind of cursor");
144 Values::const_iterator var;
146 CursorDataRow(Values::const_iterator var) : var(var) {}
148 CursorDataRow(
const Level& level,
const Trange& trange,
149 Values::const_iterator var)
150 : level(level), trange(trange), var(var)
159 std::vector<CursorDataRow> rows;
160 std::vector<CursorDataRow>::const_iterator cur;
161 bool at_start =
true;
165 station.report = msg.get_report();
166 station.coords = msg.get_coords();
167 station.ident = msg.get_ident();
168 datetime = msg.get_datetime();
170 for (
const auto& ctx : msg.data)
171 for (Values::const_iterator cur = ctx.values.begin();
172 cur != ctx.values.end(); ++cur)
173 rows.emplace_back(ctx.level, ctx.trange, cur);
176 for (Values::const_iterator cur = msg.station_data.begin();
177 cur != msg.station_data.end(); ++cur)
180 rows.emplace_back(cur);
184 bool has_value()
const override {
return !at_start && cur != rows.end(); }
190 return rows.end() - cur;
199 return cur != rows.end();
201 else if (cur == rows.end())
208 return cur != rows.end();
218 void enq(
Enq& enq)
const override;
224 return (*(cur->var))->code();
232 inline static std::shared_ptr<CursorData>
235 auto res = std::dynamic_pointer_cast<CursorData>(c);
237 throw std::runtime_error(
238 "Attempted to downcast the wrong kind of cursor");
Storage for related physical data.
Definition msg.h:134
Sorted storage for all the dba_msg_datum present on one level.
Collection of DBValue objects, indexed by wreport::Varcode.
Definition values.h:230
Date and time.
Definition types.h:164
Vertical level or layer.
Definition types.h:625
Information on how a value has been sampled or computed with regards to time.
Definition types.h:689
Collection of Value objects, indexed by wreport::Varcode.
Definition values.h:216
Cursor iterating over data values.
Definition core/cursor.h:53
Cursor iterating over station data values.
Definition core/cursor.h:33
Cursor iterating over stations.
Definition core/cursor.h:13
Class passed to key-value accessors to set values in an invoker-defined way.
Definition core/enq.h:18
bool next() override
Get a new item from the results of a query.
Definition msg/cursor.h:193
Level get_level() const override
Get the level.
Definition msg/cursor.h:227
void discard() override
Discard the results that have not been read yet.
Definition msg/cursor.h:212
DBStation get_station() const override
Get the whole station data in a single call.
Definition msg/cursor.h:220
Trange get_trange() const override
Get the time range.
Definition msg/cursor.h:228
wreport::Varcode get_varcode() const override
Get the variable code.
Definition msg/cursor.h:222
bool has_value() const override
Check if the cursor points to a valid value.
Definition msg/cursor.h:184
Datetime get_datetime() const override
Get the datetime.
Definition msg/cursor.h:229
wreport::Var get_var() const override
Get the variable.
Definition msg/cursor.h:226
int remaining() const override
Get the number of rows still to be fetched.
Definition msg/cursor.h:186
static std::shared_ptr< CursorData > downcast(std::shared_ptr< dballe::CursorData > c)
Downcast a unique_ptr pointer.
Definition msg/cursor.h:233
void discard() override
Discard the results that have not been read yet.
Definition msg/cursor.h:115
int remaining() const override
Get the number of rows still to be fetched.
Definition msg/cursor.h:91
bool has_value() const override
Check if the cursor points to a valid value.
Definition msg/cursor.h:86
wreport::Varcode get_varcode() const override
Get the variable code.
Definition msg/cursor.h:125
static std::shared_ptr< CursorStationData > downcast(std::shared_ptr< dballe::CursorStationData > c)
Downcast a unique_ptr pointer.
Definition msg/cursor.h:130
DBStation get_station() const override
Get the whole station data in a single call.
Definition msg/cursor.h:123
wreport::Var get_var() const override
Get the variable.
Definition msg/cursor.h:126
bool next() override
Get a new item from the results of a query.
Definition msg/cursor.h:98
DBValues get_values() const override
Get the station data values.
Definition msg/cursor.h:55
static std::shared_ptr< CursorStation > downcast(std::shared_ptr< dballe::CursorStation > c)
Downcast a unique_ptr pointer.
Definition msg/cursor.h:59
bool has_value() const override
Check if the cursor points to a valid value.
Definition msg/cursor.h:29
int remaining() const override
Get the number of rows still to be fetched.
Definition msg/cursor.h:31
bool next() override
Get a new item from the results of a query.
Definition msg/cursor.h:38
void discard() override
Discard the results that have not been read yet.
Definition msg/cursor.h:49
DBStation get_station() const override
Get the whole station data in a single call.
Definition msg/cursor.h:53
Common base types used by most of DB-All.e code.