Concrete Calculator. More...
Public Member Functions | |
const char * | getName () const |
Gets Calculator's name. | |
value::Result | getResult (const DataSet &data) const |
Gets the value::Value calculated from a DataSet. | |
value::Value | getValue (const DataSet &data) const |
Gets the value::Value calculated from a DataSet. |
Concrete Calculator.
Each Calculator is a specialization of this template class
which is parameterized on a type Tag. This type uniquely identifies the Calculator.
Calculator<Tag> public
ly derives from Processor and, additionally, it might be derived from other class
es depending on whether it has certain features or not. For instance, some Calculators are also commands and, in that case, they must public
ly derive from Command.
Rather than declare Calculator<Tag> from scratch, providing all its base class
es and declaring all its methods, the helper file keyvalue/mngt/DeclareCalculator.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, Calculator 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. The specialization Calculator<tag::TAG> public
ly derives from ProcessorInstantiator<tag::TAG>.#define
d if and only if Calculator<tag::TAG> is a command, in which case, it public
ly derives from Command and must implement its pure virtual
methods.The macros above must be #define
d before DeclareCalculator.h is #include
d and will be #undef
ined at the end of that file.
Calculator<tag::TAG> also derives from Processor and must implement its two virtual
methods. However, DeclareCalculator.h provides the implementation for Calculator<tag::TAG>::getResult() which just forwards the call to Calculator<tag::TAG>::getValue(). Hence, only Calculator<tag::TAG>::getName() needs to be implemented.
An example of how DeclareCalculator.h is used is given in keyvalue/bridge/processor/DeleteDataSets.cpp:
namespace keyvalue { #define TAG DeleteDataSets #define COMMAND #include "keyvalue/mngt/DeclareCalculator.h" /*-------------------------------------------------------------------------- * getName() *------------------------------------------------------------------------*/ const char* Calculator<tag::DeleteDataSets>::getName() const { return "DeleteDataSets"; } // ... } // namespace keyvalue
const char* getName | ( | ) | const [virtual] |
Gets Calculator's name.
File DeclareCalculator.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 value::Value calculated 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 DeclareCalculator.h provides the implementation of this method which simply forwards the call to getValue().
data | : DataSet to be processed. |
Implements Processor.
value::Value getValue | ( | const DataSet & | data | ) | const |
Gets the value::Value calculated from a DataSet.
Similarly to getResult() this is a low level method which should be avoided in favor of DataSet::process().
File DeclareCalculator.h does not provide the implementation of this method. Calculator writers must do it.
data | : DataSet to be processed. |