Concrete Calculator. More...
#include <keyvalue/mngt/DeclareCalculator.h>

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 specialisation of this template class which is parameterised on a type Tag. This type uniquely identifies the Calculator.
Calculator<Tag> derives from Processor. Additionally, it might derive from other classes depending on whether it has certain features or not. For instance, some Calculators are also commands and, in that case, they must derive from Command.
Rather than declare Calculator<Tag> from scratch, providing all base classes and declaring all its methods, the helper file keyvalue/mngt/DeclareCalculator.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, Calculator writers need only to #define these macros and then #include that file to get the right declaration. They must provide the implementation.
The macros are:
class TAG (for which no implementation is required) inside namespace tag. Calculator<tag::TAG> derives from ProcessorInstantiator<tag::TAG>.#defined if, and only if, Calculator<tag::TAG> is a command, in which case, it derives from Command and, then, must implement its pure virtual methods.The macros above must be #defined before DeclareCalculator.h is #included. On exiting DeclareCalculator.h, these macros will be #undefined. Additionally, DeclareCalculator.h has no include guards and then, it can be included more than once allowing many Calculators to be declared in the same file.
Derived from Processor, Calculator<tag::TAG> must implement its virtual methods:
const char* getName() const; value::Result getResult(const DataSet& data) const;However, DeclareCalculator.h provides the implementation for the last method above. Hence, only getName() needs to be implemented by users.
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.
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 favour of DataSet::process().
DeclareCalculator.h does provide 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 favour of DataSet::process().
DeclareCalculator.h does not provide the implementation of this method. Calculator writers must do it.
| data | : DataSet to be processed. |
1.7.1