#include <keyvalue/mngt/DeclareBuilder.h>
Public Member Functions | |
const char * | getName () const |
Gets Builder's name. | |
value::Result | getResult (const DataSet &data) const |
Gets the object built from a DataSet. | |
shared_ptr< ObjectType > | getObject (const DataSet &data) const |
Gets the object built from a DataSet. |
Concrete Builder.
Each Builder is a specialization of this template class
which is parameterized on ObjectType, the type of object built.
Builder<OutputType> is associated to a type Tag which also uniquely identifies it. Actually, this extra type seems to be redundant since ObjectType also uniquely identifies the Builder. However some C++ technicalities and the way we want to do the processor registration into the ProcessorMngr enforce the use of Tag.
Builder<OutputType> derives from Processor and, additionally, it might derive from other class
es depending on whether it has certain features or not. For instance, some Builders are also commands and, in that case, they must public
ly derive from Command. On the same way, some Builders can build from value::Variant input (see documentation of BuilderFromVariant::getObject() for an example) in which case they must publicly derive from BuilderFromVariant<OutputType>.
Rather than declare Builder<OutputType> from scratch, providing all its base class
es and declaring all its methods, the helper file keyvalue/mngt/DeclareBuilder.h should be used. This file expects some pre-processor macros to be #define
d or not and based on that, it makes the correct declaration. Therefore, Builder writers must only #define
those macros and then #include
this file to get the right declaration. After that they must provide the implementations.
The macros are:
class
TAG (for which no implementation is required) inside namespace
tag. Builder<OBJECT_TYPE> public
ly derives from ProcessorInstantiator<tag::TAG>.#define
d if, and only if, Builder<OBJECT_TYPE> is a command, in which case, it public
ly derives from Command and must implement its pure virtual
methods.#define
d if, and only if, Builder<OBJECT_TYPE> is able to build the object from a bool
input. In that case, Builder<OBJECT_TYPE> public
ly derives from BuilderFrom<OBJECT_TYPE, bool>
and must implement its pure virtual
method.double
input.ptime
input.string
input.The macros above must be #define
d before DeclareBuilder.h is #include
d and will be #undef
ined at the end of that file.
Builder<OBJECT_TYPE> also derives from Processor and must implement its two virtual
methods. However, DeclareBuilder.h provides the implementation for Builder<OBJECT_TYPE>::getResult() which just forwards the call to Builder<OBJECT_TYPE>::getObject(). Hence, only Builder<OBJECT_TYPE>::getName() needs to be implemented.
An example of how DeclareBuilder.h is used is given in keyvalue/bridge/processor/Logger.cpp:
namespace keyvalue { #define OBJECT_TYPE logger::Logger #define TAG Logger #include "keyvalue/mngt/DeclareBuilder.h" *-------------------------------------------------------------------------- * getName() *------------------------------------------------------------------------*/ const char* Builder<logger::Logger>::getName() const { return "Logger"; } // ... } // namespace keyvalue
const char* getName | ( | ) | const [virtual] |
Gets Builder's name.
File DeclareBuilder.h does not provide the implementation of this method. Builder writers must do it.
Implements Processor.
value::Result getResult | ( | const DataSet & | data | ) | const [virtual] |
Gets the object built from a DataSet.
As said in Processor::getResult() documentation, this is a low level method which should be avoided in favor of DataSet::process().
File DeclareBuilder.h provides the implementation of this method which simply forwards the call to getObject().
data | : DataSet to be processed. |
Implements Processor.
shared_ptr<ObjectType> getObject | ( | const DataSet & | data | ) | const |
Gets the object built from a DataSet.
Similarly to getResult() this is a low level method which should be avoided in favor of DataSet::process().
File DeclareBuilder.h does not provide the implementation of this method. Builder writers must do it.
data | : DataSet to be processed. |