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

Holds data for database I/O. More...

#include <data.h>

Inheritance diagram for dballe::core::Data:
dballe::Data

Public Member Functions

 Data (const Data &rec)=default
 
 Data (Data &&rec)=default
 
Dataoperator= (const Data &rec)=default
 
Dataoperator= (Data &&rec)=default
 
bool operator== (const dballe::Data &rec) const override
 Check if two records are the same.
 
bool operator!= (const dballe::Data &rec) const override
 Check if two records differ.
 
void validate ()
 Check the data fields for consistency, and fill in missing values:
 
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 clear_ids () override
 Unset all database IDs in station and values.
 
void print (FILE *out) const override
 Print the contents of this record to the given stream.
 
void set_from_string (const char *str)
 Set a value according to an assignment encoded in a string.
 
void set_from_test_string (const std::string &s)
 Set the Data from a ", "-separated string of assignments.
 
std::string to_string () const
 Encode in a one-liner of comma-separated assignments.
 
virtual void clear ()=0
 Remove all contents from the record.
 
virtual void clear_ids ()=0
 Unset all database IDs in station and values.
 
virtual void clear_vars ()=0
 Remove all Bxxyyy keys from the record, leaving the rest intact.
 
virtual bool operator== (const Data &rec) const =0
 Check if two records are the same.
 
virtual bool operator!= (const Data &rec) const =0
 Check if two records differ.
 
virtual void print (FILE *out) const =0
 Print the contents of this record to the given stream.
 

Static Public Member Functions

static const Datadowncast (const dballe::Data &data)
 Return a reference to record downcasted as core::Record.
 
static Datadowncast (dballe::Data &data)
 Return a reference to record downcasted as core::Record.
 
- Static Public Member Functions inherited from dballe::Data
static std::unique_ptr< Datacreate ()
 Create a new Record.
 

Public Attributes

DBStation station
 
Datetime datetime
 
Level level
 
Trange trange
 
DBValues values
 

Protected Member Functions

void setf (const char *key, unsigned len, const char *val)
 

Detailed Description

Holds data for database I/O.

Data is a container for one observation of meteorological values, that includes station informations, physical location of the observation in time and space, and all the observed variables.

Constructor & Destructor Documentation

◆ ~Data()

dballe::core::Data::~Data ( )
virtual

Reimplemented from dballe::Data.

Member Function Documentation

◆ clear()

void dballe::core::Data::clear ( )
overridevirtual

Remove all contents from the record.

Implements dballe::Data.

◆ clear_ids()

void dballe::core::Data::clear_ids ( )
overridevirtual

Unset all database IDs in station and values.

Implements dballe::Data.

◆ clear_vars()

void dballe::core::Data::clear_vars ( )
overridevirtual

Remove all Bxxyyy keys from the record, leaving the rest intact.

Implements dballe::Data.

◆ downcast() [1/2]

static const Data & dballe::core::Data::downcast ( const dballe::Data data)
static

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

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

Referenced by dballe::tests::ActualCursor::data_var_matches().

◆ downcast() [2/2]

static Data & dballe::core::Data::downcast ( dballe::Data data)
static

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

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

◆ operator!=()

bool dballe::core::Data::operator!= ( const dballe::Data rec) const
overridevirtual

Check if two records differ.

Implements dballe::Data.

◆ operator==()

bool dballe::core::Data::operator== ( const dballe::Data rec) const
overridevirtual

Check if two records are the same.

Implements dballe::Data.

◆ print()

void dballe::core::Data::print ( FILE *  out) const
overridevirtual

Print the contents of this record to the given stream.

Implements dballe::Data.

◆ set_from_string()

void dballe::core::Data::set_from_string ( const char *  str)

Set a value 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::Data::set_from_test_string ( const std::string &  s)

Set the Data 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.

◆ validate()

void dballe::core::Data::validate ( )

Check the data fields for consistency, and fill in missing values:

  • month without year, day without month, and so on, cause errors
  • min and max datetimes are filled with the actual minimum and maximum values acceptable for that range (year=2017, for example, becomes min=2017-01-01 00:00:00, max=2017-12-31 23:59:59

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