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();
57 void enq(
Enq& enq)
const override;
67 inline static std::shared_ptr<CursorStation>
downcast(std::shared_ptr<dballe::CursorStation> c)
69 auto res = std::dynamic_pointer_cast<CursorStation>(c);
71 throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
79 std::shared_ptr<const impl::Message> msg;
81 const Values& station_values;
83 Values::const_iterator cur;
86 : msg(msg), station_values(msg->find_station_context())
88 station.report = msg->get_report();
89 station.coords = msg->get_coords();
90 station.ident = msg->get_ident();
96 return !at_start && cur != station_values.end();
102 return station_values.size();
103 return station_values.end() - cur;
111 cur = station_values.begin();
112 return cur != station_values.end();
114 else if (cur == station_values.end())
119 return cur != station_values.end();
126 cur = station_values.end();
129 void enq(
Enq& enq)
const override;
137 inline static std::shared_ptr<CursorStationData>
downcast(std::shared_ptr<dballe::CursorStationData> c)
139 auto res = std::dynamic_pointer_cast<CursorStationData>(c);
141 throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
151 Values::const_iterator var;
159 : level(level), trange(trange), var(var)
168 std::vector<CursorDataRow> rows;
169 std::vector<CursorDataRow>::const_iterator cur;
170 bool at_start =
true;
179 for (
const auto& ctx: msg.data)
180 for (Values::const_iterator cur = ctx.values.begin(); cur != ctx.values.end(); ++cur)
181 rows.emplace_back(ctx.level, ctx.trange, cur);
184 for (Values::const_iterator cur = msg.station_data.begin(); cur != msg.station_data.end(); ++cur)
186 rows.emplace_back(cur);
192 return !at_start && cur != rows.end();
199 return rows.end() - cur;
208 return cur != rows.end();
210 else if (cur == rows.end())
217 return cur != rows.end();
227 void enq(
Enq& enq)
const override;
238 inline static std::shared_ptr<CursorData>
downcast(std::shared_ptr<dballe::CursorData> c)
240 auto res = std::dynamic_pointer_cast<CursorData>(c);
242 throw std::runtime_error(
"Attempted to downcast the wrong kind of cursor");
Storage for related physical data.
Definition: msg.h:131
std::string get_report() const override
Get the report for this message.
Coords get_coords() const override
Get the reference coordinates for this message.
Datetime get_datetime() const override
Get the reference Datetime for this message.
Ident get_ident() const override
Get the station identifier for this message.
Sorted storage for all the dba_msg_datum present on one level.
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:192
Date and time.
Definition: types.h:165
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:687
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:177
Cursor iterating over data values.
Definition: core/cursor.h:49
Cursor iterating over station data values.
Definition: core/cursor.h:31
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
Definition: msg/cursor.h:148
Definition: msg/cursor.h:165
bool next() override
Get a new item from the results of a query.
Definition: msg/cursor.h:202
Level get_level() const override
Get the level.
Definition: msg/cursor.h:233
void discard() override
Discard the results that have not been read yet.
Definition: msg/cursor.h:221
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:229
Trange get_trange() const override
Get the time range.
Definition: msg/cursor.h:234
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: msg/cursor.h:231
bool has_value() const override
Check if the cursor points to a valid value.
Definition: msg/cursor.h:190
Datetime get_datetime() const override
Get the datetime.
Definition: msg/cursor.h:235
wreport::Var get_var() const override
Get the variable.
Definition: msg/cursor.h:232
int remaining() const override
Get the number of rows still to be fetched.
Definition: msg/cursor.h:195
static std::shared_ptr< CursorData > downcast(std::shared_ptr< dballe::CursorData > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:238
Definition: msg/cursor.h:78
void discard() override
Discard the results that have not been read yet.
Definition: msg/cursor.h:123
int remaining() const override
Get the number of rows still to be fetched.
Definition: msg/cursor.h:99
bool has_value() const override
Check if the cursor points to a valid value.
Definition: msg/cursor.h:94
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: msg/cursor.h:133
static std::shared_ptr< CursorStationData > downcast(std::shared_ptr< dballe::CursorStationData > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:137
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:131
wreport::Var get_var() const override
Get the variable.
Definition: msg/cursor.h:134
bool next() override
Get a new item from the results of a query.
Definition: msg/cursor.h:106
Definition: msg/cursor.h:14
DBValues get_values() const override
Get the station data values.
Definition: msg/cursor.h:61
static std::shared_ptr< CursorStation > downcast(std::shared_ptr< dballe::CursorStation > c)
Downcast a unique_ptr pointer.
Definition: msg/cursor.h:67
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:34
bool next() override
Get a new item from the results of a query.
Definition: msg/cursor.h:41
void discard() override
Discard the results that have not been read yet.
Definition: msg/cursor.h:52
DBStation get_station() const override
Get the whole station data in a single call.
Definition: msg/cursor.h:59
Common base types used by most of DB-All.e code.