Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

DataSet Class Reference

A named map from keys to values. More...

#include <keyvalue/mngt/DataSet.h>

List of all members.

Classes

struct  Graph
 Simplified dependency graph. More...
struct  Record
 A wrapper around a value::Value. More...

Public Member Functions

 DataSet (const string &name)
 Constructs an empty DataSet with a given name.
string getName () const
 Gets DataSet's name.
void add (const string &key, const value::Value &value)
 Adds a key-value pair to the DataSet.
template<typename KeyType >
KeyType::OutputType_ * find (const KeyType &key) const
 Checks if key can be found.
template<typename KeyType >
KeyType::OutputType_ getValue (const KeyType &key) const
 Gets and processes value associated to a key.
value::Result process () const
 Processes a DataSet.
template<typename ObjectType >
value::PtrTraits< ObjectType >
::Type_ 
build () const
 Builds the object defined by this DataSet provided its type.
bool mustUpdate () const
 Checks if there is need for reprocessing.

Private Types

typedef ::std::map< string,
shared_ptr< Record > > 
MapType_
typedef MapType_::value_type ValueType_

Private Member Functions

Graph getGraph (const string &key, bool start=true) const
 Gets the simplified dependency graph of a key.
Graph getGraph (shared_ptr< Record > first, const string &key) const
const ProcessorgetProcessor () const
 Gets the Processor expected to process this DataSet.
value::Result process (const Processor &processor) const
 Processes this DataSet by a given Processor.

Private Attributes

string name_
MapType_ map_
bool mustUpdate_
value::Result result_

Friends

friend::std::ostream & operator<< (::std::ostream &os, const DataSet &dataSet)
 ostream operator<<() for DataSet.

Detailed Description

A named map from keys to values.


Constructor & Destructor Documentation

DataSet ( const string &  name  )  [explicit]

Constructs an empty DataSet with a given name.

Parameters:
name : The DataSet's name.

Member Function Documentation

string getName (  )  const

Gets DataSet's name.

Returns:
The name of this DataSet.
void add ( const string &  key,
const value::Value value 
)

Adds a key-value pair to the DataSet.

Parameters:
key : The key;
value : The value.
KeyType::OutputType_ * find ( const KeyType &  key  )  const

Checks if key can be found.

This method checks if a key can be resolved. If resolution fails, then a null pointer is returned. Otherwise, this method processes the value associated to the key.

If the processing succeeds, then a pointer to the processed value is returned. If the processing fails an exception will be thrown.

Like getValue() (see below) this method gives access to the processed value corresponding to a specific key. The difference lies on how key resolution failures are reported. While find() returns a null pointer, getValue() throws an exception.

This method gives the ability to set default values for unresolved keys:

 // DataSet data;
 // ...
 //  const key::Single<bool> keyIsRegular("IsRegular");
 
 bool isRegular(true); // Set default value
 if (bool* ptr = data.find(keyIsRegular))
   isRegular = *ptr;
Parameters:
key : The key to be checked.
Returns:
If the key can be found, this method returns a pointer to the corresponding processed value. Otherwise it returns a null pointer.

Set dependency graph.

Memoization.

Check input container type.

Process raw value.

Cache output.

KeyType::OutputType_ getValue ( const KeyType &  key  )  const

Gets and processes value associated to a key.

Parameters:
KeyType : (template parameter) Key's dynamic type;
key : Key associated to the value to be retrieved.
Returns:
Processed value which is associated to key.
value::Result process (  )  const

Processes a DataSet.

If key::Processor can be resolved for this DataSet, then the corresponding Processor (retrieved from ProcessorMngr) will be called to process this DataSet.

Returns:
Result of processing.
Exceptions:
RuntimeError : If key::Processor cannot be resolved or if the processor named by key::Processor is not found.
value::PtrTraits< ObjectType >::Type_ build (  )  const

Builds the object defined by this DataSet provided its type.

The Processor named by key::Processor is retrieved and if it can build an object of type ObjectType, then the object is built and pointer to it is returned.

Parameters:
ObjectType : (template parameter) The type of object to be built.
Returns:
A pointer to the object.
bool mustUpdate (  )  const

Checks if there is need for reprocessing.

The process() method, pass this DataSet to the relevant Processor which will query for values through find() and getValue(). Memoization takes place and the DataSet caches these values and the processing result.

The Processor calls this method to compare the new and old (cached) set of values. If they agree this method returns false indicating that the result of previous processing is up to date and the Processor may return immediately.

Returns:
This method returns true if cached result of previous processing is out-of-date. Otherwise, it returns false.
Graph getGraph ( const string &  key,
bool  start = true 
) const [private]

Gets the simplified dependency graph of a key.

If a key K1 depends on K2 which, in turn depends on K3, and so on, up to Kn, then this method goes through all this dependency graph and returns a simplified version of it containing a pointer to K1 and another to Kn. Additionally, when walking through the graph this method checks if any node has changed since the last time this graph was calculated.

Parameters:
key : The starting key (K1 above);
start : This method is recursive and must be able to detected the root call (the called from outside this function) from the others (called by itself). This flag by default is set to true to indicate calling from outside.
const Processor& getProcessor (  )  const [private]

Gets the Processor expected to process this DataSet.

If key::Processor can be resolved for this DataSet, then the corresponding Processor (retrieved from ProcessorMngr) will be returned.

Returns:
The Processor expected to process this DataSet.
Exceptions:
RuntimeError : If key::Processor cannot be resolved or if the processor named by key::Processor is not registered in ProcessorMngr.
value::Result process ( const Processor processor  )  const [private]

Processes this DataSet by a given Processor.

This method does not check the given Processor's name against the value associated to key::Processor.

Parameters:
processor : The Processor that processes the DataSet.
Returns:
The result of the processing.

Friends And Related Function Documentation

::std::ostream& operator<< ( ::std::ostream &  os,
const DataSet dataSet 
) [friend]

ostream operator<<() for DataSet.