diff options
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r-- | src/configuration.cpp | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp index c4f1cc360..624cf7865 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -217,6 +217,11 @@ int Configuration::getIntValue(const std::string &key) const defaultValue = 0; } } + else if (itdef->second->getType() == VariableData::DATA_FLOAT) + { + defaultValue = static_cast<int>( + (static_cast<FloatData*>(itdef->second))->getData()); + } } else { @@ -321,11 +326,38 @@ float Configuration::getFloatValue(const std::string &key) const { DefaultsData::const_iterator itdef = mDefaultsData->find(key); - if (itdef != mDefaultsData->end() && itdef->second - && itdef->second->getType() == VariableData::DATA_FLOAT) + if (itdef != mDefaultsData->end() && itdef->second) { - defaultValue = static_cast<float>( - (static_cast<FloatData*>(itdef->second))->getData()); + if (itdef->second->getType() == VariableData::DATA_FLOAT) + { + defaultValue = static_cast<float>( + (static_cast<FloatData*>(itdef->second))->getData()); + } + else if (itdef->second->getType() + == VariableData::DATA_STRING) + { + defaultValue = atof((static_cast<StringData*>( + itdef->second))->getData().c_str()); + } + else if (itdef->second->getType() + == VariableData::DATA_BOOL) + { + if ((static_cast<BoolData*>( + itdef->second))->getData()) + { + defaultValue = 1; + } + else + { + defaultValue = 0; + } + } + else if (itdef->second->getType() + == VariableData::DATA_INT) + { + defaultValue = (static_cast<IntData*>( + itdef->second))->getData(); + } } else { @@ -385,6 +417,18 @@ bool Configuration::getBoolValue(const std::string &key) const defaultValue = false; } } + if (itdef->second->getType() == VariableData::DATA_FLOAT) + { + if (static_cast<int>((static_cast<FloatData*>( + itdef->second))->getData()) != 0) + { + defaultValue = true; + } + else + { + defaultValue = false; + } + } } else { @@ -528,7 +572,8 @@ void ConfigurationObject::writeToXML(XmlTextWriterPtr writer) elt_it != it->second.end(); ++elt_it) { xmlTextWriterStartElement(writer, BAD_CAST name); - (*elt_it)->writeToXML(writer); + if (*elt_it) + (*elt_it)->writeToXML(writer); xmlTextWriterEndElement(writer); } @@ -572,14 +617,22 @@ void Configuration::write() xmlFreeTextWriter(writer); } -void Configuration::addListener( - const std::string &key, ConfigListener *listener) +void Configuration::addListener(const std::string &key, + ConfigListener *listener) { mListenerMap[key].push_front(listener); } -void Configuration::removeListener( - const std::string &key, ConfigListener *listener) +void Configuration::removeListener(const std::string &key, + ConfigListener *listener) { mListenerMap[key].remove(listener); } + +void Configuration::removeListeners(ConfigListener *listener) +{ + ListenerMapIterator it = mListenerMap.begin(); + ListenerMapIterator it_end = mListenerMap.end(); + for (; it != it_end; ++ it) + (it->second).remove(listener); +} |