libdballe  7.21
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dballe::core::Record Class Reference

DB-All.E record. More...

#include <record.h>

Inheritance diagram for dballe::core::Record:
dballe::Record

Public Member Functions

 Record (const Record &rec)
 
std::unique_ptr< dballe::Recordclone () const override
 Return a copy of this record.
 
Recordoperator= (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::Varget (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.
 
- Public Member Functions inherited from dballe::Record
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::Varoperator[] (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 >
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 Recorddowncast (const dballe::Record &query)
 Return a reference to record downcasted as core::Record. More...
 
static Recorddowncast (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 Public Member Functions inherited from dballe::Record
static std::unique_ptr< Recordcreate ()
 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::Varget_item (wreport::Varcode code)
 Find an item by wreport::Varcode, raising an exception if not found.
 
const wreport::Varget_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::Varkey_peek (dba_keyword parameter) const throw ()
 Look at the value of a parameter. More...
 
const wreport::Varvar_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::Varobtain (const char *key)
 Return the Var for a key, creating it if it is missing.
 
wreport::Varobtain (dba_keyword key)
 Return the Var for a key, creating it if it is missing.
 
wreport::Varobtain (wreport::Varcode code)
 Return the Var for a variable, creating it if it is missing.
 

Protected Attributes

wreport::Varkeydata [DBA_KEY_COUNT]
 
std::vector< wreport::Var * > m_vars
 

Detailed Description

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.

Member Function Documentation

§ add()

void dballe::core::Record::add ( const dballe::Record source)
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.

Parameters
sourceThe record to copy data from.

Implements dballe::Record.

§ downcast() [1/2]

static const Record& dballe::core::Record::downcast ( const dballe::Record query)
static

Return a reference to record downcasted as core::Record.

Throws an exception if record is not a core::Record.

§ downcast() [2/2]

static Record& dballe::core::Record::downcast ( dballe::Record query)
static

Return a reference to record downcasted as core::Record.

Throws an exception if record is not a core::Record.

§ iter_keys()

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.

§ key_peek()

const wreport::Var* dballe::core::Record::key_peek ( dba_keyword  parameter) const
throw (
)
protected

Look at the value of a parameter.

Returns
A const pointer to the internal variable, or NULL if the variable has not been found.

§ key_unset()

void dballe::core::Record::key_unset ( dba_keyword  parameter)
protected

Remove a parameter from the record.

Parameters
parameterThe parameter to remove.

§ keyword_byname()

static dba_keyword dballe::core::Record::keyword_byname ( const char *  tag)
static

Get the dba_keyword corresponding to the given name.

Returns
The corresponding dba_keyword, or DBA_KEY_ERROR if tag does not match a valid keyword.

§ keyword_byname_len()

static dba_keyword dballe::core::Record::keyword_byname_len ( const char *  tag,
int  len 
)
static

Get the dba_keyword corresponding to the given name.

Parameters
tagThe name to query.
lenThe length of the name in tag.
Returns
The corresponding dba_keyword, or DBA_KEY_ERROR if tag does not match a valid keyword.

§ keyword_info()

static wreport::Varinfo dballe::core::Record::keyword_info ( dba_keyword  keyword)
static

Return informations about a keyword.

Returns
The wreport::Varinfo structure with the informations.

§ keyword_name()

static const char* dballe::core::Record::keyword_name ( dba_keyword  keyword)
static

Return the name of a dba_keyword.

Returns
The keyword name, or NULL if keyword is not a valid keyword

§ set_from_string()

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=-).

Parameters
strThe string containing the assignment.

§ set_from_test_string()

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_to_difference()

void dballe::core::Record::set_to_difference ( const Record source1,
const Record source2 
)

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.

Parameters
source1The original record to compute the changes from.
source2The new record that has changes over source1.

§ setc()

void dballe::core::Record::setc ( const char *  key,
const char *  val 
)
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.

§ setf()

void dballe::core::Record::setf ( const char *  key,
const char *  val 
)
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.

§ seti()

void dballe::core::Record::seti ( const char *  key,
int  val 
)
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.

§ sets()

void dballe::core::Record::sets ( const char *  key,
const std::string &  val 
)
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.

§ var_peek()

const wreport::Var* dballe::core::Record::var_peek ( wreport::Varcode  code) const
throw (
)
protected

Look at the value of a variable.

Returns
A const pointer to the internal variable, or NULL if the variable has not been found.

§ var_unset()

void dballe::core::Record::var_unset ( wreport::Varcode  code)
protected

Remove a parameter from the record.

Parameters
codeThe variable to remove. See vartable.h

The documentation for this class was generated from the following file: