1 #ifndef DBALLE_CORE_VALUES_H 2 #define DBALLE_CORE_VALUES_H 10 #include <dballe/record.h> 47 bool operator==(
const Station& o)
const 58 void print(FILE* out,
const char* end=
"\n")
const;
80 Station::operator=(st);
84 bool operator==(
const Sampling& o)
const 86 return Station::operator==(o) && datetime == o.
datetime && level == o.
level && trange == o.
trange;
95 void print(FILE* out,
const char* end=
"\n")
const;
106 int data_id = MISSING_INT;
111 Value(
const Value& o) : data_id(o.data_id), var(o.var ? new
wreport::Var(*o.var) : nullptr) {}
112 Value(
Value&& o) : data_id(o.data_id), var(o.var) { o.var =
nullptr; }
118 Value(std::unique_ptr<wreport::Var>&& var) : var(var.release()) {}
120 ~
Value() {
delete var; }
124 if (
this == &o)
return *
this;
132 if (
this == &o)
return *
this;
139 bool operator==(
const Value& o)
const 141 if (data_id != o.
data_id)
return false;
142 if (var == o.
var)
return true;
143 if (!var || !o.
var)
return false;
144 return *var == *o.
var;
158 void set(std::unique_ptr<wreport::Var>&& v)
165 void print(FILE* out)
const;
170 std::vector<uint8_t> buf;
173 void append_uint16(uint16_t val);
174 void append_uint32(uint32_t val);
175 void append_cstring(
const char* val);
185 Decoder(
const std::vector<uint8_t>& buf);
186 uint16_t decode_uint16();
187 uint32_t decode_uint32();
188 const char* decode_cstring();
189 std::unique_ptr<wreport::Var> decode_var();
194 static void decode_attrs(
const std::vector<uint8_t>& buf,
wreport::Var& var);
202 struct Values :
protected std::map<wreport::Varcode, values::Value>
207 typedef std::map<wreport::Varcode, values::Value>::const_iterator const_iterator;
208 typedef std::map<wreport::Varcode, values::Value>::iterator iterator;
209 const_iterator begin()
const {
return std::map<wreport::Varcode, values::Value>::begin(); }
210 const_iterator end()
const {
return std::map<wreport::Varcode, values::Value>::end(); }
211 iterator begin() {
return std::map<wreport::Varcode, values::Value>::begin(); }
212 iterator end() {
return std::map<wreport::Varcode, values::Value>::end(); }
213 size_t size()
const {
return std::map<wreport::Varcode, values::Value>::size(); }
214 bool empty()
const {
return std::map<wreport::Varcode, values::Value>::empty(); }
215 void clear() {
return std::map<wreport::Varcode, values::Value>::clear(); }
216 void erase(
wreport::Varcode code) { std::map<wreport::Varcode, values::Value>::erase(code); }
217 bool operator==(
const Values& o)
const;
230 void set(std::unique_ptr<wreport::Var>&&);
233 void set(
const Values& vals);
236 template<
typename C,
typename T>
void set(C code,
const T& val) { this->
set(
newvar(code, val)); }
247 for (
auto& i : *
this)
248 i.second.clear_ids();
254 std::vector<uint8_t> encode()
const;
259 static std::vector<uint8_t> encode_attrs(
const wreport::Var& var);
264 static void decode(
const std::vector<uint8_t>& buf, std::function<
void(std::unique_ptr<wreport::Var>)> dest);
267 void print(FILE* out)
const;
286 return info == o.info && values == o.values;
297 void print(FILE* out)
const;
316 return info == o.info && values == o.values;
327 void print(FILE* out)
const;
Information about a physical variable.
Definition: values.h:64
Ident ident
Mobile station identifier.
Definition: values.h:36
void clear_ids()
Reset all the database IDs.
Definition: values.h:320
Information about a station.
Definition: values.h:20
A station or measured value.
Definition: values.h:103
Coords coords
Station coordinates.
Definition: values.h:33
Coordinates.
Definition: types.h:337
A set of measured values.
Definition: values.h:303
int ana_id
Database ID of the station.
Definition: values.h:30
int data_id
Database ID of the value.
Definition: values.h:106
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:148
Key/value store where keys are strings and values are wreport variables.
Definition: record.h:16
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
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
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:109
Trange trange
Time range.
Definition: values.h:73
void clear_ids()
Reset all the database IDs.
Definition: values.h:245
Level level
Vertical level or layer.
Definition: values.h:70
Value(std::unique_ptr< wreport::Var > &&var)
Construct from a wreport::Var, taking ownership of it.
Definition: values.h:118
void clear_ids()
Reset the database ID.
Definition: values.h:42
std::string report
rep_memo for this station
Definition: values.h:23
void clear_ids()
Reset all the database IDs.
Definition: values.h:290
Date and time.
Definition: types.h:158
A set of station values.
Definition: values.h:273
Datetime datetime
Date and time at which the value was measured or forecast.
Definition: values.h:67
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:115
Shortcut functions to work with wreport::Var in DB-All.e.
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
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:202
wreport::Varcode resolve_varcode(const char *name)
Resolve a variable name to a varcode proper, dealing with aliases and validation. ...