Abstract class that presents a more friendly ODM interface than uma::bson::Object.
More...
#include <ODMObject.h>
|
class | MetaField |
| Abstract base class that encapsulates a field in a model object. Primarily used to get around requirement that implementation needs exact type of data encapsulated in the field as template type. More...
|
|
class | MetaFieldImpl |
| Encapsulates a field in a model object. Fields are represented as a triplet of the field in the class, and its accessor and mutator methods. More...
|
|
|
virtual | ~ODMObject () |
| Virtual destructor for sub-classes.
|
|
const FieldNames | getFieldNames () const |
| Return the names of the fields registered. Note that the fields are stored in a std::map , hence the order of fields returned may not correspond to the order in which they were registered.
|
|
Value & | getValue (const std::string &name) |
| Return the value for the element with the specified name.
|
|
void | setValue (const std::string &name, const Value &value) |
| Set the value for the element with the specified name.
|
|
virtual | ~Object () |
| Virtual destructor for sub-classes.
|
|
virtual const Value & | getValue (const std::string &name) const |
| Constant version of getValue method.
|
|
virtual Object * | getObjectForArray (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 | 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.
|
|
virtual | ~Value () |
| Virtual DTOR for sub-classes.
|
|
const std::string & | getTypeName () const |
| Returns a standard textual value for this type.
|
|
|
void | registerField (const MetaFieldPtr mo) |
| Add (register) a field with the map of fields in the model object. Best practise is to check whether class has been registered (see registered, and if not, register all the fields for the class.
|
|
MetaFieldPtr | getMetaField (const std::string &name) |
| Return the meta field instance for the field with the specified name.
|
|
|
static bool | registered (Model *model) |
| Check to see if the class for the model object has been registered. Registration is the process of defining the fields with their accessor and mutator methods.
|
|
|
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.
|
|
static const std::string & | getTypeName (const Type type) |
| Return a descriptive text about the specified type.
|
|
template<typename Model>
class uma::bson::ODMObject< Model >
Abstract class that presents a more friendly ODM interface than uma::bson::Object.
This class uses a registration system for model objects to register their serialisable fields along with their accessor and mutator methods (see registerField. This removes the requirement to implement getValue using an ugly if-else
statement block.
- Warning
- Note: Model classes will need to provide a
non-const
version of the accessor methods for the registration to work.
- Template Parameters
-
Model | The type of the sub-class (needed for the MetaField implementation). |
- Since
- Version 2.5
- Date
- Created 2013/02/13 10:30
- Author
- Rakesh
- Version
- Id:
- ODMObject.h 207 2013-02-28 16:03:52Z spt
template<typename Model >
Shared pointer for a meta field instance.
template<typename Model >
Virtual destructor for sub-classes.
template<typename Model >
Return the names of the fields registered. Note that the fields are stored in a std::map
, hence the order of fields returned may not correspond to the order in which they were registered.
- Returns
- const FieldNames The
vector
of field names.
Implements uma::bson::Object.
template<typename Model >
Return the meta field instance for the field with the specified name.
- Parameters
-
name | The name of the field whose meta instance is to be retrieved. |
- Returns
- MetaFieldPtr The meta field representing the named field.
template<typename Model >
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
-
name | The name of the BSON element |
- Returns
- The value for the element.
- Exceptions
-
Poco::NotFoundException | If no element with specified name exists. |
Implements uma::bson::Object.
template<typename Model >
Check to see if the class for the model object has been registered. Registration is the process of defining the fields with their accessor and mutator methods.
- Parameters
-
model | The model object to check to see if registered. |
- Returns
- bool Returns
true
if already registered.
template<typename Model >
Add (register) a field with the map of fields in the model object. Best practise is to check whether class has been registered (see registered, and if not, register all the fields for the class.
- Parameters
-
mo | The shared pointer to the meta field instance. |
template<typename Model >
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
-
- Exceptions
-
Poco::InvalidArgumentException | Will 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::NotImplementedException | If the value specified is a complex type such as Value::Type::Object or Value::Type::Array . |
Reimplemented from uma::bson::Object.
The documentation for this class was generated from the following file:
- /Users/rakesh/projects/opensource/mongoviewer/bson/src/api/uma/bson/ODMObject.h