From 0cd4bcd92680d9db51561c53bf6243f88686a26c Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Thu, 19 May 2011 21:03:15 -0300 Subject: [PATCH] type casts for config manager --- src/framework/core/configs.cpp | 7 ++----- src/framework/core/configs.h | 17 +++-------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/framework/core/configs.cpp b/src/framework/core/configs.cpp index 81d9afba..4fcc923f 100644 --- a/src/framework/core/configs.cpp +++ b/src/framework/core/configs.cpp @@ -32,9 +32,6 @@ bool Configs::load(const std::string& fileName) { m_fileName = fileName; - if(!g_resources.fileExists(fileName)) - return false; - std::stringstream fin; if(!g_resources.loadFile(fileName, fin)) return false; @@ -46,12 +43,12 @@ bool Configs::load(const std::string& fileName) for(auto it = doc.begin(); it != doc.end(); ++it) m_confsMap[yamlRead(it.first())] = yamlRead(it.second()); + + return true; } catch (YAML::Exception& e) { flogError("ERROR: Malformed config file: %s", e.what()); return false; } - - return true; } void Configs::save() diff --git a/src/framework/core/configs.h b/src/framework/core/configs.h index c58cb43f..846ee72f 100644 --- a/src/framework/core/configs.h +++ b/src/framework/core/configs.h @@ -27,33 +27,22 @@ #include -class ConfigValueProxy { -public: - ConfigValueProxy(const std::string& value) : value(value) { } +struct ConfigValueProxy { operator std::string() const { return convert_cast(value); } operator float() const { return convert_cast(value); } operator int() const { return convert_cast(value); } operator bool() const { return convert_cast(value); } - -private: std::string value; }; class Configs { public: - Configs() { } - - /// Read configuration file and parse all settings to memory bool load(const std::string& fileName); - - /// Dump all settings to configuration file void save(); - template - void setValue(const std::string& key, const T& value) { m_confsMap[key] = convert_cast(value); } - - ConfigValueProxy get(const std::string& key) { return ConfigValueProxy(m_confsMap[key]); } + template void setValue(const std::string& key, const T& value) { m_confsMap[key] = convert_cast(value); } + ConfigValueProxy get(const std::string& key) { return ConfigValueProxy{m_confsMap[key]}; } private: std::string m_fileName;