Public Member Functions | Private Member Functions

BuilderFromVariant< ObjectType > Class Template Reference

Base class for Builders that can build from value::Variant. More...

#include <keyvalue/mngt/BuilderFrom.h>

List of all members.

Public Member Functions

shared_ptr< ObjectType > getObject (const value::Variant &data) const
 Gets the object built by the derived Builder.

Private Member Functions

virtual const char * getName () const =0
template<typename InputType >
shared_ptr< ObjectType > build (const value::Variant &data) const
 Called by getObject.

Detailed Description

template<typename ObjectType>
class keyvalue::BuilderFromVariant< ObjectType >

Base class for Builders that can build from value::Variant.

Any Builder which can build from value::Variant must derive from this class. Additionally, it also must derive from at least one instantiation of template class BuilderFrom.

Parameters:
ObjectType : (template parameter) Type of object build by the derived Builder.

Member Function Documentation

shared_ptr< ObjectType > getObject ( const value::Variant data  )  const

Gets the object built by the derived Builder.

In general, the data that builders need to perform their duties is so rich that must be stored in a DataSet. Nevertheless, in some particular cases, a single value::Variant might be enough. For instance, consider a builder that creates a curve given a few points on it. Normally, this processor needs the set of points together with interpolator and extrapolator methods. In this general case, a DataSet is necessary to hold all this information. However, when the curve is known to be constant, then a single number - the constant - is enough to build the whole curve. Rather than creating a DataSet to store a single double value, it would be more convenient if the processor could accept just this value (or more generally, a value::Variant). That is the reason for this method.

Given the content type InputType of the provided value::Variant and assuming that the dynamic type of the derived object is BuilderFrom<ObjectType, InputType>, this method forwards its call to BuilderFrom<ObjectType, InputType>::getObject().

Parameters:
data : The input value::Variant.
Returns:
The object built by the derived Builder.
Exceptions:
LogicError : If the dynamic type of the derived object is not BuilderFrom<ObjectType, InputType>.
shared_ptr< ObjectType > build ( const value::Variant data  )  const [private]

Called by getObject.

See the documentation of getObject(). Actually, that method only detects InputType and then call this one.

Parameters:
data : The input value::Variant.
Returns:
The object built by the derived Builder.

@ throw LogicError : If the dynamic type of this is not BuildFrom<ObjectType, InputType>.