1 #ifndef DBALLE_VALUES_H 2 #define DBALLE_VALUES_H 8 #include <dballe/fwd.h> 9 #include <dballe/value.h> 21 typedef typename std::vector<Value>::const_iterator const_iterator;
22 typedef typename std::vector<Value>::iterator iterator;
25 std::vector<Value> m_values;
27 iterator insert_new(
Value&& val);
36 const_iterator begin()
const {
return m_values.begin(); }
37 const_iterator end()
const {
return m_values.end(); }
38 const_iterator cbegin()
const {
return m_values.cbegin(); }
39 const_iterator cend()
const {
return m_values.cend(); }
40 iterator begin() {
return m_values.begin(); }
41 iterator end() {
return m_values.end(); }
42 iterator find(wreport::Varcode code) noexcept;
43 const_iterator find(wreport::Varcode code)
const noexcept;
44 size_t size()
const {
return m_values.size(); }
45 bool empty()
const {
return m_values.empty(); }
46 void clear() {
return m_values.clear(); }
47 void reserve(
typename std::vector<Value>::size_type size)
49 m_values.reserve(size);
58 void set(std::unique_ptr<wreport::Var>&&);
61 void set(
Value&& val);
64 void unset(wreport::Varcode code);
73 template <
typename C,
typename T>
void set(
const C& code,
const T& val)
75 this->
set(
newvar(code, val));
78 template <
typename C,
typename T>
void setf(
const C& code,
const T& val)
82 this->
set(std::move(
var));
88 const Value&
value(wreport::Varcode code)
const;
93 const Value&
value(
const std::string& code)
const 95 return value(resolve_varcode(code));
125 const Value*
maybe_value(wreport::Varcode code)
const;
130 const Value*
maybe_value(
const std::string& code)
const 164 template <
typename C,
typename T> T
enq(C code,
const T& def)
183 void move_to(std::function<
void(std::unique_ptr<wreport::Var>)> dest);
186 void print(FILE* out)
const;
191 std::vector<uint8_t>
encode()
const;
201 static void decode(
const std::vector<uint8_t>& buf,
202 std::function<
void(std::unique_ptr<wreport::Var>)> dest);
205 extern template struct ValuesBase<Value>;
206 extern template struct ValuesBase<DBValue>;
217 using ValuesBase<Value>::ValuesBase;
232 using ValuesBase<DBValue>::ValuesBase;
241 bool vars_equal(
const DBValues& o)
const;
244 void set_data_id(wreport::Varcode code,
int data_id);
249 for (
auto& val : m_values)
250 val.data_id = MISSING_INT;
254 std::ostream& operator<<(std::ostream&,
const Values&);
255 std::ostream& operator<<(std::ostream&,
const DBValues&);
void move_to(std::function< void(std::unique_ptr< wreport::Var >)> dest)
Move all the Var passing them to the given function.
void move_to_attributes(wreport::Var &dest)
Move all the Var as attributes to dest.
const wreport::Var & var(wreport::Varcode code) const
Lookup a wreport::Var, throwing an exception if not found.
void unset(wreport::Varcode code)
Remove one variable.
const wreport::Var * maybe_var(wreport::Varcode code) const
Lookup a variable, returning nullptr if not found.
std::vector< uint8_t > encode() const
Encode these values in a DB-All.e specific binary representation.
Create wreport variables from the DB-All.e B table.
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:64
Collection of DBValue objects, indexed by wreport::Varcode.
Definition: values.h:229
void merge(const ValuesBase< Value > &vals)
Add all the variables from vals.
wreport::Varcode resolve_varcode(const char *name)
Resolve a variable name to a varcode proper, dealing with aliases and validation. ...
const Value & value(wreport::Varcode code) const
Lookup a value, throwing an exception if not found.
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.
static std::vector< uint8_t > encode_attrs(const wreport::Var &var)
Encode the attributes of var in a DB-All.e specific binary representation.
void print(FILE *out) const
Print the contents of this Values.
Container for a wreport::Var pointer.
Definition: value.h:18
void setf(const char *val)
T enq(C code, const T &def)
Get the value of a variable, or def if it is not set.
Definition: values.h:164
void clear_ids()
Reset all the database IDs.
Definition: values.h:247
const Value * maybe_value(wreport::Varcode code) const
Lookup a value, returning nullptr if not found.
Collection of Value objects, indexed by wreport::Varcode.
Definition: values.h:215