Public Member Functions

Calculator< Tag > Class Template Reference

Concrete Calculator. More...

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 specialization of this template class which is parameterized on a type Tag. This type uniquely identifies the Calculator.

Calculator<Tag> publicly derives from Processor and, additionally, it might be derived 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 publicly derive from Command.

Rather than declare Calculator<Tag> from scratch, providing all its base classes and declaring all its methods, the helper file keyvalue/mngt/DeclareCalculator.h should be used. This file expects some pre-processor macros to be #defined 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:

The macros above must be #defined before DeclareCalculator.h is #included and will be #undefined 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
 

Member Function Documentation

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.

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 favor of DataSet::process().

File DeclareCalculator.h provides 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 favor of DataSet::process().

File 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.