Public Member Functions

Calculator< Tag > Class Template Reference

Concrete Calculator. More...

#include <keyvalue/mngt/DeclareCalculator.h>

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

List of all members.

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.

Detailed Description

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

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:

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:

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

Member Function Documentation

const char* getName (  )  const [virtual]

Gets Calculator's name.

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

Parameters:
data : DataSet to be processed.
Returns:
The resulting value::Value.

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.

Parameters:
data : DataSet to be processed.
Returns:
The resulting value::Value.