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.
value::Result process (const Processor &processor) const
 Processes a DataSet provided the Processor.
bool mustUpdate () const
 Checks if there is need for redoing the processing.

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
value::Result doProcess (const Processor &processor) const

Private Attributes

string name_
MapType_ map_
bool mustUpdate_
value::Result result_

Friends

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.

On the other hand. if resolution succeeds, this method processes the value associated to the key and in case of success a pointer to the processed value is returned. If the processing fails an exception indicating the error will be thrown.

This method is similar to getValue() below since both give access to the processed value corresponding to a specific key. The difference is how they report resolution failure. While find() returns a null pointer, getValue() throws an exception.

This method gives to the user the ability to set default values for unsolved 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 passed to process(const Processor& processor).

Returns:
Result of processing or a null pointer.
Exceptions:
RuntimeError : If key::Processor cannot be resolved or the processor is not registered.
value::Result process ( const Processor processor  )  const

Processes a DataSet provided the Processor.

Given a Processor processor, if key::Processor can be resolved for this DataSet and its corresponding value matches processor's name (i.e. processor.getName()), then this DataSet will be processed by processor and the result will be returned. Otherwise, an exception will be thrown.

Parameters:
processor : The Processor for this DataSet.
Returns:
The result of processing.

ProcessDefault : When one tries to process "Default" DataSet.

Exceptions:
RuntimeError : When the processing cannot be performed (see description above).
bool mustUpdate (  )  const

Checks if there is need for redoing the processing.

The two process() methods, pass this DataSet to the relevant Processor which will query for values through find() and getValue(). The memoization technique is applied: The DataSet will cache those values along the processing result. If the same processing is requested again, then the same values will be retrieved a second time.

The Processor can call this method which will 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.

Friends And Related Function Documentation

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

ostream operator<<() for DataSet.