diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-07-28 19:57:31 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-07-28 19:57:31 +0200 |
commit | 2b1c0dcf269d617de1f6c203df547166661f089e (patch) | |
tree | 5d247d694f28ddbeb6e2da26b9db02eeab5c7480 /src/configuration.h | |
parent | 44d8856c777790449df46e3b5348a6a7433a75d8 (diff) | |
download | mana-2b1c0dcf269d617de1f6c203df547166661f089e.tar.gz mana-2b1c0dcf269d617de1f6c203df547166661f089e.tar.bz2 mana-2b1c0dcf269d617de1f6c203df547166661f089e.tar.xz mana-2b1c0dcf269d617de1f6c203df547166661f089e.zip |
Centralized configuration default values using the VariableData system.
Please note that I didn't turned all the getValue() call into new ones,
simply because I have to have config object initiated which is not
forcefully the case the branding file.
Resolves: Manasource Mantis #170.
Diffstat (limited to 'src/configuration.h')
-rw-r--r-- | src/configuration.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/configuration.h b/src/configuration.h index 908d13a4..761cc43b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -23,6 +23,7 @@ #define CONFIGURATION_H #include "utils/stringutils.h" +#include "defaults.h" #include <libxml/xmlwriter.h> @@ -192,7 +193,7 @@ class ConfigurationObject class Configuration : public ConfigurationObject { public: - virtual ~Configuration() {} + ~Configuration(); /** * Reads config file and parse all options into memory. @@ -203,6 +204,13 @@ class Configuration : public ConfigurationObject void init(const std::string &filename, bool useResManager = false); /** + * Set the default values for each keys. + * + * @param defaultsData data used as defaults. + */ + void setDefaultValues(DefaultsData *defaultsData); + + /** * Writes the current settings back to the config file. */ void write(); @@ -238,14 +246,30 @@ class Configuration : public ConfigurationObject inline void setValue(const std::string &key, bool value) { setValue(key, value ? "1" : "0"); } + /** + * returns a value corresponding to the given key. + * The default value returned in based on fallbacks registry. + * @see defaults.h + */ + int getIntValue(const std::string &key) const; + float getFloatValue(const std::string &key) const; + std::string getStringValue(const std::string &key) const; + bool getBoolValue(const std::string &key) const; + private: + /** + * Clean up the default values member. + */ + void cleanDefaults(); + typedef std::list<ConfigListener*> Listeners; typedef Listeners::iterator ListenerIterator; typedef std::map<std::string, Listeners> ListenerMap; typedef ListenerMap::iterator ListenerMapIterator; ListenerMap mListenerMap; - std::string mConfigPath; /**< Location of config file */ + std::string mConfigPath; /**< Location of config file */ + DefaultsData *mDefaultsData; /**< Defaults of value for a given key */ }; extern Configuration branding; |