A named map from keys to values. More...
#include <keyvalue/mngt/DataSet.h>
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 Processor & | getProcessor () 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. |
A named map from keys to values.
DataSet | ( | const string & | name | ) | [explicit] |
void add | ( | const string & | key, | |
const value::Value & | value | |||
) |
Adds a key-value pair to the DataSet.
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;
key | : The key to be checked. |
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.
KeyType | : (template parameter) Key's dynamic type; | |
key | : Key associated to the value to be retrieved. |
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.
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.
ObjectType | : (template parameter) The type of object to be built. |
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.
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.
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.
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] |
::std::ostream& operator<< | ( | ::std::ostream & | os, | |
const DataSet & | dataSet | |||
) | [friend] |
ostream operator<<() for DataSet.