From ea946a63d1ec1726971a6e0a351a237611d89b02 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Sep 2011 19:01:13 +0300 Subject: Fix error with getting default configuration values. --- src/configuration.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/src/configuration.cpp b/src/configuration.cpp index 2524d6b93..a6ef27815 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -194,11 +194,32 @@ int Configuration::getIntValue(const std::string &key) const { DefaultsData::const_iterator itdef = mDefaultsData->find(key); - if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_INT) + if (itdef != mDefaultsData->end() && itdef->second) { - defaultValue = (static_cast( - itdef->second))->getData(); + if (itdef->second->getType() == Mana::VariableData::DATA_INT) + { + defaultValue = (static_cast( + itdef->second))->getData(); + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_STRING) + { + defaultValue = atoi((static_cast( + itdef->second))->getData().c_str()); + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_BOOL) + { + if ((static_cast( + itdef->second))->getData()) + { + defaultValue = 1; + } + else + { + defaultValue = 0; + } + } } else { @@ -249,11 +270,33 @@ std::string Configuration::getStringValue(const std::string &key) const { DefaultsData::const_iterator itdef = mDefaultsData->find(key); - if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_STRING) + if (itdef != mDefaultsData->end() && itdef->second) { - defaultValue = (static_cast( - itdef->second))->getData(); + if (itdef->second->getType() + == Mana::VariableData::DATA_STRING) + { + defaultValue = (static_cast( + itdef->second))->getData(); + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_BOOL) + { + if ((static_cast( + itdef->second))->getData()) + { + defaultValue = "1"; + } + else + { + defaultValue = "0"; + } + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_INT) + { + defaultValue = toString((static_cast( + itdef->second))->getData()); + } } else { @@ -312,11 +355,39 @@ bool Configuration::getBoolValue(const std::string &key) const { DefaultsData::const_iterator itdef = mDefaultsData->find(key); - if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == Mana::VariableData::DATA_BOOL) + if (itdef != mDefaultsData->end() && itdef->second) { - defaultValue = (static_cast( - itdef->second))->getData(); + if (itdef->second->getType() == Mana::VariableData::DATA_BOOL) + { + defaultValue = (static_cast( + itdef->second))->getData(); + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_INT) + { + if ((static_cast( + itdef->second))->getData() != 0) + { + defaultValue = true; + } + else + { + defaultValue = false; + } + } + else if (itdef->second->getType() + == Mana::VariableData::DATA_STRING) + { + if ((static_cast( + itdef->second))->getData() != "0") + { + defaultValue = true; + } + else + { + defaultValue = false; + } + } } else { -- cgit v1.2.3-70-g09d2