#include <keyvalue/mngt/DeclareBuilder.h>

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. | |
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:
class TAG (for which no implementation is required) inside namespace tag. Builder<tag::TAG> derives from ProcessorInstantiator<tag::TAG>.#defined if, and only if, Builder<tag::TAG> is a command, in which case, it derives from Command and, then, must implement its pure virtual methods.#defined if, and only if, Builder<tag::TAG> is able to build the object from a basic input type. This macro defines the input type that the Builder can build from. It can be set to one bool, double, ptime, string or unsigned int. If this macro is defined, then Builder<tag::TAG> derives from BuilderFrom<OBJECT_TYPE, BUILDS_FROM> and must implement its pure virtual method: shared_ptr<OBJECT_TYPE> getObject(const BUILDS_FROM& data) const;
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:
const char* getName() const; value::Result getResult(const DataSet& data) const; void thrower() const;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
| const char* getName | ( | ) | const [virtual] |
Gets Builders's name.
DeclareBuilder.h does not provide the implementation of this method. Calculator 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 favour of DataSet::process().
DeclareBuilder.h does provide the implementation of this method which simply forwards the call to getObject().
| data | : DataSet to be processed. |
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().
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.
| data | : DataSet to be processed. |
| 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.)
| data | : The input. |
1.7.1