cumbia 1.x
general purpose multi threaded library
|
container for data exchange for the cumbia library and its clients More...
#include <cudata.h>
Public Member Functions | |
virtual | ~CuData () |
the class destructor More... | |
CuData () | |
constructor of an empty CuData More... | |
CuData (const CuVariant &v) | |
constructor of a CuData initialised with one value (key: emtpy string) More... | |
CuData (const std::string &key, const CuVariant &v) | |
constructor initialising a CuData with one key-value pair More... | |
CuData (const CuData &other) | |
the copy constructor More... | |
CuData (CuData &&other) | |
c++11 move constructor More... | |
virtual CuData & | operator= (const CuData &other) |
assignment operator, copies data from another source More... | |
virtual CuData & | operator= (CuData &&other) |
move assignment operator, moves contents from another source More... | |
CuData & | set (const std::string &key, const CuVariant &value) |
CuData & | merge (const CuData &other) |
CuData & | merge (const CuData &&other) |
CuData | clone () const |
clone this data, without sharing More... | |
CuData & | remove (const std::string &key) |
CuData | remove (const std::string &key) const |
CuData & | remove (const std::vector< std::string > &keys) |
CuData | remove (const std::vector< std::string > &keys) const |
size_t | size () const |
returns the number of key-value pairs stored More... | |
CuVariant | value () const |
return the value associated to the empty key More... | |
CuVariant | value (const std::string &key) const |
return a copy of the value associated with the given key, or an invalid and null CuVariant More... | |
void | add (const std::string &key, const CuVariant &value) |
insert the key/value into the bundle More... | |
bool | containsKey (const std::string &key) const |
returns true if the bundle contains the given key More... | |
bool | has (const std::string &key, const std::string &value) const |
returns true if the specified key has the given string value More... | |
CuVariant & | operator[] (const std::string &key) |
array subscript write operator; pushes a new key-value pair into the bundle More... | |
const CuVariant & | operator[] (const std::string &key) const |
array subscript read operator: get a reference to a value given the key More... | |
virtual bool | operator== (const CuData &other) const |
equality relational operator. Returns true if this CuData equals another More... | |
virtual bool | operator!= (const CuData &other) const |
inequality relational operator. Returns true if the equality operator CuData::operator == returns false More... | |
bool | isEmpty () const |
returns true if there are no key-value pairs stored More... | |
void | print () const |
prints the representation of the object provided by toString using printf More... | |
std::string | toString () const |
write a representation of this object into a std::string More... | |
void | putTimestamp () |
put date and time information into this object More... | |
std::vector< std::string > | keys () const |
std::string | s (const std::string &key) const |
double | d (const std::string &key) const |
int | i (const std::string &key) const |
unsigned int | u (const std::string &key) const |
bool | b (const std::string &key) const |
double | D (const std::string &key) const |
int | I (const std::string &key) const |
unsigned int | U (const std::string &key) const |
bool | B (const std::string &key) const |
std::vector< double > | DV (const std::string &key) const |
std::vector< int > | IV (const std::string &key) const |
std::vector< long long > | LLV (const std::string &key) const |
std::vector< unsigned int > | UV (const std::string &key) const |
std::vector< unsigned long int > | ULV (const std::string &key) const |
std::vector< unsigned long long int > | ULLV (const std::string &key) const |
std::vector< bool > | BV (const std::string &key) const |
container for data exchange for the cumbia library and its clients
CuData is a bundle that stores key-value pairs. The key is a std::string, the value is of type CuVariant. A copy of the value associated to a key can be obtained with CuData::value(const std::string& key). A value can be accessed with the [] operator. [] operators are defined in the const and non const flavours. The non const version allows to insert new CuVariant values with a string key within the square brackets.
The parameterless CuData::value version returns the value associated to an empty key, if there is one, created for example with the CuData::CuData(const CuVariant &v) constructor.
The number of key-value pairs stored by CuData can be queried with CuData::size. CuData::isEmpty returns true if the CuData has no key/value pair. CuData::containsKey tells whether a given key is or not in the bundle. CuData::add can be used to add a key-value pair. The result is equivalent to using the [] operator.
Two CuData can be compared with the == and != operators. The == operator returns true if the two bundles contain the same keys and each of their values correspond. The operator != returns the opposite value of the operator ==
The CuData::toString method returns a std::string representation of its contents. The contents of a CuData can be printed on the console by means of CuData::print
Data is implicitly shared, enabling copy on write. Atomic reference counters make the class reentrant, meaning that methods can be called from multiple threads, but only if each invocation uses its own data. Atomic reference counting is used to ensure the integrity of the shared data. Since cumbia 1.4.0, CuData uses implicit sharing as well.
|
virtual |
the class destructor
CuData class destructor
CuData::CuData | ( | ) |
CuData::CuData | ( | const CuVariant & | v | ) |
constructor of a CuData initialised with one value (key: emtpy string)
v | a CuVariant used to initialise a key/value pair where the key is an empty string. |
The parameter-less of CuData::value can be used to get the value associated to an empty key
CuData::CuData | ( | const std::string & | key, |
const CuVariant & | v | ||
) |
CuData::CuData | ( | const CuData & | other | ) |
CuData::CuData | ( | CuData && | other | ) |
void CuData::add | ( | const std::string & | key, |
const CuVariant & | value | ||
) |
insert the key/value into the bundle
key | the new key, as a std::string |
value | the new value bound to key |
References value().
Referenced by putTimestamp().
bool CuData::b | ( | const std::string & | key | ) | const |
References containsKey(), CuVariant::d(), and operator[]().
Referenced by B().
bool CuData::B | ( | const std::string & | key | ) | const |
References b(), containsKey(), operator[](), and CuVariant::to().
Referenced by CuDataSerializer::serialize().
std::vector< bool > CuData::BV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
CuData CuData::clone | ( | ) | const |
clone this data, without sharing
References d().
bool CuData::containsKey | ( | const std::string & | key | ) | const |
double CuData::d | ( | const std::string & | key | ) | const |
References CuVariant::d(), and operator[]().
Referenced by clone().
double CuData::D | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::to().
std::vector< double > CuData::DV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
bool CuData::has | ( | const std::string & | key, |
const std::string & | value | ||
) | const |
returns true if the specified key has the given string value
This method is a shortcut to test if to a given key is associated a string with the given value.
key | the key |
value | the value as string |
References value().
int CuData::i | ( | const std::string & | key | ) | const |
References CuVariant::i(), and operator[]().
int CuData::I | ( | const std::string & | key | ) | const |
References containsKey(), i, operator[](), and CuVariant::to().
bool CuData::isEmpty | ( | ) | const |
returns true if there are no key-value pairs stored
std::vector< int > CuData::IV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
std::vector< long long > CuData::LLV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
|
virtual |
inequality relational operator. Returns true if the equality operator CuData::operator == returns false
References operator==().
assignment operator, copies data from another source
other | another CuData which values will be copied into this |
move assignment operator, moves contents from another source
other | another CuData which values will be moved into this |
|
virtual |
equality relational operator. Returns true if this CuData equals another
other | another CuData (const reference) |
the inequality operator is also defined
Referenced by operator!=().
CuVariant & CuData::operator[] | ( | const std::string & | key | ) |
const CuVariant & CuData::operator[] | ( | const std::string & | key | ) | const |
array subscript read operator: get a reference to a value given the key
key | the key to search for |
void CuData::print | ( | ) | const |
prints the representation of the object provided by toString using printf
Prints a string representation of the contents of this object on the console, using printf.
References toString().
void CuData::putTimestamp | ( | ) |
put date and time information into this object
writes the following keys into this object, taking the system clock time from the gettimeofday call.
References add().
CuData & CuData::remove | ( | const std::string & | key | ) |
CuData CuData::remove | ( | const std::vector< std::string > & | keys | ) | const |
std::string CuData::s | ( | const std::string & | key | ) | const |
References operator[](), and CuVariant::s().
Referenced by CuDataSerializer::deserialize(), and CuDataSerializer::serialize().
References value().
Referenced by CuDataSerializer::deserialize().
size_t CuData::size | ( | ) | const |
returns the number of key-value pairs stored
std::string CuData::toString | ( | ) | const |
write a representation of this object into a std::string
All keys are printed with their values (CuVariant is always converted to string with CuVariant::toString). At last, the number of key/values stored and the flag returned by CuData::isEmpty are printed.
References i.
Referenced by print().
unsigned int CuData::u | ( | const std::string & | key | ) | const |
References operator[](), and CuVariant::u().
unsigned int CuData::U | ( | const std::string & | key | ) | const |
References containsKey(), i, operator[](), and CuVariant::to().
std::vector< unsigned long long > CuData::ULLV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
std::vector< unsigned long > CuData::ULV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
std::vector< unsigned int > CuData::UV | ( | const std::string & | key | ) | const |
References containsKey(), operator[](), and CuVariant::toVector().
CuVariant CuData::value | ( | ) | const |
return the value associated to the empty key
If there's no value associated to an empty key (i.e. an emtpy string, ""), an invalid and null CuVariant is returned. See CuVariant::isValid and CuVariant::isNull
CuVariant CuData::value | ( | const std::string & | key | ) | const |
return a copy of the value associated with the given key, or an invalid and null CuVariant