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;
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)
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;
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)
134 throw std::runtime_error(
135 "Attempted to downcast the wrong kind of cursor");
144 Values::const_iterator var;
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;
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");
Datetime get_datetime() const override
Get the datetime.
Definition: msg/cursor.h:229
Definition: msg/cursor.h:155
int remaining() const override
Get the number of rows still to be fetched.
Definition: msg/cursor.h:91
Common base types used by most of DB-All.e code.
Class passed to key-value accessors to set values in an invoker-defined way.
Definition: core/enq.h:17
Sorted storage for all the dba_msg_datum present on one level.
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:123
Definition: msg/cursor.h:13
DBValues get_values() const override
Get the station data values.
Definition: msg/cursor.h:55
Cursor iterating over station data values.
Definition: core/cursor.h:32
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:53
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:688
std::string get_report() const override
Get the report for this message.
bool next() override
Get a new item from the results of a query.
Definition: msg/cursor.h:193
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:229
Level get_level() const override
Get the level.
Definition: msg/cursor.h:227
static std::shared_ptr< CursorData > downcast(std::shared_ptr< dballe::CursorData > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:233
Vertical level or layer.
Definition: types.h:624
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:86
wreport::Var get_var() const override
Get the variable.
Definition: msg/cursor.h:226
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: msg/cursor.h:125
Coords get_coords() const override
Get the reference coordinates for this message.
static std::shared_ptr< CursorStationData > downcast(std::shared_ptr< dballe::CursorStationData > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:130
Definition: msg/cursor.h:69
bool has_value() const override
Check if the cursor points to a valid value.
Definition: msg/cursor.h:184
bool next() override
Get a new item from the results of a query.
Definition: msg/cursor.h:98
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:220
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:115
Cursor iterating over stations.
Definition: core/cursor.h:12
bool has_value() const override
Check if the cursor points to a valid value.
Definition: msg/cursor.h:29
Date and time.
Definition: types.h:163
Cursor iterating over data values.
Definition: core/cursor.h:52
int remaining() const override
Get the number of rows still to be fetched.
Definition: msg/cursor.h:31
Trange get_trange() const override
Get the time range.
Definition: msg/cursor.h:228
wreport::Var get_var() const override
Get the variable.
Definition: msg/cursor.h:126
Datetime get_datetime() const override
Get the reference Datetime for this message.
static std::shared_ptr< CursorStation > downcast(std::shared_ptr< dballe::CursorStation > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:59
Storage for related physical data.
Definition: msg.h:133
int remaining() const override
Get the number of rows still to be fetched.
Definition: msg/cursor.h:186
void discard() override
Discard the results that have not been read yet.
Definition: msg/cursor.h:212
void discard() override
Discard the results that have not been read yet.
Definition: msg/cursor.h:49
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:215
Ident get_ident() const override
Get the station identifier for this message.
Definition: msg/cursor.h:140