Public Member Functions

Builder< ObjectType > Class Template Reference

Concrete Builder. More...

#include <keyvalue/mngt/DeclareBuilder.h>

Inheritance diagram for Builder< ObjectType >:
Inheritance graph
[legend]

List of all members.

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.

Detailed Description

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

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 classes depending on whether it has certain features or not. For instance, some Builders are also commands and, in that case, they must publicly 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 classes and declaring all its methods, the helper file keyvalue/mngt/DeclareBuilder.h should be used. This file expects some pre-processor macros to be #defined 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:

The macros above must be #defined before DeclareBuilder.h is #included and will be #undefined 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
 

Member Function Documentation

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.

Returns:
The name.

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().

Parameters:
data : DataSet to be processed.
Returns:
The object built.

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.

Parameters:
data : DataSet to be processed.
Returns:
The object built.