BSON C++ API  2.5.1
uma::bson
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
uma::bson::Element Class Reference

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.
 
ElementsetName (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 >
ElementsetValue (const DataType &dt)
 Set the value held in this element to the specified value.
 
Elementset (Value *val)
 Set the value held in this element to the specified value.
 
template<typename DataType >
Elementoperator= (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 >
ElementsetSimple (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 ElementsetValue (const double &v)
 Specialised method for setting the value to uma::bson::Double.
 
template<>
UMA_BSON_API ElementsetValue (const bool &v)
 Specialised method for setting the value to uma::bson::Boolean.
 
template<>
UMA_BSON_API ElementsetValue (const int32_t &v)
 Specialised method for setting the value to uma::bson::Integer.
 
template<>
UMA_BSON_API ElementsetValue (const int64_t &v)
 Specialised method for setting the value to uma::bson::Long.
 
template<>
UMA_BSON_API Elementoperator= (const double value)
 Specialised method for setting the value to uma::bson::Double.
 
template<>
UMA_BSON_API Elementoperator= (const std::string &value)
 Specialised method for setting the value to uma::bson::String.
 
template<>
UMA_BSON_API Elementoperator= (const char *value)
 Specialised method for setting the value to uma::bson::String.
 
template<>
UMA_BSON_API Elementoperator= (const bool value)
 Specialised method for setting the value to uma::bson::Boolean.
 
template<>
UMA_BSON_API Elementoperator= (const int32_t value)
 Specialised method for setting the value to uma::bson::Integer.
 
template<>
UMA_BSON_API Elementoperator= (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.
 

Detailed Description

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.

Date
Created 2012/09/05 19:49
Author
Rakesh
Version
Id:
Element.h 203 2013-02-15 12:23:15Z spt

Constructor & Destructor Documentation

uma::bson::Element::Element ( )
inline

Default CTOR.

template<typename DataType >
uma::bson::Element::Element ( const std::string &  fieldName,
const DataType &  v 
)
inline

Create a new element with the specified name and value.

Template Parameters
DataTypeThe type of value to store in the element.
Parameters
fieldNameThe field name for this element.
vThe value for the element
template<>
UMA_BSON_API uma::bson::Element::Element ( const std::string &  name,
const double &  value 
)

Specialised CTOR for an element holding a uma::bson::Double.

template<>
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.

template<>
UMA_BSON_API uma::bson::Element::Element ( const std::string &  name,
const bool &  value 
)

Specialised CTOR for an element holding a uma::bson::Boolean.

template<>
UMA_BSON_API uma::bson::Element::Element ( const std::string &  name,
const int &  value 
)

Specialised CTOR for an element holding a uma::bson::Integer.

template<>
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.

Member Function Documentation

static Element uma::bson::Element::createElement ( const std::string &  name,
Value value 
)
static

Create a new element with the specified name and value.

Warning
Note that this element takes ownership of the specified value instance. Callers must not delete the passed in value.
Since
Version 2.2
Parameters
nameThe field name of the this element
valueThe value of this element.
const std::string& uma::bson::Element::getName ( ) const
inline

Return the name of the element.

Returns
The field name.
UMA_BSON_API int64_t uma::bson::Element::getSimple< int64_t > ( ) const
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>();
Template Parameters
SimpleTypeThe primitive represented by the element value.
Returns
The simple value.
int32_t uma::bson::Element::getSize ( ) const
inline

Returns the total size in bytes the BSON representation of this element.

Returns
The size in bytes
Value::Type uma::bson::Element::getType ( ) const
inline

Returns the type for data stored in this element.

Returns
The current data type
template<typename DataType >
DataType& uma::bson::Element::getValue ( )
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.

Template Parameters
DataTypeThe type of value stored in the element.
Returns
The current value held in this element.
Exceptions
Poco::NullValueExceptionIf no value is currently held in this element.
Poco::BadCastExceptionIf the template type specified does not match the type held in this element.
template<typename DataType >
const DataType& uma::bson::Element::getValue ( ) const
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.

Template Parameters
DataTypeThe type of value stored in the element.
Returns
The current value held in this element.
Exceptions
Poco::NullValueExceptionIf no value is currently held in this element.
Poco::BadCastExceptionIf the template type specified does not match the type held in this element.
template<typename DataType >
Element& uma::bson::Element::operator= ( DataType  value)
inline

Copy assignment operator used to assign a new value to this element.

Warning
This element takes ownership of the passed in value instance. Callers must not delete the passed in value instance.
Since
Version 2.2
Template Parameters
DataTypeThe type of value stored in the element.
Parameters
valueThe new value to associate with this element.
Returns
This instance for method chaining.
template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const double  value)

Specialised method for setting the value to uma::bson::Double.

template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const std::string &  value)

Specialised method for setting the value to uma::bson::String.

template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const char *  value)

Specialised method for setting the value to uma::bson::String.

template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const bool  value)

Specialised method for setting the value to uma::bson::Boolean.

template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const int32_t  value)

Specialised method for setting the value to uma::bson::Integer.

template<>
UMA_BSON_API Element& uma::bson::Element::operator= ( const int64_t  value)

Specialised method for setting the value to uma::bson::Long.

Element& uma::bson::Element::set ( Value val)
inline

Set the value held in this element to the specified value.

Warning
Note that the element takes ownership of the specified value instance. Callers must not delete the passed in value.
Parameters
valThe value to set for this element.
Returns
This instance for method chaining.
Element& uma::bson::Element::setName ( const std::string &  name)
inline

Rename this element.

Warning
Note that this is an internal use only method. If you invoke this method from client code, the element may become invisible to the containing document. Client's should always use the methods in the document/array classes to manage elements, which in turn will invoke this method to update the instance as appropriate.
Parameters
nameThe new name for this element.
template<typename DataType >
Element& uma::bson::Element::setSimple ( const DataType  )
inline

Set the value for this element. This is supported only for the specialisations provided (primarily for setting simple primitive type values).

Template Parameters
DataTypeThe primitive value type.
Parameters
vThe value to set
Returns
This instance for method chaining.
template<typename DataType >
Element& uma::bson::Element::setValue ( const DataType &  dt)
inline

Set the value held in this element to the specified value.

Template Parameters
DataTypeThe type of value stored in the element.
Parameters
dtThe value to set for this element.
Returns
This instance for method chaining.
template<>
UMA_BSON_API Element& uma::bson::Element::setValue ( const double &  v)

Specialised method for setting the value to uma::bson::Double.

template<>
UMA_BSON_API Element& uma::bson::Element::setValue ( const bool &  v)

Specialised method for setting the value to uma::bson::Boolean.

template<>
UMA_BSON_API Element& uma::bson::Element::setValue ( const int32_t &  v)

Specialised method for setting the value to uma::bson::Integer.

template<>
UMA_BSON_API Element& uma::bson::Element::setValue ( const int64_t &  v)

Specialised method for setting the value to uma::bson::Long.


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