/* * ValueStorage.hpp * * Created on: Jul 22, 2010 * Author: heber */ #ifndef VALUESTORAGE_HPP_ #define VALUESTORAGE_HPP_ #include "Actions/MapOfActions.hpp" #include "Patterns/Singleton.hpp" /** ValueStorage serves as a mediator to MapOfActions. * This is needed to relax inter-dependencies between the Queries and the Actions. * I.e. this is the interface implemented in MapOfActions which both can safely rely on * to store&retrieve/exchange values. */ class ValueStorage : public Singleton { friend class Singleton; public: /** Gets a value from the storage * If the value is not present, an ASSERT is thrown unless optional is set to true. * \param _T key of value * \param optional whether this value is optional, i.e. may actually not be in the storage (i.e. may return false in this case). * \return true - value present, false - value not present (only given when optional set to true) */ template bool queryCurrentValue(const char *name, T &_T, const bool optional = false) { if (optional) { if (!MapOfActions_instance.isCurrentValuePresent(name)) return false; } MapOfActions_instance.queryCurrentValue(name, _T); return true; } /** Sets a value in the storage. * \param name key of value * \param _T value */ template void setCurrentValue(const char *name, T &_T) { MapOfActions_instance.setCurrentValue(name, _T); } /** Obtain a descriptive text for a given key. * \param actionname key * \return text describing the key's contents */ std::string getDescription(std::string actionname); protected: ValueStorage(); ~ValueStorage(); MapOfActions &MapOfActions_instance; }; #endif /* VALUESTORAGE_HPP_ */