| 1 | /*
|
|---|
| 2 | * ValueStorage.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jul 22, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef VALUESTORAGE_HPP_
|
|---|
| 9 | #define VALUESTORAGE_HPP_
|
|---|
| 10 |
|
|---|
| 11 | #include "Actions/MapOfActions.hpp"
|
|---|
| 12 | #include "Patterns/Singleton.hpp"
|
|---|
| 13 |
|
|---|
| 14 | /** ValueStorage serves as a mediator to MapOfActions.
|
|---|
| 15 | * This is needed to relax inter-dependencies between the Queries and the Actions.
|
|---|
| 16 | * I.e. this is the interface implemented in MapOfActions which both can safely rely on
|
|---|
| 17 | * to store&retrieve/exchange values.
|
|---|
| 18 | */
|
|---|
| 19 | class ValueStorage : public Singleton<ValueStorage> {
|
|---|
| 20 | friend class Singleton<ValueStorage>;
|
|---|
| 21 |
|
|---|
| 22 | public:
|
|---|
| 23 | /** Gets a value from the storage
|
|---|
| 24 | * If the value is not present, an ASSERT is thrown unless optional is set to true.
|
|---|
| 25 | * \param _T key of value
|
|---|
| 26 | * \param optional whether this value is optional, i.e. may actually not be in the storage (i.e. may return false in this case).
|
|---|
| 27 | * \return true - value present, false - value not present (only given when optional set to true)
|
|---|
| 28 | */
|
|---|
| 29 | template <typename T> bool queryCurrentValue(const char *name, T &_T, const bool optional = false) {
|
|---|
| 30 | if (optional) {
|
|---|
| 31 | if (!MapOfActions_instance.isCurrentValuePresent(name))
|
|---|
| 32 | return false;
|
|---|
| 33 | }
|
|---|
| 34 | MapOfActions_instance.queryCurrentValue(name, _T);
|
|---|
| 35 | return true;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | /** Sets a value in the storage.
|
|---|
| 39 | * \param name key of value
|
|---|
| 40 | * \param _T value
|
|---|
| 41 | */
|
|---|
| 42 | template <typename T> void setCurrentValue(const char *name, T &_T) {
|
|---|
| 43 | MapOfActions_instance.setCurrentValue(name, _T);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | /** Obtain a descriptive text for a given key.
|
|---|
| 47 | * \param actionname key
|
|---|
| 48 | * \return text describing the key's contents
|
|---|
| 49 | */
|
|---|
| 50 | std::string getDescription(std::string actionname);
|
|---|
| 51 |
|
|---|
| 52 | protected:
|
|---|
| 53 | ValueStorage();
|
|---|
| 54 | ~ValueStorage();
|
|---|
| 55 |
|
|---|
| 56 | MapOfActions &MapOfActions_instance;
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | #endif /* VALUESTORAGE_HPP_ */
|
|---|