[75dc28] | 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 |
|
---|
[9d33ba] | 11 | #include "Actions/MapOfActions.hpp"
|
---|
[75dc28] | 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 |
|
---|
[9d33ba] | 22 | public:
|
---|
[03c902] | 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;
|
---|
[75dc28] | 36 | }
|
---|
[03c902] | 37 |
|
---|
| 38 | /** Sets a value in the storage.
|
---|
| 39 | * \param name key of value
|
---|
| 40 | * \param _T value
|
---|
| 41 | */
|
---|
[9d33ba] | 42 | template <typename T> void setCurrentValue(const char *name, T &_T) {
|
---|
[03c902] | 43 | MapOfActions_instance.setCurrentValue(name, _T);
|
---|
[75dc28] | 44 | }
|
---|
| 45 |
|
---|
[03c902] | 46 | /** Obtain a descriptive text for a given key.
|
---|
| 47 | * \param actionname key
|
---|
| 48 | * \return text describing the key's contents
|
---|
| 49 | */
|
---|
[4885f85] | 50 | const std::string getCurrentValue(std::string actionname);
|
---|
| 51 | const std::string getDescription(std::string actionname);
|
---|
| 52 | const std::string getShortForm(std::string actionname);
|
---|
| 53 | const std::type_info * getType(std::string actionname);
|
---|
[9d33ba] | 54 |
|
---|
[75dc28] | 55 | protected:
|
---|
| 56 | ValueStorage();
|
---|
| 57 | ~ValueStorage();
|
---|
[03c902] | 58 |
|
---|
| 59 | MapOfActions &MapOfActions_instance;
|
---|
[75dc28] | 60 | };
|
---|
| 61 |
|
---|
| 62 | #endif /* VALUESTORAGE_HPP_ */
|
---|