summaryrefslogtreecommitdiff
path: root/src/configuration.cpp
diff options
context:
space:
mode:
authorReid <reidyaro@gmail.com>2012-03-01 22:03:01 +0100
committerReid <reidyaro@gmail.com>2012-03-01 22:03:01 +0100
commit490862919d79369112c75955a9c36ff8a081efd3 (patch)
tree6fe89466b9c53ba811f298174e6d787bbae71e09 /src/configuration.cpp
parentdff814619d63496acd3c4e8730b828b5d4d931fb (diff)
parentd873da3e8e57480016596f714845c1bc7e712e68 (diff)
downloadmv-490862919d79369112c75955a9c36ff8a081efd3.tar.gz
mv-490862919d79369112c75955a9c36ff8a081efd3.tar.bz2
mv-490862919d79369112c75955a9c36ff8a081efd3.tar.xz
mv-490862919d79369112c75955a9c36ff8a081efd3.zip
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r--src/configuration.cpp71
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);
+}