BSON C++ API
2.5.1
uma::bson
|
A class that represents a BSON element. Stores the name-value mapping for a BSON element in a PIMPL. This enables efficient copy-by-value semantics at the cost of shared data across the various copies of the element. More...
#include <Element.h>
Public Member Functions | |
Element () | |
Default CTOR. | |
template<typename DataType > | |
Element (const std::string &fieldName, const DataType &v) | |
Create a new element with the specified name and value. | |
const std::string & | getName () const |
Return the name of the element. | |
Element & | setName (const std::string &name) |
Rename this element. | |
template<typename DataType > | |
DataType & | getValue () |
Return a reference to the value held in this element for editing. | |
template<typename DataType > | |
const DataType & | getValue () const |
Return a constant reference to the value held in this element. | |
template<typename DataType > | |
Element & | setValue (const DataType &dt) |
Set the value held in this element to the specified value. | |
Element & | set (Value *val) |
Set the value held in this element to the specified value. | |
template<typename DataType > | |
Element & | operator= (DataType value) |
Copy assignment operator used to assign a new value to this element. | |
template<typename SimpleType > | |
SimpleType | getSimple () const |
A convenience method to retrieve the value of a simple type. This cannot be implemented as a template specialisation of the getValue() method since those methods return references to the value. | |
template<typename DataType > | |
Element & | setSimple (const DataType) |
Set the value for this element. This is supported only for the specialisations provided (primarily for setting simple primitive type values). | |
int32_t | getSize () const |
Returns the total size in bytes the BSON representation of this element. | |
Value::Type | getType () const |
Returns the type for data stored in this element. | |
template<> | |
UMA_BSON_API | Element (const std::string &name, const double &value) |
Specialised CTOR for an element holding a uma::bson::Double. | |
template<> | |
UMA_BSON_API | Element (const std::string &name, const std::string &value) |
Specialised CTOR for an element holding a uma::bson::String. | |
template<> | |
UMA_BSON_API | Element (const std::string &name, const bool &value) |
Specialised CTOR for an element holding a uma::bson::Boolean. | |
template<> | |
UMA_BSON_API | Element (const std::string &name, const int &value) |
Specialised CTOR for an element holding a uma::bson::Integer. | |
template<> | |
UMA_BSON_API | Element (const std::string &name, const int64_t &value) |
Specialised CTOR for an element holding a uma::bson::Long. | |
template<> | |
UMA_BSON_API Element & | setValue (const double &v) |
Specialised method for setting the value to uma::bson::Double. | |
template<> | |
UMA_BSON_API Element & | setValue (const bool &v) |
Specialised method for setting the value to uma::bson::Boolean. | |
template<> | |
UMA_BSON_API Element & | setValue (const int32_t &v) |
Specialised method for setting the value to uma::bson::Integer. | |
template<> | |
UMA_BSON_API Element & | setValue (const int64_t &v) |
Specialised method for setting the value to uma::bson::Long. | |
template<> | |
UMA_BSON_API Element & | operator= (const double value) |
Specialised method for setting the value to uma::bson::Double. | |
template<> | |
UMA_BSON_API Element & | operator= (const std::string &value) |
Specialised method for setting the value to uma::bson::String. | |
template<> | |
UMA_BSON_API Element & | operator= (const char *value) |
Specialised method for setting the value to uma::bson::String. | |
template<> | |
UMA_BSON_API Element & | operator= (const bool value) |
Specialised method for setting the value to uma::bson::Boolean. | |
template<> | |
UMA_BSON_API Element & | operator= (const int32_t value) |
Specialised method for setting the value to uma::bson::Integer. | |
template<> | |
UMA_BSON_API Element & | operator= (const int64_t value) |
Specialised method for setting the value to uma::bson::Long. | |
Static Public Member Functions | |
static Element | createElement (const std::string &name, Value *value) |
Create a new element with the specified name and value. | |
A class that represents a BSON element. Stores the name-value mapping for a BSON element in a PIMPL. This enables efficient copy-by-value semantics at the cost of shared data across the various copies of the element.
|
inline |
Default CTOR.
|
inline |
Create a new element with the specified name and value.
DataType | The type of value to store in the element. |
fieldName | The field name for this element. |
v | The value for the element |
UMA_BSON_API uma::bson::Element::Element | ( | const std::string & | name, |
const double & | value | ||
) |
Specialised CTOR for an element holding a uma::bson::Double.
UMA_BSON_API uma::bson::Element::Element | ( | const std::string & | name, |
const std::string & | value | ||
) |
Specialised CTOR for an element holding a uma::bson::String.
UMA_BSON_API uma::bson::Element::Element | ( | const std::string & | name, |
const bool & | value | ||
) |
Specialised CTOR for an element holding a uma::bson::Boolean.
UMA_BSON_API uma::bson::Element::Element | ( | const std::string & | name, |
const int & | value | ||
) |
Specialised CTOR for an element holding a uma::bson::Integer.
UMA_BSON_API uma::bson::Element::Element | ( | const std::string & | name, |
const int64_t & | value | ||
) |
Specialised CTOR for an element holding a uma::bson::Long.
Create a new element with the specified name and value.
delete
the passed in value.name | The field name of the this element |
value | The value of this element. |
|
inline |
Return the name of the element.
|
inline |
A convenience method to retrieve the value of a simple type. This cannot be implemented as a template specialisation of the getValue() method since those methods return references to the value.
Specialised method for getting the value of uma::bson::Long.
Specialised method for getting the value of uma::bson::Integer.
Specialised method for getting the value of uma::bson::Boolean.
Specialised method for getting the value of uma::bson::Double.
Template specialisations are provided for the common simple types (double
, string
, bool
, integer
, long
) which will work as expected. This method makes it easier to retrieve simple values than the full syntax. For example:
const double dval = elem->getValue<Double>().getValue();
becomes
const double dval = elem->getSimple<double>();
SimpleType | The primitive represented by the element value. |
|
inline |
Returns the total size in bytes the BSON representation of this element.
|
inline |
Returns the type for data stored in this element.
|
inline |
Return a reference to the value held in this element for editing.
If the template type specified does not match the current data type, or if the value is null
an exception is thrown.
DataType | The type of value stored in the element. |
Poco::NullValueException | If no value is currently held in this element. |
Poco::BadCastException | If the template type specified does not match the type held in this element. |
|
inline |
Return a constant reference to the value held in this element.
If the template type specified does not match the current data type, or if the value is null
an exception is thrown.
DataType | The type of value stored in the element. |
Poco::NullValueException | If no value is currently held in this element. |
Poco::BadCastException | If the template type specified does not match the type held in this element. |
|
inline |
Copy assignment operator used to assign a new value to this element.
delete
the passed in value instance.DataType | The type of value stored in the element. |
value | The new value to associate with this element. |
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const double | value | ) |
Specialised method for setting the value to uma::bson::Double.
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const std::string & | value | ) |
Specialised method for setting the value to uma::bson::String.
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const char * | value | ) |
Specialised method for setting the value to uma::bson::String.
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const bool | value | ) |
Specialised method for setting the value to uma::bson::Boolean.
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const int32_t | value | ) |
Specialised method for setting the value to uma::bson::Integer.
UMA_BSON_API Element& uma::bson::Element::operator= | ( | const int64_t | value | ) |
Specialised method for setting the value to uma::bson::Long.
Set the value held in this element to the specified value.
delete
the passed in value.val | The value to set for this element. |
|
inline |
Rename this element.
name | The new name for this element. |
|
inline |
Set the value for this element. This is supported only for the specialisations provided (primarily for setting simple primitive type values).
DataType | The primitive value type. |
v | The value to set |
|
inline |
Set the value held in this element to the specified value.
DataType | The type of value stored in the element. |
dt | The value to set for this element. |
UMA_BSON_API Element& uma::bson::Element::setValue | ( | const double & | v | ) |
Specialised method for setting the value to uma::bson::Double.
UMA_BSON_API Element& uma::bson::Element::setValue | ( | const bool & | v | ) |
Specialised method for setting the value to uma::bson::Boolean.
UMA_BSON_API Element& uma::bson::Element::setValue | ( | const int32_t & | v | ) |
Specialised method for setting the value to uma::bson::Integer.
UMA_BSON_API Element& uma::bson::Element::setValue | ( | const int64_t & | v | ) |
Specialised method for setting the value to uma::bson::Long.