diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-09-08 22:43:00 +0200 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-09-08 22:43:00 +0200 |
commit | d6d215e2ab53322c769792b4aa53396ecce96422 (patch) | |
tree | ca1f73f1156f7a3eeccf2430a00d7bcdbd39d149 /src/common | |
parent | de803e103f5317856d4eadf15661ef7516cfc72a (diff) | |
download | manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.tar.gz manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.tar.xz manaserv-d6d215e2ab53322c769792b4aa53396ecce96422.zip |
Centralized stringToBool conversion.
Also moved the trim() function into the utils namespace
where it belongs more, and made some random code cleanups.
Reviewed-by: Thorbjorn.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/configuration.cpp | 15 | ||||
-rw-r--r-- | src/common/configuration.hpp | 9 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp index 0f0a584..a0e2ab2 100644 --- a/src/common/configuration.cpp +++ b/src/common/configuration.cpp @@ -27,6 +27,7 @@ #include "utils/logger.h" #include "utils/xml.hpp" +#include "utils/string.hpp" /**< Persistent configuration. */ static std::map< std::string, std::string > options; @@ -78,13 +79,23 @@ std::string Configuration::getValue(const std::string &key, const std::string &deflt) { std::map<std::string, std::string>::iterator iter = options.find(key); - if (iter == options.end()) return deflt; + if (iter == options.end()) + return deflt; return iter->second; } int Configuration::getValue(const std::string &key, int deflt) { std::map<std::string, std::string>::iterator iter = options.find(key); - if (iter == options.end()) return deflt; + if (iter == options.end()) + return deflt; return atoi(iter->second.c_str()); } + +bool Configuration::getBoolValue(const std::string &key, bool deflt) +{ + std::map<std::string, std::string>::iterator iter = options.find(key); + if (iter == options.end()) + return deflt; + return utils::stringToBool(iter->second.c_str(), deflt); +} diff --git a/src/common/configuration.hpp b/src/common/configuration.hpp index 0627c29..dbb0a7d 100644 --- a/src/common/configuration.hpp +++ b/src/common/configuration.hpp @@ -43,11 +43,18 @@ namespace Configuration std::string getValue(const std::string &key, const std::string &deflt); /** - * Gets an option as a string. + * Gets an option as an integer. * @param key option identifier. * @param deflt default value. */ int getValue(const std::string &key, int deflt); + + /** + * Gets an option as a boolean. + * @param key option identifier. + * @param deflt default value. + */ + bool getBoolValue(const std::string &key, bool deflt); } #ifndef DEFAULT_SERVER_PORT |