libdballe
7.29
|
DB-All.E record. More...
#include <record.h>
Public Member Functions | |
Record (const Record &rec) | |
std::unique_ptr< dballe::Record > | clone () const override |
Return a copy of this record. | |
Record & | operator= (const Record &rec) |
void | clear () override |
Remove all contents from the record. | |
void | clear_vars () override |
Remove all Bxxyyy keys from the record, leaving the rest intact. | |
void | seti (const char *key, int val) override |
Set a key to an integer value. More... | |
void | setd (const char *key, double val) override |
Set a key to a double value. | |
void | setc (const char *key, const char *val) override |
Set a key to a string value. More... | |
void | sets (const char *key, const std::string &val) override |
Set a key to a string value. More... | |
void | setf (const char *key, const char *val) override |
Set a key to a string value. More... | |
void | set_datetime (const Datetime &dt) override |
Set year, month, day, hour, min, sec. | |
void | set_datetimerange (const DatetimeRange &range) override |
Set datetime-min and datetime-max values. | |
void | set_coords (const Coords &c) override |
Set lat, lon. | |
void | set_latrange (const LatRange &lr) override |
Set latmin, latmax. | |
void | set_lonrange (const LonRange &lr) override |
Set lonmin, lonmax. | |
void | set_level (const Level &lev) override |
Set leveltype1, l1, leveltype2, l2. | |
void | set_trange (const Trange &tr) override |
Set pindicator, p1, p2. | |
void | set_var (const wreport::Var &var) override |
Set var.code() == var.value() | |
void | set_var_acquire (std::unique_ptr< wreport::Var > &&var) override |
Set var.code() == var. | |
void | unset (const char *name) override |
Remove/unset a key from the record. | |
const wreport::Var * | get (const char *key) const override |
Get a value, if set, or nullptr if not. | |
void | add (const dballe::Record &source) override |
Copy all data from the record source into dest. More... | |
bool | contains (const dballe::Record &subset) const override |
Return true if all elements of subset are present in this record, with the same value. | |
bool | equals (const dballe::Record &rec) const override |
Check if two records are the same. | |
void | foreach_key_ref (std::function< void(const char *, const wreport::Var &)> dest) const override |
void | foreach_key_copy (std::function< void(const char *, std::unique_ptr< wreport::Var > &&)> dest) const override |
void | print (FILE *out) const override |
Print the contents of this record to the given stream. | |
void | set_to_difference (const Record &source1, const Record &source2) |
Set the record to contain only those fields that change source1 into source2. More... | |
Level | get_level () const |
Compose a Level out of the leveltype1...l2 values. | |
Trange | get_trange () const |
Compose a Trange out of the pindicator...p2 values. | |
Datetime | get_datetime () const |
Compose a Datetime out of the year...sec values. | |
DatetimeRange | get_datetimerange () const |
Compose a DatetimeRange out of the yearmin...secmax values. | |
bool | iter_keys (std::function< bool(dba_keyword, const wreport::Var &)> f) const |
Iterate all keys in the record, calling f on them. More... | |
const std::vector < wreport::Var * > & | vars () const |
Return the varcode-sorted vector with the variables. | |
void | set_from_string (const char *str) |
Set a value in the record according to an assignment encoded in a string. More... | |
void | set_from_test_string (const std::string &s) |
Set a record from a ", "-separated string of assignments. More... | |
std::string | to_string () const |
Encode in a one-liner of comma-separated assignments. | |
![]() | |
void | set (const char *key, int val) |
void | set (const char *key, double val) |
void | set (const char *key, const char *val) |
void | set (const char *key, const std::string &val) |
void | set (const Datetime &dt) |
void | set (const DatetimeRange &dt) |
void | set (const Coords &c) |
void | set (const LatRange &lr) |
void | set (const LonRange &lr) |
void | set (const Level &lev) |
void | set (const Trange &tr) |
void | set (const wreport::Var &var) |
void | set (std::unique_ptr< wreport::Var > &&var) |
virtual bool | isset (const char *key) const |
Check if a value is set. | |
bool | operator== (const Record &rec) const |
Check if two records are the same. | |
bool | operator!= (const Record &rec) const |
Check if two records differ. | |
const wreport::Var & | operator[] (const char *key) const |
Get a value, if set, or throw an exception if not. | |
const char * | enq (const char *key, const char *def) const |
template<typename T > | |
T | enq (const char *key, const T &def) const |
void | foreach_key (std::function< void(const char *, const wreport::Var &)> dest) const |
Generate a sequence of key names and const Var& for all the contents of the record. | |
void | foreach_key (std::function< void(const char *, std::unique_ptr< wreport::Var > &&)> dest) const |
Generate a sequence of key names and unique_ptr<Var> for all the contents of the record. | |
Static Public Member Functions | |
static const Record & | downcast (const dballe::Record &query) |
Return a reference to record downcasted as core::Record. More... | |
static Record & | downcast (dballe::Record &query) |
Return a reference to record downcasted as core::Record. More... | |
static const char * | keyword_name (dba_keyword keyword) |
Return the name of a dba_keyword. More... | |
static wreport::Varinfo | keyword_info (dba_keyword keyword) |
Return informations about a keyword. More... | |
static dba_keyword | keyword_byname (const char *tag) |
Get the dba_keyword corresponding to the given name. More... | |
static dba_keyword | keyword_byname_len (const char *tag, int len) |
Get the dba_keyword corresponding to the given name. More... | |
![]() | |
static std::unique_ptr< Record > | create () |
Create a new Record. | |
static wreport::Varinfo | key_info (const char *key) |
Return informations about a key. More... | |
static wreport::Varinfo | key_info (const std::string &key) |
Return informations about a key. More... | |
Protected Member Functions | |
int | find_item (wreport::Varcode code) const throw () |
Find an item by wreport::Varcode, returning -1 if not found. | |
wreport::Var & | get_item (wreport::Varcode code) |
Find an item by wreport::Varcode, raising an exception if not found. | |
const wreport::Var & | get_item (wreport::Varcode code) const |
Find an item by wreport::Varcode, raising an exception if not found. | |
void | remove_item (wreport::Varcode code) |
Remove an item by wreport::Varcode. | |
const wreport::Var * | key_peek (dba_keyword parameter) const throw () |
Look at the value of a parameter. More... | |
const wreport::Var * | var_peek (wreport::Varcode code) const throw () |
Look at the value of a variable. More... | |
void | key_unset (dba_keyword parameter) |
Remove a parameter from the record. More... | |
void | var_unset (wreport::Varcode code) |
Remove a parameter from the record. More... | |
wreport::Var & | obtain (const char *key) |
Return the Var for a key, creating it if it is missing. | |
wreport::Var & | obtain (dba_keyword key) |
Return the Var for a key, creating it if it is missing. | |
wreport::Var & | obtain (wreport::Varcode code) |
Return the Var for a variable, creating it if it is missing. | |
Protected Attributes | |
wreport::Var * | keydata [DBA_KEY_COUNT] |
std::vector< wreport::Var * > | m_vars |
DB-All.E record.
A Record is a container for one observation of meteorological values, that includes anagraphical informations, physical location of the observation in time and space, and all the observed variables.
|
overridevirtual |
Copy all data from the record source into dest.
At the end of the function, dest will contain its previous values, plus the values in source. If a value is present both in source and in dest, the one in dest will be overwritten.
source | The record to copy data from. |
Implements dballe::Record.
|
static |
Return a reference to record downcasted as core::Record.
Throws an exception if record is not a core::Record.
|
static |
Return a reference to record downcasted as core::Record.
Throws an exception if record is not a core::Record.
bool dballe::core::Record::iter_keys | ( | std::function< bool(dba_keyword, const wreport::Var &)> | f | ) | const |
Iterate all keys in the record, calling f on them.
Iteration stops if f returns false.
The function returns true if it reached the end of the iteration, or false if it stopped because f returned false.
|
protected |
Look at the value of a parameter.
|
protected |
Remove a parameter from the record.
parameter | The parameter to remove. |
|
static |
Get the dba_keyword corresponding to the given name.
|
static |
Get the dba_keyword corresponding to the given name.
tag | The name to query. |
len | The length of the name in tag. |
|
static |
Return informations about a keyword.
|
static |
Return the name of a dba_keyword.
void dballe::core::Record::set_from_string | ( | const char * | str | ) |
Set a value in the record according to an assignment encoded in a string.
String can use keywords, aliases and varcodes. Examples: ana_id=3, name=Bologna, B12012=32.4
In case of numeric parameter, a hyphen ("-") means MISSING_INT (e.g., leveltype2=-
).
str | The string containing the assignment. |
void dballe::core::Record::set_from_test_string | ( | const std::string & | s | ) |
Set a record from a ", "-separated string of assignments.
The implementation is not efficient and the method is not safe for any input, since ", " could appear in a station identifier. It is however useful to quickly create test queries for unit testing.
Set the record to contain only those fields that change source1 into source2.
If a field has been deleted from source1 to source2, it will not be copied in dest.
source1 | The original record to compute the changes from. |
source2 | The new record that has changes over source1. |
|
overridevirtual |
Set a key to a string value.
If the key that is being set has a decimal component (like lat and lon), the string is converted to an integer value representing the units of maximum precision of the field. For example, using seti to set lat to "4500000" is the same as setting it to 45.0.
Implements dballe::Record.
|
overridevirtual |
Set a key to a string value.
Contrarily to setc, the string is parsed according to the natural representation for the given key. For example, if lat is set to "45", then it gets the value 45.0.
Also, if a Decimal or Integer value is assigned "-", it is unset instead.
Implements dballe::Record.
|
overridevirtual |
Set a key to an integer value.
If the key that is being set has a decimal component (like lat and lon), the integer value represents the units of maximum precision of the field. For example, using seti to set lat to 4500000 is the same as setting it to 45.0.
Implements dballe::Record.
|
overridevirtual |
Set a key to a string value.
If the key that is being set has a decimal component (like lat and lon), the string is converted to an integer value representing the units of maximum precision of the field. For example, using seti to set lat to "4500000" is the same as setting it to 45.0.
Implements dballe::Record.
|
protected |
Look at the value of a variable.
|
protected |
Remove a parameter from the record.
code | The variable to remove. See vartable.h |