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

Abstract base class that represents a BSON Object type. More...

#include <Object.h>

+ Inheritance diagram for uma::bson::Object:
+ Collaboration diagram for uma::bson::Object:

Public Types

typedef std::vector< std::string > FieldNames
 A container for the top-level fields in an object.
 
typedef FieldNames::const_iterator FieldsIterator
 Iterator for iterating over the top-level field names in an object.
 
- Public Types inherited from uma::bson::Value
enum  Type {
  Eoo = 0, Double = 1, String = 2, Object = 3,
  Array = 4, BinData = 5, Undefined = 6, OID = 7,
  Boolean = 8, Date = 9, Null = 10, RegEx = 11,
  DbRef = 12, Code = 13, Symbol = 14, CodeWScope = 15,
  Integer = 16, Timestamp = 17, Long = 18
}
 

Public Member Functions

virtual ~Object ()
 Virtual destructor for sub-classes.
 
virtual const FieldNames getFieldNames () const =0
 Return a vector of all the element names (top-level only) in this object.
 
virtual ValuegetValue (const std::string &name)=0
 Return the value for the element with the specified name.
 
virtual const ValuegetValue (const std::string &name) const
 Constant version of getValue method.
 
virtual ObjectgetObjectForArray (const std::string &)
 Return an empty instance of an object implementation that represents the type of data stored in an array type field.
 
virtual void setValue (const std::string &name, const Value &value)
 Set the value for the element with the specified name.
 
virtual void toBson (std::ostream &os) const
 Serialise the data in this object in BSON format to the specified output stream.
 
virtual void populate (std::istream &is)
 Populate the fields in this object from the BSON data stream. Complementary method to toBson.
 
int32_t getSize () const
 Return the size of the data as per BSON specifications.
 
Value::Type getType () const
 Returns the type for this instance as listed in the BSON specifications.
 
- Public Member Functions inherited from uma::bson::Value
virtual ~Value ()
 Virtual DTOR for sub-classes.
 
const std::string & getTypeName () const
 Returns a standard textual value for this type.
 

Additional Inherited Members

- Static Public Member Functions inherited from uma::bson::Value
static const std::string & getTypeName (const Type type)
 Return a descriptive text about the specified type.
 
- Protected Member Functions inherited from uma::bson::Value
 Value ()
 

Detailed Description

Abstract base class that represents a BSON Object type.

The primary purpose of this indirection is to allow client API to model BSON object instances as regular POD types. By implementing the methods in this abstract interface these classes automatically get support for serialisation to and from BSON.

Since
Version 2.2
Date
Created 2012/12/17 19:30
Author
Rakesh
Version
Id:
Object.h 192 2012-12-23 22:51:30Z spt

Member Typedef Documentation

typedef std::vector<std::string> uma::bson::Object::FieldNames

A container for the top-level fields in an object.

typedef FieldNames::const_iterator uma::bson::Object::FieldsIterator

Iterator for iterating over the top-level field names in an object.

Constructor & Destructor Documentation

virtual uma::bson::Object::~Object ( )
inlinevirtual

Virtual destructor for sub-classes.

Member Function Documentation

virtual const FieldNames uma::bson::Object::getFieldNames ( ) const
pure virtual

Return a vector of all the element names (top-level only) in this object.

Returns
The vector of element names.

Implemented in uma::bson::Document, and uma::bson::ODMObject< Model >.

virtual Object* uma::bson::Object::getObjectForArray ( const std::string &  )
inlinevirtual

Return an empty instance of an object implementation that represents the type of data stored in an array type field.

Array type fields are used to represent data stored in container classes in the class. This method is used primarily when de-serialising an object instance from its BSON representation. If the object being de-serialised contains array type data, this method will be used to determine the type of values stored in the array.

Note that container fields that store simple types (literally all types of values except Value::Type::Object) will in general not need any special support or this method to be implemented.

Note that the default implementation just throws an exception. This is done to avoid having to make this method a pure-virtual method. Not all model objects will need to store collections of values, and hence only objects that need to support collections need implement this method.

The calling method implemented in this API will populate the instance returned with the BSON data and save in an uma::bson::Element. The element instance takes ownership of the memory allocated for the instance returned. Implementations must not delete the instance returned.

Parameters
nameThe name of the array type field.
Returns
A new empty object instance that will be populated and stored in an uma::bson::Array.
int32_t uma::bson::Object::getSize ( ) const
virtual

Return the size of the data as per BSON specifications.

Returns
The size of the BSON data.

Implements uma::bson::Value.

Value::Type uma::bson::Object::getType ( ) const
inlinevirtual

Returns the type for this instance as listed in the BSON specifications.

Returns
Returns uma::bson::Value::Type::Object

Implements uma::bson::Value.

virtual Value& uma::bson::Object::getValue ( const std::string &  name)
pure virtual

Return the value for the element with the specified name.

This method is primarily intended to provide rudimentary ODM (object-document mapping) capabilities in the API. Model objects that extend this class and store fields as Value types may be serialised to BSON seamlessly. See unit test suite for a simple custom model object that is serialised to BSON.

Since
Version 2.2
Parameters
nameThe name of the BSON element
Returns
The value for the element.
Exceptions
Poco::NotFoundExceptionIf no element with specified name exists.

Implemented in uma::bson::Document, and uma::bson::ODMObject< Model >.

virtual const Value& uma::bson::Object::getValue ( const std::string &  name) const
inlinevirtual

Constant version of getValue method.

virtual void uma::bson::Object::populate ( std::istream &  is)
virtual

Populate the fields in this object from the BSON data stream. Complementary method to toBson.

Parameters
isThe BSON data stream from which this object instance is to be populated.
Exceptions
Poco::InvalidArgumentExceptionIf the bson data contains elements that do not match the fields in this class.
virtual void uma::bson::Object::setValue ( const std::string &  name,
const Value value 
)
virtual

Set the value for the element with the specified name.

This method is also used to provide rudimentary ODM capabilities in the API. Model objects that extend this class and store fields as Value types may be deserialised from BSON through this method. See unit test suite for a simple custom model object that is de-serialised from BSON.

Note that from Version 2.3 onwards a default implementation is provided. The default implementation handles setting the value for all the simple types. In particular Value::Type::Object, Value::Type::Array and consequently Value::Type::CodeWScope are not handled and may throw an exception. Despite this clients may still not need to provide an implementation of this method even if they store other object and array fields. The BSON deserialiser implemented in this API retrieves a reference to the current object/array from the destination instance and populates those. Hence if the only code using this method is from the internal BSON deserialiser, there will be no need to provide additional implementation for setting object/array fields.

Since
Version 2.2
Parameters
name
value
Exceptions
Poco::InvalidArgumentExceptionWill be thrown if the specified value type does not match the existing value type. May also be throw since this method invokes getValue( const std::string& ) at the beginning to fetch the current instance that is to be modified.
Poco::NotImplementedExceptionIf the value specified is a complex type such as Value::Type::Object or Value::Type::Array.

Reimplemented in uma::bson::Document, and uma::bson::ODMObject< Model >.

virtual void uma::bson::Object::toBson ( std::ostream &  os) const
virtual

Serialise the data in this object in BSON format to the specified output stream.

The default implementation uses uma::bson::io::ObjectWriter to serialise the fields returned by getFieldNames to the stream.

Parameters
osThe output stream to serialise the BSON data to.

Reimplemented in uma::bson::Document.


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