1 #ifndef DBALLE_CORE_VALUES_H 2 #define DBALLE_CORE_VALUES_H 6 #include <dballe/record.h> 7 #include <wreport/varinfo.h> 15 int ana_id = MISSING_INT;
21 void clear_ids() { ana_id = MISSING_INT; }
22 void set_from_record(
const Record& rec);
23 bool operator==(
const Station& o)
const 25 return report == o.report && ana_id == o.ana_id && coords == o.coords && ident == o.ident;
28 void print(FILE* out,
const char* end=
"\n")
const;
39 void set_from_record(
const Record& rec);
42 Station::operator=(st);
46 bool operator==(
const Sampling& o)
const 48 return Station::operator==(o) && datetime == o.datetime && level == o.level && trange == o.trange;
51 void print(FILE* out,
const char* end=
"\n")
const;
57 int data_id = MISSING_INT;
58 wreport::Var* var =
nullptr;
60 Value(
const Value& o) : data_id(o.data_id), var(o.var ?
new wreport::Var(*o.var) :
nullptr) {}
61 Value(
Value&& o) : data_id(o.data_id), var(o.var) { o.var =
nullptr; }
62 Value(
const wreport::Var& var) : var(
new wreport::Var(var)) {}
63 Value(std::unique_ptr<wreport::Var>&& var) : var(var.release()) {}
64 ~
Value() {
delete var; }
67 if (
this == &o)
return *
this;
70 var = o.var ?
new wreport::Var(*o.var) :
nullptr;
75 if (
this == &o)
return *
this;
82 bool operator==(
const Value& o)
const 84 if (data_id != o.data_id)
return false;
85 if (var == o.var)
return true;
86 if (!var || !o.var)
return false;
87 return *var == *o.var;
89 void clear_ids() { data_id = MISSING_INT; }
90 void set(
const wreport::Var& v)
93 var =
new wreport::Var(v);
95 void set(std::unique_ptr<wreport::Var>&& v)
101 void print(FILE* out)
const;
106 struct Values :
protected std::map<wreport::Varcode, values::Value>
111 typedef std::map<wreport::Varcode, values::Value>::const_iterator const_iterator;
112 typedef std::map<wreport::Varcode, values::Value>::iterator iterator;
113 const_iterator begin()
const {
return std::map<wreport::Varcode, values::Value>::begin(); }
114 const_iterator end()
const {
return std::map<wreport::Varcode, values::Value>::end(); }
115 iterator begin() {
return std::map<wreport::Varcode, values::Value>::begin(); }
116 iterator end() {
return std::map<wreport::Varcode, values::Value>::end(); }
117 size_t size()
const {
return std::map<wreport::Varcode, values::Value>::size(); }
118 bool empty()
const {
return std::map<wreport::Varcode, values::Value>::empty(); }
119 void clear() {
return std::map<wreport::Varcode, values::Value>::clear(); }
120 bool operator==(
const Values& o)
const;
122 const values::Value& operator[](wreport::Varcode code)
const;
128 void set(
const wreport::Var&);
129 void set(std::unique_ptr<wreport::Var>&&);
130 template<
typename C,
typename T>
void set(C code,
const T& val) { this->
set(
newvar(code, val)); }
131 void add_data_id(wreport::Varcode code,
int data_id);
132 void set_from_record(
const Record& rec);
135 for (
auto& i : *
this)
136 i.second.clear_ids();
139 void print(FILE* out)
const;
149 void set_from_record(
const Record& rec);
152 return info == o.info && values == o.values;
160 void print(FILE* out)
const;
170 void set_from_record(
const Record& rec);
173 return info == o.info && values == o.values;
181 void print(FILE* out)
const;
Coordinates.
Definition: types.h:320
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:565
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:515
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: core/defs.h:19
Date and time.
Definition: types.h:147
Implement ::dba_var, an encapsulation of a measured variable.
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
wreport::Varcode resolve_varcode(const char *name)
Resolve a variable name to a varcode proper, dealing with aliases and validation. ...