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. | |
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. |
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.
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;
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 passed to process(const Processor& processor).
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.
ProcessDefault : When one tries to process "Default" DataSet.
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.
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. |
std::ostream& operator<< | ( | std::ostream & | os, | |
const DataSet & | dataSet | |||
) | [friend] |
ostream operator<<() for DataSet.