Public Member Functions

Builder< Tag > Class Template Reference

Concrete Builder. More...

#include <keyvalue/mngt/DeclareBuilder.h>

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

List of all members.

Public Member Functions

const char * getName () const
 Gets Builders's name.
value::Result getResult (const DataSet &data) const
 Gets the object built from a DataSet.
const ::std::type_info & getObjectType () const
 Gets Builder's ObjectType.
value::PtrTraits< OBJECT_TYPE >
::Type_ 
getObject (const DataSet &data) const
 Gets the object built from a DataSet.
value::PtrTraits< OBJECT_TYPE >
::Type_ 
getObject (const BUILDS_FROM &data) const
 Gets the object built from a BUILDS_FROM.
template<typename ObjectType >
bool canBuild () const
 Checks if the Builder can build objects of a given type.

Detailed Description

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

Concrete Builder.

Each Builder is a specialisation of this template class which is parameterised on a type Tag. This type uniquely identifies the Builder.

Builder<Tag> derives from AbstractBuilder. 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 derive from Command. Similarly, some Builders can build from a basic input type (see documentation of BuilderFrom for an example) in which case they must derive from BuilderFrom<ObjectType, InputType>.

Rather than declaring Builder<Tag> from scratch, providing all base classes and declaring all methods, the helper file keyvalue/mngt/DeclareBuilder.h should be used. This file checks whether some pre-processor macros are #defined or not and, based on that, makes the correct declaration. Therefore, Builder writers need only to #define these macros and then #include that file to get the right declaration. They must provide implementation.

The macros are:

The macros above must be #defined before DeclareBuilder.h is #included. On exiting DeclareBuilder.h, these macros will be #undefined. Additionally, DeclareBuilder.h has no include guards and then, it can be included more than once allowing many Builders to be declared in the same file.

Derived from AbstractBuilder and Processor, Builder<tag::TAG> must implement their virtual methods:

However, DeclareBuilder.h provides implementations for the last two methods above. Hence, only getName() and getObject() need to be implemented by users.

An example of how DeclareBuilder.h is used is given in keyvalue/bridge/processor/Logger.cpp:

 namespace keyvalue {
 
 #define  OBJECT_TYPE keyvalue::logger::Logger
 #define  TAG         Logger
 #include "keyvalue/mngt/DeclareBuilder.h"
 
 /*--------------------------------------------------------------------------
  * getName()
  *------------------------------------------------------------------------*/
 
 const char*
 Builder<tag::Logger>::getName() const {
   return "Logger";
 }
 
 // ...
 
 } // namespace keyvalue


Member Function Documentation

const char* getName (  )  const [virtual]

Gets Builders's name.

DeclareBuilder.h does not provide the implementation of this method. Calculator 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 favour of DataSet::process().

DeclareBuilder.h does provide the implementation of this method which simply forwards the call to getObject().

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

Implements Processor.

const ::std::type_info& getObjectType (  )  const [virtual]

Gets Builder's ObjectType.

DeclareBuilder.h does provide the implementation of this method which simply forwards the call to getObject().

Returns:
std::type_info of Builder<span>'s ObjectType.

Implements AbstractBuilder.

value::PtrTraits<OBJECT_TYPE>::Type_ 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 favour of DataSet::process().

DeclareBuilder.h does not provide the implementation of this method. Users must do it.

Parameters:
data : DataSet to be processed.
Returns:
The object built.
value::PtrTraits<OBJECT_TYPE>::Type_ getObject ( const BUILDS_FROM &  data  )  const

Gets the object built from a BUILDS_FROM.

WARNING: This method is declared if, and only if, macro BUILDS_FROM is. (See explanation above.)

Parameters:
data : The input.
Returns:
The object built.
bool canBuild (  )  const [inherited]

Checks if the Builder can build objects of a given type.

Parameters:
ObjectType : (template parameter) The type to be checked against.
Returns:
This method returns true if the Builder can build objects of type ObjectType.