summaryrefslogtreecommitdiff
path: root/src/configuration.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/configuration.cpp')
-rw-r--r--src/configuration.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp
index d8b11034..a6f691d8 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -98,6 +98,126 @@ ConfigurationObject::~ConfigurationObject()
clear();
}
+void Configuration::cleanDefaults()
+{
+ if (mDefaultsData)
+ {
+ for (DefaultsData::const_iterator iter = mDefaultsData->begin();
+ iter != mDefaultsData->end(); iter++)
+ {
+ if (iter->second)
+ delete(iter->second);
+ }
+ mDefaultsData->clear();
+ delete mDefaultsData;
+ mDefaultsData = 0;
+ }
+}
+
+Configuration::~Configuration()
+{
+ cleanDefaults();
+}
+
+void Configuration::setDefaultValues(DefaultsData *defaultsData)
+{
+ cleanDefaults();
+ mDefaultsData = defaultsData;
+}
+
+int Configuration::getIntValue(const std::string &key) const
+{
+ int defaultValue = 0;
+ if (mDefaultsData)
+ {
+ DefaultsData::const_iterator itdef = mDefaultsData->find(key);
+
+ if (itdef != mDefaultsData->end() && itdef->second
+ && itdef->second->getType() == Mana::VariableData::DATA_INT)
+ {
+ defaultValue = ((Mana::IntData*)itdef->second)->getData();
+ }
+ else
+ {
+ logger->log("%s: No integer value in registry for key %s",
+ mConfigPath.c_str(), key.c_str());
+ }
+ }
+ Options::const_iterator iter = mOptions.find(key);
+ return (iter != mOptions.end()) ? atoi(iter->second.c_str()) : defaultValue;
+}
+
+std::string Configuration::getStringValue(const std::string &key) const
+{
+ std::string defaultValue = "";
+ if (mDefaultsData)
+ {
+ DefaultsData::const_iterator itdef = mDefaultsData->find(key);
+
+ if (itdef != mDefaultsData->end() && itdef->second
+ && itdef->second->getType() == Mana::VariableData::DATA_STRING)
+ {
+ defaultValue = ((Mana::StringData*)itdef->second)->getData();
+ }
+ else
+ {
+ logger->log("%s: No string value in registry for key %s",
+ mConfigPath.c_str(), key.c_str());
+ }
+ }
+ Options::const_iterator iter = mOptions.find(key);
+ return (iter != mOptions.end()) ? iter->second : defaultValue;
+}
+
+
+float Configuration::getFloatValue(const std::string &key) const
+{
+ float defaultValue = 0.0f;
+ if (mDefaultsData)
+ {
+ DefaultsData::const_iterator itdef = mDefaultsData->find(key);
+
+ if (itdef != mDefaultsData->end() && itdef->second
+ && itdef->second->getType() == Mana::VariableData::DATA_FLOAT)
+ {
+ defaultValue = ((Mana::FloatData*)itdef->second)->getData();
+ }
+ else
+ {
+ logger->log("%s: No float value in registry for key %s",
+ mConfigPath.c_str(), key.c_str());
+ }
+ }
+ Options::const_iterator iter = mOptions.find(key);
+ return (iter != mOptions.end()) ? atof(iter->second.c_str()) : defaultValue;
+}
+
+bool Configuration::getBoolValue(const std::string &key) const
+{
+ bool defaultValue = false;
+ if (mDefaultsData)
+ {
+ DefaultsData::const_iterator itdef = mDefaultsData->find(key);
+
+ if (itdef != mDefaultsData->end() && itdef->second
+ && itdef->second->getType() == Mana::VariableData::DATA_BOOL)
+ {
+ defaultValue = ((Mana::BoolData*)itdef->second)->getData();
+ }
+ else
+ {
+ logger->log("%s: No boolean value in registry for key %s",
+ mConfigPath.c_str(), key.c_str());
+ }
+ }
+
+ Options::const_iterator iter = mOptions.find(key);
+ if (iter != mOptions.end())
+ return getBoolFromString(iter->second);
+ else
+ return defaultValue;
+}
+
void ConfigurationObject::initFromXML(xmlNodePtr parent_node)
{
clear();