1 #ifndef DBALLE_CORE_VALUES_H
2 #define DBALLE_CORE_VALUES_H
10 #include <dballe/record.h>
48 bool operator==(
const Station& o)
const
59 void print(FILE* out,
const char* end=
"\n")
const;
78 void set_from_record(
const Record& rec);
81 Station::operator=(st);
85 bool operator==(
const Sampling& o)
const
87 return Station::operator==(o) &&
datetime == o.datetime &&
level == o.level &&
trange == o.trange;
96 void print(FILE* out,
const char* end=
"\n")
const;
123 Value& operator=(
const Value& o)
125 if (
this == &o)
return *
this;
131 Value& operator=(Value&& o)
133 if (
this == &o)
return *
this;
140 bool operator==(
const Value& o)
const
142 if (
data_id != o.data_id)
return false;
143 if (
var == o.var)
return true;
144 if (!
var || !o.var)
return false;
145 return *
var == *o.var;
159 void set(std::unique_ptr<wreport::Var>&& v)
166 void print(FILE* out)
const;
171 std::vector<uint8_t> buf;
174 void append_uint16(uint16_t val);
175 void append_uint32(uint32_t val);
176 void append_cstring(
const char* val);
186 Decoder(
const std::vector<uint8_t>& buf);
187 uint16_t decode_uint16();
188 uint32_t decode_uint32();
189 const char* decode_cstring();
190 std::unique_ptr<wreport::Var> decode_var();
203 struct Values :
protected std::map<wreport::Varcode, values::Value>
208 typedef std::map<wreport::Varcode, values::Value>::const_iterator const_iterator;
209 typedef std::map<wreport::Varcode, values::Value>::iterator iterator;
210 const_iterator begin()
const {
return std::map<wreport::Varcode, values::Value>::begin(); }
211 const_iterator end()
const {
return std::map<wreport::Varcode, values::Value>::end(); }
212 iterator begin() {
return std::map<wreport::Varcode, values::Value>::begin(); }
213 iterator end() {
return std::map<wreport::Varcode, values::Value>::end(); }
214 size_t size()
const {
return std::map<wreport::Varcode, values::Value>::size(); }
215 bool empty()
const {
return std::map<wreport::Varcode, values::Value>::empty(); }
216 void clear() {
return std::map<wreport::Varcode, values::Value>::clear(); }
217 void erase(
wreport::Varcode code) { std::map<wreport::Varcode, values::Value>::erase(code); }
218 bool operator==(
const Values& o)
const;
231 void set(std::unique_ptr<wreport::Var>&&);
237 template<
typename C,
typename T>
void set(C code,
const T& val) { this->
set(
newvar(code, val)); }
248 for (
auto& i : *
this)
249 i.second.clear_ids();
255 std::vector<uint8_t>
encode()
const;
265 static void decode(
const std::vector<uint8_t>& buf, std::function<
void(std::unique_ptr<wreport::Var>)> dest);
268 void print(FILE* out)
const;
287 return info == o.info && values == o.values;
298 void print(FILE* out)
const;
317 return info == o.info && values == o.values;
328 void print(FILE* out)
const;
Information about a physical variable.
Definition: values.h:65
std::vector< uint8_t > encode() const
Encode these values in a DB-All.e specific binary representation.
void print(FILE *out) const
Print the contents of this StationValues.
Ident ident
Mobile station identifier.
Definition: values.h:37
void set(C code, const T &val)
Set from a variable created by dballe::newvar()
Definition: values.h:237
void clear_ids()
Reset all the database IDs.
Definition: values.h:321
void set(const wreport::Var &v)
Fill from a wreport::Var.
Definition: values.h:152
Information about a station.
Definition: values.h:21
A station or measured value.
Definition: values.h:104
void set(const wreport::Var &)
Set from a wreport::Var.
Coords coords
Station coordinates.
Definition: values.h:34
Coordinates.
Definition: types.h:337
A set of measured values.
Definition: values.h:304
int ana_id
Database ID of the station.
Definition: values.h:31
int data_id
Database ID of the value.
Definition: values.h:107
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
void clear_ids()
Reset the database ID.
Definition: values.h:149
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:17
void set(std::unique_ptr< wreport::Var > &&v)
Fill from a wreport::Var, taking ownership of it.
Definition: values.h:159
static std::vector< uint8_t > encode_attrs(const wreport::Var &var)
Encode the attributes of var in a DB-All.e specific binary representation.
Vertical level or layer.
Definition: types.h:532
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: core/defs.h:19
static void decode(const std::vector< uint8_t > &buf, std::function< void(std::unique_ptr< wreport::Var >)> dest)
Decode variables from a DB-All.e specific binary representation.
void set_from_record(const Record &rec)
Fill this Station with values from a dballe::Record.
wreport::Var * var
wreport::Var representing the value
Definition: values.h:110
Trange trange
Time range.
Definition: values.h:74
void clear_ids()
Reset all the database IDs.
Definition: values.h:246
Level level
Vertical level or layer.
Definition: values.h:71
Value(std::unique_ptr< wreport::Var > &&var)
Construct from a wreport::Var, taking ownership of it.
Definition: values.h:119
void print(FILE *out) const
Print the contents of this Value.
void clear_ids()
Reset the database ID.
Definition: values.h:43
std::string report
rep_memo for this station
Definition: values.h:24
void set_from_record(const Record &rec)
Set from the contents of a dballe::Record.
void set_from_record(const Record &rec)
Set from the contents of a dballe::Record.
void clear_ids()
Reset all the database IDs.
Definition: values.h:291
Date and time.
Definition: types.h:158
A set of station values.
Definition: values.h:274
void print(FILE *out, const char *end="\n") const
Print the Sampling contents to a FILE*.
Datetime datetime
Date and time at which the value was measured or forecast.
Definition: values.h:68
void print(FILE *out, const char *end="\n") const
Print the Station to a FILE*.
Value(const wreport::Var &var)
Construct from a wreport::Var.
Definition: values.h:116
void print(FILE *out) const
Print the contents of this Values.
Shortcut functions to work with wreport::Var in DB-All.e.
void print(FILE *out) const
Print the contents of this StationValues.
std::unique_ptr< wreport::Var > newvar(C code, const T &val)
Create a new Var, from the DB-All.e B table, with value.
Definition: var.h:62
static void decode_attrs(const std::vector< uint8_t > &buf, wreport::Var &var)
Decode the attributes of var from a buffer.
void add_data_id(wreport::Varcode code, int data_id)
Set the database ID for the Value with this wreport::Varcode.
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:203
wreport::Varcode resolve_varcode(const char *name)
Resolve a variable name to a varcode proper, dealing with aliases and validation. ...
void set_from_record(const Record &rec)
Set from the contents of a dballe::Record.