[Orxonox-commit 1818] r6536 - in code/trunk: . data/lua src/libraries/core src/libraries/core/input src/libraries/util src/modules/questsystem
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Mar 16 11:22:37 CET 2010
Author: rgrieder
Date: 2010-03-16 11:22:36 +0100 (Tue, 16 Mar 2010)
New Revision: 6536
Modified:
code/trunk/
code/trunk/data/lua/LuaStateInit.lua
code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc
code/trunk/src/libraries/core/ArgumentCompletionFunctions.h
code/trunk/src/libraries/core/ConfigFileManager.cc
code/trunk/src/libraries/core/ConfigFileManager.h
code/trunk/src/libraries/core/ConfigValueContainer.cc
code/trunk/src/libraries/core/ConfigValueContainer.h
code/trunk/src/libraries/core/ConfigValueIncludes.h
code/trunk/src/libraries/core/CorePrereqs.h
code/trunk/src/libraries/core/Identifier.cc
code/trunk/src/libraries/core/Identifier.h
code/trunk/src/libraries/core/Language.h
code/trunk/src/libraries/core/Shell.cc
code/trunk/src/libraries/core/Shell.h
code/trunk/src/libraries/core/input/Button.cc
code/trunk/src/libraries/core/input/Button.h
code/trunk/src/libraries/core/input/JoyStick.cc
code/trunk/src/libraries/core/input/KeyBinder.cc
code/trunk/src/libraries/core/input/KeyBinder.h
code/trunk/src/libraries/util/Singleton.h
code/trunk/src/modules/questsystem/QuestManager.cc
code/trunk/src/modules/questsystem/QuestManager.h
Log:
Merged revisions 6430-6440 from the gamestate branch to the trunk.
This adds keybindings merging functionality.
(from log of r6437)
When running development builds, the keybinder will merge the local file and the one from the data folder.
Catch: if you want to remove a binding, you'll have to write "NoBinding" (not case sensitive) to override the default command
The keybind command already does that for you though.
Property changes on: code/trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/console:5941-6104
/code/branches/core5:5768-5928,6009
/code/branches/ingamemenu:6000-6023
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/menu:5941-6146,6148
/code/branches/particles2:6050-6106,6109
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/presentation2:6106-6416
/code/branches/resource2:3372-5694
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
code/branches/buildsystem:1874-2276,2278-2400
code/branches/buildsystem2:2506-2658
code/branches/buildsystem3:2662-2708
code/branches/ceguilua:1802-1808
code/branches/core3:1572-1739
code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
code/branches/gametypes:2826-3031
code/branches/gcc43:1580
code/branches/gui:1635-1723,2795-2894
code/branches/input:1629-1636
code/branches/lodfinal:2372-2411
code/branches/map:2801-3086,3089
code/branches/miniprojects:2754-2824
code/branches/netp2:2835-2988
code/branches/netp3:2988-3082
code/branches/netp6:3214-3302
code/branches/network:2356
code/branches/network64:2210-2355
code/branches/objecthierarchy:1911-2085,2100,2110-2169
code/branches/objecthierarchy2:2171-2479
code/branches/overlay:2117-2385
code/branches/particles:2829-3085
code/branches/pch:3113-3194
code/branches/physics:1912-2055,2107-2439
code/branches/physics_merge:2436-2457
code/branches/pickups:1926-2086,2127,2827-2915
code/branches/pickups2:2107-2497,2915-3071
code/branches/presentation:2369-2652,2654-2660
code/branches/questsystem:1894-2088
code/branches/questsystem2:2107-2259
code/branches/questsystem5:2776-2905
code/branches/resource:3327-3366
code/branches/script_trigger:1295-1953,1955
code/branches/sound:2829-3010
code/branches/weapon:1925-2094
code/branches/weapon2:2107-2488
code/branches/weapons:2897-3051
code/branches/weaponsystem:2742-2890
+ /code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/console:5941-6104
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/gamestate:6430-6440
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/menu:5941-6146,6148
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network64:2210-2355
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/presentation:2369-2652,2654-2660
/code/branches/presentation2:6106-6416
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/script_trigger:1295-1953,1955
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
Modified: code/trunk/data/lua/LuaStateInit.lua
===================================================================
--- code/trunk/data/lua/LuaStateInit.lua 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/data/lua/LuaStateInit.lua 2010-03-16 10:22:36 UTC (rev 6536)
@@ -57,3 +57,14 @@
orxonox.execute = function(command)
orxonox.CommandExecutor:execute(command)
end
+
+-- Convenience function for config values
+orxonox.getConfig = function(section, entry)
+ return orxonox.SettingsConfigFile:getInstance():getConfig(section, entry)
+end
+orxonox.config = function(section, entry, value)
+ return orxonox.SettingsConfigFile:getInstance():config(section, entry, value)
+end
+orxonox.tconfig = function(section, entry, value)
+ return orxonox.SettingsConfigFile:getInstance():tconfig(section, entry, value)
+end
Modified: code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -35,6 +35,7 @@
#include "util/Convert.h"
#include "util/StringUtils.h"
#include "Identifier.h"
+#include "ConfigFileManager.h"
#include "ConfigValueContainer.h"
#include "TclThreadManager.h"
@@ -95,45 +96,48 @@
return filelist;
}
- ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)()
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)()
{
- ArgumentCompletionList classlist;
+ ArgumentCompletionList sectionList;
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
- if (it->second->hasConfigValues())
- classlist.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first)));
+ const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames();
+ for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
+ sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));
- return classlist;
+ return sectionList;
}
- ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section)
{
- ArgumentCompletionList configvalues;
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
+ ArgumentCompletionList entryList;
+ SettingsConfigFile& settings = SettingsConfigFile::getInstance();
+ const std::string& sectionLC = getLowercase(section);
- if (identifier != Identifier::getLowercaseStringIdentifierMapEnd() && identifier->second->hasConfigValues())
- {
- for (std::map<std::string, ConfigValueContainer*>::const_iterator it = identifier->second->getConfigValueMapBegin(); it != identifier->second->getConfigValueMapEnd(); ++it)
- configvalues.push_back(ArgumentCompletionListElement(it->first, getLowercase(it->first)));
- }
+ SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
+ for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
+ entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first));
- return configvalues;
+ return entryList;
}
- ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
+ ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section)
{
- ArgumentCompletionList oldvalue;
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
+ ArgumentCompletionList oldValue;
+ SettingsConfigFile& settings = SettingsConfigFile::getInstance();
+ const std::string& sectionLC = getLowercase(section);
+ const std::string& entryLC = getLowercase(entry);
+
+ SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
+ for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
{
- std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));
- if (variable != identifier->second->getLowercaseConfigValueMapEnd())
+ if (it->second.first == entryLC)
{
- const std::string& valuestring = variable->second->toString();
- oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
+ const std::string& valuestring = it->second.second->toString();
+ oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
}
}
- return oldvalue;
+
+ return oldValue;
}
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)()
Modified: code/trunk/src/libraries/core/ArgumentCompletionFunctions.h
===================================================================
--- code/trunk/src/libraries/core/ArgumentCompletionFunctions.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ArgumentCompletionFunctions.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -53,9 +53,9 @@
{
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment);
- ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalueclasses)();
- ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalues)(const std::string& fragment, const std::string& classname);
- ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname);
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingssections)();
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingsentries)(const std::string& fragment, const std::string& section);
+ ARGUMENT_COMPLETION_FUNCTION_DECLARATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section);
ARGUMENT_COMPLETION_FUNCTION_DECLARATION(tclthreads)();
}
}
Modified: code/trunk/src/libraries/core/ConfigFileManager.cc
===================================================================
--- code/trunk/src/libraries/core/ConfigFileManager.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ConfigFileManager.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -32,63 +32,12 @@
#include "util/Convert.h"
#include "util/Math.h"
-#include "util/StringUtils.h"
#include "ConsoleCommand.h"
#include "ConfigValueContainer.h"
#include "PathConfig.h"
namespace orxonox
{
- SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
- SetConsoleCommandShortcutExtern(tconfig).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue());
- SetConsoleCommandShortcutExtern(reloadConfig);
- SetConsoleCommandShortcutExtern(cleanConfig);
- SetConsoleCommandShortcutExtern(loadSettings).argumentCompleter(0, autocompletion::files());
-
- bool config(const std::string& classname, const std::string& varname, const std::string& value)
- {
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));
- if (variable != identifier->second->getLowercaseConfigValueMapEnd())
- return variable->second->set(value);
- }
- return false;
- }
-
- const std::string& getConfig(const std::string& classname, const std::string& varname)
- {
- return ConfigFileManager::getInstance().getValue(ConfigFileType::Settings, classname, varname, "", true);
- }
-
- bool tconfig(const std::string& classname, const std::string& varname, const std::string& value)
- {
- std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname));
- if (identifier != Identifier::getLowercaseStringIdentifierMapEnd())
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator variable = identifier->second->getLowercaseConfigValueMap().find(getLowercase(varname));
- if (variable != identifier->second->getLowercaseConfigValueMapEnd())
- return variable->second->tset(value);
- }
- return false;
- }
-
- void reloadConfig()
- {
- ConfigFileManager::getInstance().load();
- }
-
- void cleanConfig()
- {
- ConfigFileManager::getInstance().clean(false);
- }
-
- void loadSettings(const std::string& filename)
- {
- ConfigFileManager::getInstance().setFilename(ConfigFileType::Settings, filename);
- }
-
//////////////////////////
// ConfigFileEntryValue //
//////////////////////////
@@ -100,7 +49,7 @@
this->value_ = stripEnclosingQuotes(this->value_);
// Assemble the entry line
this->fileEntry_ = this->getKeyString() + " = ";
- if (this->bString_)
+ if (this->bString_ && !this->value_.empty())
this->fileEntry_ += '"' + addSlashes(this->value_) + '"';
else
this->fileEntry_ += this->value_;
@@ -144,7 +93,7 @@
}
}
- unsigned int ConfigFileSection::getVectorSize(const std::string& name)
+ unsigned int ConfigFileSection::getVectorSize(const std::string& name) const
{
unsigned int size = 0;
for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
@@ -165,8 +114,28 @@
return ('[' + this->name_ + "] " + this->additionalComment_);
}
- std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback, bool bString)
+ ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name) const
{
+ for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
+ {
+ if ((*it)->getName() == name)
+ return *it;
+ }
+ return NULL;
+ }
+
+ ConfigFileEntry* ConfigFileSection::getEntry(const std::string& name, unsigned int index) const
+ {
+ for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
+ {
+ if (((*it)->getName() == name) && ((*it)->getIndex() == index))
+ return *it;
+ }
+ return NULL;
+ }
+
+ std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString)
+ {
for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
{
if ((*it)->getName() == name)
@@ -178,10 +147,10 @@
this->bUpdated_ = true;
- return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryValue(name, fallback, bString)));
+ return this->entries_.insert(this->entries_.end(), new ConfigFileEntryValue(name, fallback, bString));
}
- std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+ std::list<ConfigFileEntry*>::iterator ConfigFileSection::getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
{
for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it)
{
@@ -195,35 +164,57 @@
this->bUpdated_ = true;
if (index == 0)
- return this->entries_.insert(this->entries_.end(), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
+ return this->entries_.insert(this->entries_.end(), new ConfigFileEntryVectorValue(name, index, fallback, bString));
else
- return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), static_cast<ConfigFileEntry*>(new ConfigFileEntryVectorValue(name, index, fallback, bString)));
+ return this->entries_.insert(++this->getOrCreateEntryIterator(name, index - 1, "", bString), new ConfigFileEntryVectorValue(name, index, fallback, bString));
}
////////////////
// ConfigFile //
////////////////
+
+ const char* ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig";
+
+ ConfigFile::ConfigFile(const std::string& filename, bool bCopyFallbackFile)
+ : filename_(filename)
+ , bCopyFallbackFile_(bCopyFallbackFile)
+ , bUpdated_(false)
+ {
+ }
+
ConfigFile::~ConfigFile()
{
this->clear();
}
- void ConfigFile::load(bool bCreateIfNotExisting)
+ void ConfigFile::load()
{
// Be sure we start from new in the memory
this->clear();
- // Get default file if necessary and available
- boost::filesystem::path filepath(PathConfig::getConfigPath() / this->filename_);
- if (!boost::filesystem::exists(filepath))
+ boost::filesystem::path filepath(this->filename_);
+ if (!filepath.is_complete())
{
- // Try to get default one from the data folder
- boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / "defaultConfig" / this->filename_);
- if (boost::filesystem::exists(defaultFilepath))
+ filepath = PathConfig::getConfigPath() / filepath;
+ if (this->bCopyFallbackFile_)
{
- COUT(3) << "Copied " << this->filename_ << " from the defaultConfig folder." << std::endl;
- boost::filesystem::copy_file(defaultFilepath, filepath);
+ // Look for default file in the data folder
+ if (!boost::filesystem::exists(filepath))
+ {
+ boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / DEFAULT_CONFIG_FOLDER / this->filename_);
+ if (boost::filesystem::exists(defaultFilepath))
+ {
+ // Try to copy default file from the data folder
+ try
+ {
+ boost::filesystem::copy_file(defaultFilepath, filepath);
+ COUT(3) << "Copied " << this->filename_ << " from the default config folder." << std::endl;
+ }
+ catch (const boost::filesystem::filesystem_error& ex)
+ { COUT(1) << "Error in ConfigFile: " << ex.what() << std::endl; }
+ }
+ }
}
}
@@ -299,7 +290,7 @@
if (convertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1)))
{
// New array
- std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
+ std::list<ConfigFileEntry*>::iterator it = newsection->getOrCreateEntryIterator(getStripped(line.substr(0, pos2)), index, value, false);
(*it)->setValue(value);
(*it)->setComment(comment);
continue;
@@ -318,25 +309,28 @@
COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl;
- // Save the file in case something changed (like stripped whitespaces)
- this->save();
-
- // Update all ConfigValueContainers
- this->updateConfigValues();
+ // DO NOT save the file --> we can open supposedly read only config files
} // end file.is_open()
}
void ConfigFile::save() const
{
+ this->saveAs(this->filename_);
+ }
+
+ void ConfigFile::saveAs(const std::string& filename) const
+ {
+ boost::filesystem::path filepath(filename);
+ if (!filepath.is_complete())
+ filepath = PathConfig::getConfigPath() / filename;
std::ofstream file;
- file.open((PathConfig::getConfigPathString() + filename_).c_str(), std::fstream::out);
+ file.open(filepath.string().c_str(), std::fstream::out);
file.setf(std::ios::fixed, std::ios::floatfield);
file.precision(6);
if (!file.is_open())
{
- COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl;
- COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl;
+ COUT(1) << "Error: Couldn't open config-file \"" << filename << "\"." << std::endl;
return;
}
@@ -345,75 +339,55 @@
file << (*it)->getFileEntry() << std::endl;
for (std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries)
- {
file << (*it_entries)->getFileEntry() << std::endl;
- }
file << std::endl;
}
file.close();
- COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl;
+ COUT(4) << "Saved config file \"" << filename << "\"." << std::endl;
}
- void ConfigFile::saveAs(const std::string& filename)
+ void ConfigFile::clear()
{
- std::string temp = this->filename_;
- this->filename_ = filename;
- this->save();
- this->filename_ = temp;
+ for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); )
+ delete (*(it++));
+ this->sections_.clear();
}
- void ConfigFile::clean(bool bCleanComments)
+ const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
{
- for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); )
+ const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, fallback, bString);
+ this->saveIfUpdated();
+ return output;
+ }
+
+ const std::string& ConfigFile::getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+ {
+ const std::string& output = this->getOrCreateSection(section)->getOrCreateValue(name, index, fallback, bString);
+ this->saveIfUpdated();
+ return output;
+ }
+
+ void ConfigFile::deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex)
+ {
+ if (ConfigFileSection* sectionPtr = this->getSection(section))
{
- std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName());
- if (it2 != Identifier::getStringIdentifierMapEnd() && it2->second->hasConfigValues())
- {
- // The section exists, delete comment
- if (bCleanComments)
- (*it1)->setComment("");
- for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); )
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it4 = it2->second->getConfigValueMap().find((*it3)->getName());
- if (it4 != it2->second->getConfigValueMapEnd())
- {
- // The config-value exists, delete comment
- if (bCleanComments)
- (*it3)->setComment("");
- ++it3;
- }
- else
- {
- // The config-value doesn't exist
- delete (*it3);
- (*it1)->entries_.erase(it3++);
- }
- }
- ++it1;
- }
- else
- {
- // The section doesn't exist
- delete (*it1);
- this->sections_.erase(it1++);
- }
+ sectionPtr->deleteVectorEntries(name, startindex);
+ this->save();
}
-
- // Save the file
- this->save();
}
- void ConfigFile::clear()
+ ConfigFileSection* ConfigFile::getSection(const std::string& section) const
{
- for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); )
- delete (*(it++));
- this->sections_.clear();
+ for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
+ if ((*it)->getName() == section)
+ return (*it);
+ return NULL;
}
- ConfigFileSection* ConfigFile::getSection(const std::string& section)
+ ConfigFileSection* ConfigFile::getOrCreateSection(const std::string& section)
{
for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it)
if ((*it)->getName() == section)
@@ -444,124 +418,207 @@
}
}
- void ConfigFile::updateConfigValues()
- {
- if (this->type_ == ConfigFileType::Settings)
- {
- for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it)
- {
- if (it->second->hasConfigValues())
- {
- for (std::map<std::string, ConfigValueContainer*>::const_iterator it2 = it->second->getConfigValueMapBegin(); it2 != it->second->getConfigValueMapEnd(); ++it2)
- it2->second->update();
- it->second->updateConfigValues();
- }
- }
- }
- }
+ ////////////////////////
+ // SettingsConfigFile //
+ ////////////////////////
+ SettingsConfigFile* SettingsConfigFile::singletonPtr_s = 0;
- ///////////////////////
- // ConfigFileManager //
- ///////////////////////
+ SettingsConfigFile::SettingsConfigFile(const std::string& filename)
+ : ConfigFile(filename)
+ {
+ ConsoleCommand* command = createConsoleCommand(createFunctor(&ConfigFile::load, this), "reloadSettings");
+ CommandExecutor::addConsoleCommandShortcut(command);
+ command = createConsoleCommand(createFunctor(&SettingsConfigFile::setFilename, this), "setSettingsFile");
+ CommandExecutor::addConsoleCommandShortcut(command);
+ command = createConsoleCommand(createFunctor(&SettingsConfigFile::config, this), "config");
+ CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
+ command = createConsoleCommand(createFunctor(&SettingsConfigFile::tconfig, this), "tconfig");
+ CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries()).argumentCompleter(2, autocompletion::settingsvalue());
+ command = createConsoleCommand(createFunctor(&SettingsConfigFile::getConfig, this), "getConfig");
+ CommandExecutor::addConsoleCommandShortcut(command).argumentCompleter(0, autocompletion::settingssections()).argumentCompleter(1, autocompletion::settingsentries());
+ }
- ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
-
- std::string ConfigFileManager::DEFAULT_CONFIG_FILE = "default.ini";
-
- ConfigFileManager::ConfigFileManager()
- : mininmalFreeType_(ConfigFileType::numberOfReservedTypes)
+ SettingsConfigFile::~SettingsConfigFile()
{
}
- ConfigFileManager::~ConfigFileManager()
+ void SettingsConfigFile::load()
{
- for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); )
- delete (it++)->second;
+ ConfigFile::load();
+ this->updateConfigValues();
}
- void ConfigFileManager::setFilename(ConfigFileType type, const std::string& filename)
+ void SettingsConfigFile::setFilename(const std::string& filename)
{
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- {
- assert(it->second);
- delete it->second;
- }
- this->configFiles_[type] = new ConfigFile(filename, type);
- this->load(type);
+ ConfigFileManager::getInstance().setFilename(ConfigFileType::Settings, filename);
}
- void ConfigFileManager::load()
+ void SettingsConfigFile::addConfigValueContainer(ConfigValueContainer* container)
{
- for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->load();
+ if (container == NULL)
+ return;
+ std::pair<std::string, ConfigValueContainer*> second(getLowercase(container->getName()), container);
+ this->containers_.insert(std::make_pair(getLowercase(container->getSectionName()), second));
+ this->sectionNames_.insert(container->getSectionName());
}
- void ConfigFileManager::save()
+ void SettingsConfigFile::removeConfigValueContainer(ConfigValueContainer* container)
{
- for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->save();
+ if (container == NULL)
+ return;
+ const std::string& sectionLC = getLowercase(container->getSectionName());
+ ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC);
+ for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it)
+ {
+ if (it->second.second == container)
+ {
+ // Remove entry from section name set this was the last container for that section
+ if (upper == this->containers_.lower_bound(sectionLC))
+ this->sectionNames_.erase(container->getSectionName());
+ this->containers_.erase(it);
+ break;
+ }
+ }
}
- void ConfigFileManager::clean(bool bCleanComments)
+ void SettingsConfigFile::updateConfigValues()
{
- for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- this->clean(it->first, bCleanComments);
+ for (ContainerMap::const_iterator it = this->containers_.begin(); it != this->containers_.end(); ++it)
+ {
+ it->second.second->update();
+ it->second.second->getIdentifier()->updateConfigValues();
+ }
}
- void ConfigFileManager::load(ConfigFileType type)
+ void SettingsConfigFile::clean(bool bCleanComments)
{
- this->getFile(type)->load();
+ for (std::list<ConfigFileSection*>::iterator itSection = this->sections_.begin(); itSection != this->sections_.end(); )
+ {
+ const std::string& sectionLC = getLowercase((*itSection)->getName());
+ ContainerMap::const_iterator lower = this->containers_.lower_bound(sectionLC);
+ ContainerMap::const_iterator upper = this->containers_.upper_bound(sectionLC);
+ if (lower != upper)
+ {
+ // The section exists, delete comment
+ if (bCleanComments)
+ (*itSection)->setComment("");
+ for (std::list<ConfigFileEntry*>::iterator itEntry = (*itSection)->entries_.begin(); itEntry != (*itSection)->entries_.end(); )
+ {
+ const std::string& entryLC = getLowercase((*itEntry)->getName());
+ bool bFound = false;
+ for (ContainerMap::const_iterator itContainer = lower; itContainer != upper; ++itContainer)
+ {
+ if (itContainer->second.first == entryLC)
+ {
+ // The config-value exists, delete comment
+ if (bCleanComments)
+ (*itEntry)->setComment("");
+ ++itEntry;
+ bFound = true;
+ break;
+ }
+ }
+ if (!bFound)
+ {
+ // The config-value doesn't exist
+ delete (*itEntry);
+ (*itSection)->entries_.erase(itEntry++);
+ }
+ }
+ ++itSection;
+ }
+ else
+ {
+ // The section doesn't exist
+ delete (*itSection);
+ this->sections_.erase(itSection++);
+ }
+ }
+
+ // Save the file
+ this->save();
}
- void ConfigFileManager::save(ConfigFileType type)
+ bool SettingsConfigFile::config(const std::string& section, const std::string& entry, const std::string& value)
{
- this->getFile(type)->save();
+ return this->configImpl(section, entry, value, &ConfigValueContainer::set);
}
- void ConfigFileManager::saveAs(ConfigFileType type, const std::string& saveFilename)
+ bool SettingsConfigFile::tconfig(const std::string& section, const std::string& entry, const std::string& value)
{
- this->getFile(type)->saveAs(saveFilename);
+ return this->configImpl(section, entry, value, &ConfigValueContainer::tset);
}
- void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments)
+ bool SettingsConfigFile::configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&))
{
- this->getFile(type)->clean(bCleanComments);
+ const std::string& sectionLC = getLowercase(section);
+ const std::string& entryLC = getLowercase(entry);
+ ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC);
+ for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it)
+ {
+ // Note: Config value vectors cannot be supported
+ if (it->second.first == entryLC && !it->second.second->isVector())
+ {
+ return (it->second.second->*function)(value);
+ }
+ }
+ return false;
}
- void ConfigFileManager::updateConfigValues()
+ std::string SettingsConfigFile::getConfig(const std::string& section, const std::string& entry)
{
- for (std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
- it->second->updateConfigValues();
+ const std::string& sectionLC = getLowercase(section);
+ const std::string& entryLC = getLowercase(entry);
+ ContainerMap::iterator upper = this->containers_.upper_bound(sectionLC);
+ for (ContainerMap::iterator it = this->containers_.lower_bound(sectionLC); it != upper; ++it)
+ {
+ // Note: Config value vectors cannot be supported
+ if (it->second.first == entryLC && ! it->second.second->isVector())
+ {
+ std::string value;
+ it->second.second->getValue<std::string, OrxonoxClass>(&value, NULL);
+ return value;
+ }
+ }
+ return "";
}
- void ConfigFileManager::updateConfigValues(ConfigFileType type)
+
+ ///////////////////////
+ // ConfigFileManager //
+ ///////////////////////
+
+ ConfigFileManager* ConfigFileManager::singletonPtr_s = 0;
+
+ ConfigFileManager::ConfigFileManager()
{
- this->getFile(type)->updateConfigValues();
+ this->configFiles_.assign(NULL);
}
- const std::string& ConfigFileManager::getFilename(ConfigFileType type)
+ ConfigFileManager::~ConfigFileManager()
{
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- return it->second->getFilename();
- else
- return BLANKSTRING;
+ for (boost::array<ConfigFile*, 3>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it)
+ if (*it)
+ delete (*it);
}
- ConfigFile* ConfigFileManager::getFile(ConfigFileType type)
+ void ConfigFileManager::setFilename(ConfigFileType::Value type, const std::string& filename)
{
- std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type);
- if (it != this->configFiles_.end())
- return it->second;
- else
+ if (this->getConfigFile(type))
+ delete this->configFiles_[type];
+ // Create and load config file
+ switch (type)
{
- COUT(1) << "ConfigFileManager: Can't find a config file for type with ID " << static_cast<int>(type) << std::endl;
- COUT(1) << "Using " << DEFAULT_CONFIG_FILE << " file." << std::endl;
- this->setFilename(type, DEFAULT_CONFIG_FILE);
- return getFile(type);
+ case ConfigFileType::Settings:
+ this->configFiles_[type] = new SettingsConfigFile(filename);
+ break;
+ case ConfigFileType::JoyStickCalibration:
+ case ConfigFileType::CommandHistory:
+ this->configFiles_[type] = new ConfigFile(filename);
+ break;
}
+ this->configFiles_[type]->load();
}
}
Modified: code/trunk/src/libraries/core/ConfigFileManager.h
===================================================================
--- code/trunk/src/libraries/core/ConfigFileManager.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ConfigFileManager.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -31,40 +31,18 @@
#include "CorePrereqs.h"
-#include <cassert>
-#include <string>
#include <list>
#include <map>
+#include <set>
+#include <string>
+#include <boost/array.hpp>
-#include "util/OrxEnum.h"
#include "util/Singleton.h"
+#include "util/StringUtils.h"
-// tolua_begin
-namespace orxonox
-{
- // tolua_end
- // Use int as config file type to have an arbitrary number of files
- struct ConfigFileType : OrxEnum<ConfigFileType>
- {
- OrxEnumConstructors(ConfigFileType);
+namespace orxonox // tolua_export
+{ // tolua_export
- static const int NoType = 0;
- static const int Settings = 1;
- static const int JoyStickCalibration = 2;
- static const int CommandHistory = 3;
-
- static const int numberOfReservedTypes = 1024;
- };
-
- _CoreExport bool config(const std::string& classname, const std::string& varname, const std::string& value); // tolua_export
- _CoreExport const std::string& getConfig(const std::string& classname, const std::string& varname); // tolua_export
- _CoreExport bool tconfig(const std::string& classname, const std::string& varname, const std::string& value);
- _CoreExport void reloadConfig();
- _CoreExport void saveConfig();
- _CoreExport void cleanConfig();
- _CoreExport void loadSettings(const std::string& filename);
-
-
/////////////////////
// ConfigFileEntry //
/////////////////////
@@ -195,6 +173,7 @@
class _CoreExport ConfigFileSection
{
friend class ConfigFile;
+ friend class SettingsConfigFile;
public:
inline ConfigFileSection(const std::string& name, const std::string& additionalComment = "")
@@ -211,17 +190,37 @@
{ this->additionalComment_ = comment; }
inline void setValue(const std::string& name, const std::string& value, bool bString)
- { this->getEntry(name, value, bString)->setValue(value); }
- inline const std::string& getValue(const std::string& name, const std::string& fallback, bool bString)
- { return this->getEntry(name, fallback, bString)->getValue(); }
+ { this->getOrCreateEntry(name, value, bString)->setValue(value); }
+ inline const std::string& getValue(const std::string& name, bool bString)
+ {
+ ConfigFileEntry* entry = this->getEntry(name);
+ if (entry)
+ {
+ entry->setString(bString);
+ return entry->getValue();
+ }
+ return BLANKSTRING;
+ }
+ inline const std::string& getOrCreateValue(const std::string& name, const std::string& fallback, bool bString)
+ { return this->getOrCreateEntry(name, fallback, bString)->getValue(); }
inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getEntry(name, index, value, bString)->setValue(value); }
- inline const std::string& getValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return this->getEntry(name, index, fallback, bString)->getValue(); }
+ { this->getOrCreateEntry(name, index, value, bString)->setValue(value); }
+ inline const std::string& getValue(const std::string& name, unsigned int index, bool bString)
+ {
+ ConfigFileEntry* entry = this->getEntry(name, index);
+ if (entry)
+ {
+ entry->setString(bString);
+ return entry->getValue();
+ }
+ return BLANKSTRING;
+ }
+ inline const std::string& getOrCreateValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+ { return this->getOrCreateEntry(name, index, fallback, bString)->getValue(); }
void deleteVectorEntries(const std::string& name, unsigned int startindex = 0);
- unsigned int getVectorSize(const std::string& name);
+ unsigned int getVectorSize(const std::string& name) const;
std::string getFileEntry() const;
@@ -233,13 +232,15 @@
std::list<ConfigFileEntry*>::const_iterator getEntriesEnd() const
{ return this->entries_.end(); }
- std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, const std::string& fallback, bool bString);
- std::list<ConfigFileEntry*>::iterator getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString);
+ std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString);
+ std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString);
- inline ConfigFileEntry* getEntry(const std::string& name, const std::string& fallback, bool bString)
- { return (*this->getEntryIterator(name, fallback, bString)); }
- inline ConfigFileEntry* getEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return (*this->getEntryIterator(name, index, fallback, bString)); }
+ ConfigFileEntry* getEntry(const std::string& name) const;
+ inline ConfigFileEntry* getOrCreateEntry(const std::string& name, const std::string& fallback, bool bString)
+ { return (*this->getOrCreateEntryIterator(name, fallback, bString)); }
+ ConfigFileEntry* getEntry(const std::string& name, unsigned int index) const;
+ inline ConfigFileEntry* getOrCreateEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
+ { return (*this->getOrCreateEntryIterator(name, index, fallback, bString)); }
std::string name_;
std::string additionalComment_;
@@ -254,49 +255,108 @@
class _CoreExport ConfigFile
{
public:
- inline ConfigFile(const std::string& filename, ConfigFileType type)
- : filename_(filename)
- , type_(type)
- , bUpdated_(false)
- { }
- ~ConfigFile();
+ ConfigFile(const std::string& filename, bool bCopyFallbackFile = true);
+ virtual ~ConfigFile();
- void load(bool bCreateIfNotExisting = true);
- void save() const;
- void saveAs(const std::string& filename);
- void clean(bool bCleanComments = false);
- void clear();
+ virtual void load();
+ virtual void save() const;
+ virtual void saveAs(const std::string& filename) const;
+ virtual void clear();
- const std::string& getFilename() { return this->filename_; }
+ inline const std::string& getFilename()
+ { return this->filename_; }
inline void setValue(const std::string& section, const std::string& name, const std::string& value, bool bString)
- { this->getSection(section)->setValue(name, value, bString); this->save(); }
- inline const std::string& getValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString)
- { const std::string& output = this->getSection(section)->getValue(name, fallback, bString); this->saveIfUpdated(); return output; }
+ {
+ this->getOrCreateSection(section)->setValue(name, value, bString);
+ this->save();
+ }
+ inline const std::string& getValue(const std::string& section, const std::string& name, bool bString)
+ {
+ ConfigFileSection* sectionPtr = this->getSection(section);
+ return (sectionPtr ? sectionPtr->getValue(name, bString) : BLANKSTRING);
+ }
+ const std::string& getOrCreateValue(const std::string& section, const std::string& name, const std::string& fallback, bool bString);
inline void setValue(const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getSection(section)->setValue(name, index, value, bString); this->save(); }
- inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { const std::string& output = this->getSection(section)->getValue(name, index, fallback, bString); this->saveIfUpdated(); return output; }
+ {
+ this->getOrCreateSection(section)->setValue(name, index, value, bString);
+ this->save();
+ }
+ inline const std::string& getValue(const std::string& section, const std::string& name, unsigned int index, bool bString)
+ {
+ ConfigFileSection* sectionPtr = this->getSection(section);
+ return (sectionPtr ? sectionPtr->getValue(name, index, bString) : BLANKSTRING);
+ }
+ const std::string& getOrCreateValue(const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString);
- inline void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0)
- { this->getSection(section)->deleteVectorEntries(name, startindex); }
- inline unsigned int getVectorSize(const std::string& section, const std::string& name)
- { return this->getSection(section)->getVectorSize(name); }
+ void deleteVectorEntries(const std::string& section, const std::string& name, unsigned int startindex = 0);
+ inline unsigned int getVectorSize(const std::string& section, const std::string& name) const
+ {
+ ConfigFileSection* sectionPtr = this->getSection(section);
+ return (sectionPtr ? sectionPtr->getVectorSize(name) : 0);
+ }
- void updateConfigValues();
+ static const char* DEFAULT_CONFIG_FOLDER;
+ protected:
+ ConfigFileSection* getSection(const std::string& section) const;
+ ConfigFileSection* getOrCreateSection(const std::string& section);
+
+ std::list<ConfigFileSection*> sections_;
+
private:
- ConfigFileSection* getSection(const std::string& section);
void saveIfUpdated();
-
- std::string filename_;
- ConfigFileType type_;
- std::list<ConfigFileSection*> sections_;
+ const std::string filename_;
+ const bool bCopyFallbackFile_;
bool bUpdated_;
};
+ ////////////////////////
+ // SettingsConfigFile //
+ ////////////////////////
+ class _CoreExport SettingsConfigFile // tolua_export
+ : public ConfigFile, public Singleton<SettingsConfigFile>
+ { // tolua_export
+ friend class Singleton<SettingsConfigFile>;
+
+ public:
+ typedef std::multimap<std::string, std::pair<std::string, ConfigValueContainer*> > ContainerMap;
+
+ SettingsConfigFile(const std::string& filename);
+ ~SettingsConfigFile();
+
+ void load(); // tolua_export
+ void setFilename(const std::string& filename); // tolua_export
+ void clean(bool bCleanComments = false); // tolua_export
+
+ bool config(const std::string& section, const std::string& entry, const std::string& value); // tolua_export
+ bool tconfig(const std::string& section, const std::string& entry, const std::string& value); // tolua_export
+ std::string getConfig(const std::string& section, const std::string& entry); // tolua_export
+
+ void addConfigValueContainer(ConfigValueContainer* container);
+ void removeConfigValueContainer(ConfigValueContainer* container);
+
+ inline const std::set<std::string>& getSectionNames()
+ { return this->sectionNames_; }
+ inline ContainerMap::const_iterator getContainerLowerBound(const std::string section)
+ { return this->containers_.lower_bound(section); }
+ inline ContainerMap::const_iterator getContainerUpperBound(const std::string section)
+ { return this->containers_.upper_bound(section); }
+
+ static SettingsConfigFile& getInstance() { return Singleton<SettingsConfigFile>::getInstance(); } // tolua_export
+
+ private:
+ void updateConfigValues();
+ bool configImpl(const std::string& section, const std::string& entry, const std::string& value, bool (ConfigValueContainer::*function)(const MultiType&));
+
+ ContainerMap containers_;
+ std::set<std::string> sectionNames_;
+ static SettingsConfigFile* singletonPtr_s;
+ }; // tolua_export
+
+
///////////////////////
// ConfigFileManager //
///////////////////////
@@ -307,48 +367,18 @@
ConfigFileManager();
~ConfigFileManager();
- void load();
- void save();
- void clean(bool bCleanComments = false);
+ void setFilename(ConfigFileType::Value type, const std::string& filename);
- void setFilename(ConfigFileType type, const std::string& filename);
- const std::string& getFilename(ConfigFileType type);
+ inline ConfigFile* getConfigFile(ConfigFileType::Value type)
+ {
+ // Check array bounds
+ return configFiles_.at(type);
+ }
- ConfigFileType getNewConfigFileType() { return mininmalFreeType_++; }
-
- void load(ConfigFileType type);
- void save(ConfigFileType type);
- void saveAs(ConfigFileType type, const std::string& saveFilename);
- void clean(ConfigFileType type, bool bCleanComments = false);
-
- inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& value, bool bString)
- { this->getFile(type)->setValue(section, name, value, bString); }
- inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, const std::string& fallback, bool bString)
- { return this->getFile(type)->getValue(section, name, fallback, bString); }
-
- inline void setValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& value, bool bString)
- { this->getFile(type)->setValue(section, name, index, value, bString); }
- inline const std::string& getValue(ConfigFileType type, const std::string& section, const std::string& name, unsigned int index, const std::string& fallback, bool bString)
- { return this->getFile(type)->getValue(section, name, index, fallback, bString); }
-
- inline void deleteVectorEntries(ConfigFileType type, const std::string& section, const std::string& name, unsigned int startindex = 0)
- { this->getFile(type)->deleteVectorEntries(section, name, startindex); }
- inline unsigned int getVectorSize(ConfigFileType type, const std::string& section, const std::string& name)
- { return this->getFile(type)->getVectorSize(section, name); }
-
- void updateConfigValues();
- void updateConfigValues(ConfigFileType type);
-
- static std::string DEFAULT_CONFIG_FILE;
-
private:
ConfigFileManager(const ConfigFileManager&);
- ConfigFile* getFile(ConfigFileType type);
-
- std::map<ConfigFileType, ConfigFile*> configFiles_;
- unsigned int mininmalFreeType_;
-
+ boost::array<ConfigFile*, 3> configFiles_;
static ConfigFileManager* singletonPtr_s;
};
} // tolua_export
Modified: code/trunk/src/libraries/core/ConfigValueContainer.cc
===================================================================
--- code/trunk/src/libraries/core/ConfigValueContainer.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ConfigValueContainer.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -35,6 +35,7 @@
#include "util/Convert.h"
#include "util/SubString.h"
+#include "ConfigFileManager.h"
#include "Language.h"
namespace orxonox
@@ -42,9 +43,9 @@
const unsigned int MAX_VECTOR_INDEX = 255; // to avoid up to 4*10^9 vector entries in the config file after accidentally using a wrong argument
/**
- @brief Initializes the ConfigValueContainer with defaultvalues.
+ @brief Initializes the ConfigValueContainer with default values.
*/
- void ConfigValueContainer::init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
+ void ConfigValueContainer::init(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname)
{
this->type_ = type;
this->identifier_ = identifier;
@@ -54,6 +55,10 @@
this->bContainerIsNew_ = true;
this->bDoInitialCallback_ = false;
this->bAddedDescription_ = false;
+
+ // Register containers for general settings
+ if (this->type_ == ConfigFileType::Settings)
+ SettingsConfigFile::getInstance().addConfigValueContainer(this);
}
/**
@@ -77,7 +82,7 @@
for (unsigned int i = 0; i < this->valueVector_.size(); i++)
{
- ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
this->defvalueStringVector_.push_back(this->valueVector_[i]);
}
@@ -91,6 +96,10 @@
{
if (this->callback_)
delete this->callback_;
+
+ // Unregister general settings containers
+ if (this->type_ == ConfigFileType::Settings && SettingsConfigFile::exists())
+ SettingsConfigFile::getInstance().removeConfigValueContainer(this);
}
/**
@@ -108,7 +117,7 @@
{
if (this->tset(input))
{
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, input, this->value_.isType(MT_Type::String));
return true;
}
}
@@ -127,7 +136,7 @@
{
if (this->tset(index, input))
{
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, index, input, this->value_.isType(MT_Type::String));
return true;
}
}
@@ -227,8 +236,8 @@
// Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file
this->valueVector_.erase(this->valueVector_.begin() + index);
for (unsigned int i = index; i < this->valueVector_.size(); i++)
- ConfigFileManager::getInstance().setValue(this->type_, this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
- ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->valueVector_.size());
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->setValue(this->sectionname_, this->varname_, i, this->valueVector_[i], this->value_.isType(MT_Type::String));
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->valueVector_.size());
return true;
}
@@ -252,7 +261,7 @@
for (unsigned int i = 0; i < this->defvalueStringVector_.size(); i++)
if (!this->set(i, this->defvalueStringVector_[i]))
success = false;
- ConfigFileManager::getInstance().deleteVectorEntries(this->type_, this->sectionname_, this->varname_, this->defvalueStringVector_.size());
+ ConfigFileManager::getInstance().getConfigFile(this->type_)->deleteVectorEntries(this->sectionname_, this->varname_, this->defvalueStringVector_.size());
return success;
}
}
@@ -263,20 +272,20 @@
void ConfigValueContainer::update()
{
if (!this->bIsVector_)
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));
+ this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, this->defvalueString_, this->value_.isType(MT_Type::String));
else
{
this->valueVector_.clear();
- unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_);
+ unsigned int vectorSize = ConfigFileManager::getInstance().getConfigFile(this->type_)->getVectorSize(this->sectionname_, this->varname_);
for (unsigned int i = 0; i < vectorSize; i++)
{
if (i < this->defvalueStringVector_.size())
{
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));
+ this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, this->defvalueStringVector_[i], this->value_.isType(MT_Type::String));
}
else
{
- this->value_ = ConfigFileManager::getInstance().getValue(this->type_, this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));
+ this->value_ = ConfigFileManager::getInstance().getConfigFile(this->type_)->getOrCreateValue(this->sectionname_, this->varname_, i, MultiType(), this->value_.isType(MT_Type::String));
}
this->valueVector_.push_back(this->value_);
Modified: code/trunk/src/libraries/core/ConfigValueContainer.h
===================================================================
--- code/trunk/src/libraries/core/ConfigValueContainer.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ConfigValueContainer.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -49,7 +49,6 @@
#include <vector>
#include "util/MultiType.h"
-#include "ConfigFileManager.h"
#include "Identifier.h"
namespace orxonox
@@ -107,7 +106,7 @@
@param value Only needed do determine the right type.
*/
template <class D, class V>
- ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value)
+ ConfigValueContainer(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const D& defvalue, const V& value)
{
this->init(type, identifier, sectionname, varname);
this->initValue(static_cast<V>(defvalue));
@@ -121,7 +120,7 @@
@param defvalue The default-value
*/
template <class D, class V>
- ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<D>& defvalue, const std::vector<V>& value)
+ ConfigValueContainer(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<D>& defvalue, const std::vector<V>& value)
{
this->init(type, identifier, sectionname, varname);
@@ -216,9 +215,12 @@
/** @brief Returns the name of this container. */
inline const std::string& getName() const
{ return this->varname_; }
- /** @brief Retuns the name of the section this config value is in. */
+ /** @brief Returns the name of the section this config value is in. */
inline const std::string& getSectionName() const
{ return this->sectionname_; }
+ /** @brief Returns the associated identifier (can be NULL). */
+ inline Identifier* getIdentifier() const
+ { return this->identifier_; }
/** @brief Returns true if this config-value is a vector */
inline bool isVector() const
{ return this->bIsVector_; }
@@ -270,14 +272,14 @@
{ return this->value_.getTypename(); }
private:
- void init(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname);
+ void init(ConfigFileType::Value type, Identifier* identifier, const std::string& sectionname, const std::string& varname);
void initValue(const MultiType& defvalue);
void initVector();
bool callFunctionWithIndex(bool (ConfigValueContainer::* function) (unsigned int, const MultiType&), const std::string& input);
bool bIsVector_; //!< True if the container contains a std::vector
- ConfigFileType type_; //!< The type of the corresponding config-file
+ ConfigFileType::Value type_; //!< The type of the corresponding config-file
Identifier* identifier_; //!< The identifier of the class
std::string sectionname_; //!< The name of the class the variable belongs to
std::string varname_; //!< The name of the variable
Modified: code/trunk/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- code/trunk/src/libraries/core/ConfigValueIncludes.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/ConfigValueIncludes.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -39,7 +39,6 @@
#include "Identifier.h"
#include "ConfigValueContainer.h"
-#include "ConfigFileManager.h"
namespace orxonox
{
@@ -60,7 +59,7 @@
Value to be used if it cannot be read from the ini file
*/
template <class T, class D, class V>
- inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType type, const std::string& sectionName, const std::string& entryName, const D& defaultValue)
+ inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType::Value type, const std::string& sectionName, const std::string& entryName, const D& defaultValue)
{
ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName);
if (!container)
Modified: code/trunk/src/libraries/core/CorePrereqs.h
===================================================================
--- code/trunk/src/libraries/core/CorePrereqs.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/CorePrereqs.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -83,6 +83,17 @@
};
}
+ namespace ConfigFileType
+ {
+ enum Value
+ {
+ Settings,
+ JoyStickCalibration,
+ CommandHistory
+ // Don't forget to adjust the array size in the ConfigFileManager when adding a new entry here!
+ };
+ }
+
namespace KeybindMode
{
enum Value
@@ -123,7 +134,6 @@
class ConfigFileEntryValue;
class ConfigFileManager;
class ConfigFileSection;
- struct ConfigFileType;
class ConfigValueContainer;
class ConsoleCommand;
class Core;
@@ -171,6 +181,7 @@
class OrxonoxClass;
class PathConfig;
struct ResourceInfo;
+ class SettingsConfigFile;
class Shell;
class ShellListener;
template <class T>
Modified: code/trunk/src/libraries/core/Identifier.cc
===================================================================
--- code/trunk/src/libraries/core/Identifier.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/Identifier.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -415,7 +415,6 @@
this->bHasConfigValues_ = true;
this->configValues_[varname] = container;
- this->configValues_LC_[getLowercase(varname)] = container;
}
/**
@@ -433,20 +432,6 @@
}
/**
- @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase.
- @param varname The name of the variable in lowercase
- @return The ConfigValueContainer
- */
- ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname)
- {
- std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname);
- if (it != configValues_LC_.end())
- return it->second;
- else
- return 0;
- }
-
- /**
@brief Adds a new console command of this class.
@param executor The executor of the command
@param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command
Modified: code/trunk/src/libraries/core/Identifier.h
===================================================================
--- code/trunk/src/libraries/core/Identifier.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/Identifier.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -199,23 +199,8 @@
/** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
inline bool hasConfigValues() const { return this->bHasConfigValues_; }
- /** @brief Returns the map that stores all config values. @return The const_iterator */
- inline const std::map<std::string, ConfigValueContainer*>& getConfigValueMap() const { return this->configValues_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all config values. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapBegin() const { return this->configValues_.begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all config values. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getConfigValueMapEnd() const { return this->configValues_.end(); }
-
- /** @brief Returns the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline const std::map<std::string, ConfigValueContainer*>& getLowercaseConfigValueMap() const { return this->configValues_LC_; }
- /** @brief Returns a const_iterator to the beginning of the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapBegin() const { return this->configValues_LC_.begin(); }
- /** @brief Returns a const_iterator to the end of the map that stores all config values with their names in lowercase. @return The const_iterator */
- inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); }
-
void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
ConfigValueContainer* getConfigValueContainer(const std::string& varname);
- ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);
////////////////////////////
@@ -319,7 +304,6 @@
bool bHasConfigValues_; //!< True if this class has at least one assigned config value
std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer
- std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer
bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command
std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class
Modified: code/trunk/src/libraries/core/Language.h
===================================================================
--- code/trunk/src/libraries/core/Language.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/Language.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -52,13 +52,6 @@
#include <cassert>
#include "util/Singleton.h"
-#define AddLanguageEntry(label, fallbackstring) \
- orxonox::Language::getInstance().addEntry(label, fallbackstring)
-
-#define GetLocalisation(label) \
- orxonox::Language::getInstance().getLocalisation(label)
-
-
namespace orxonox
{
// ###############################
@@ -139,6 +132,18 @@
static Language* singletonPtr_s;
};
+
+ //! Shortcut function for Language::addEntry
+ inline void AddLanguageEntry(const LanguageEntryLabel& label, const std::string& fallbackString)
+ {
+ Language::getInstance().addEntry(label, fallbackString);
+ }
+
+ //! Shortcut function for Language::getLocalisation
+ inline const std::string& GetLocalisation(const LanguageEntryLabel& label)
+ {
+ return Language::getInstance().getLocalisation(label);
+ }
}
#endif /* _Language_H__ */
Modified: code/trunk/src/libraries/core/Shell.cc
===================================================================
--- code/trunk/src/libraries/core/Shell.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/Shell.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -33,6 +33,7 @@
#include "util/SubString.h"
#include "CommandExecutor.h"
#include "CoreIncludes.h"
+#include "ConfigFileManager.h"
#include "ConfigValueIncludes.h"
#include "ConsoleCommand.h"
Modified: code/trunk/src/libraries/core/Shell.h
===================================================================
--- code/trunk/src/libraries/core/Shell.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/Shell.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -38,7 +38,6 @@
#include "util/OutputHandler.h"
#include "OrxonoxClass.h"
-#include "ConfigFileManager.h"
#include "input/InputBuffer.h"
namespace orxonox
Modified: code/trunk/src/libraries/core/input/Button.cc
===================================================================
--- code/trunk/src/libraries/core/input/Button.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/input/Button.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -41,6 +41,7 @@
#include "core/ConsoleCommand.h"
#include "core/CommandEvaluation.h"
#include "core/CommandExecutor.h"
+#include "core/ConfigFileManager.h"
namespace orxonox
{
@@ -80,16 +81,18 @@
this->bindingString_.clear();
}
- void Button::readBinding(ConfigFileType type)
+ void Button::readBinding(ConfigFile* configFile, ConfigFile* fallbackFile)
{
- const std::string& binding = ConfigFileManager::getInstance().getValue(type, groupName_, name_, "", true);
+ std::string binding = configFile->getOrCreateValue(groupName_, name_, "", true);
+ if (binding.empty() && fallbackFile)
+ binding = fallbackFile->getValue(groupName_, name_, true);
this->parse(binding);
}
- void Button::setBinding(ConfigFileType type, const std::string& binding, bool bTemporary)
+ void Button::setBinding(ConfigFile* configFile, ConfigFile* fallbackFile, const std::string& binding, bool bTemporary)
{
if (!bTemporary)
- ConfigFileManager::getInstance().setValue(type, groupName_, name_, binding, true);
+ configFile->setValue(groupName_, name_, binding, true);
this->parse(binding);
}
@@ -102,7 +105,7 @@
clear();
this->bindingString_ = binding;
- if (isEmpty(bindingString_))
+ if (isEmpty(bindingString_) || removeTrailingWhitespaces(getLowercase(binding)) == "nobinding")
return;
// reset this to false first when parsing (was true before when parsing for the first time)
Modified: code/trunk/src/libraries/core/input/Button.h
===================================================================
--- code/trunk/src/libraries/core/input/Button.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/input/Button.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -40,7 +40,6 @@
#include <string>
#include <vector>
#include "InputCommands.h"
-#include "core/ConfigFileManager.h"
namespace orxonox
{
@@ -52,8 +51,8 @@
virtual void clear();
virtual bool addParamCommand(ParamCommand* command) { return false; }
void parse(const std::string& binding);
- void readBinding(ConfigFileType type);
- void setBinding(ConfigFileType type, const std::string& binding, bool bTemporary);
+ void readBinding(ConfigFile* configFile, ConfigFile* fallbackFile);
+ void setBinding(ConfigFile* configFile, ConfigFile* fallbackFile, const std::string& binding, bool bTemporary);
bool execute(KeybindMode::Value mode, float abs = 1.0f, float rel = 1.0f);
//! The configured string value
Modified: code/trunk/src/libraries/core/input/JoyStick.cc
===================================================================
--- code/trunk/src/libraries/core/input/JoyStick.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/input/JoyStick.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -105,14 +105,14 @@
void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue)
{
list.resize(size);
- unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName);
+ unsigned int configValueVectorSize = ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)->getVectorSize(sectionName, valueName);
if (configValueVectorSize > size)
configValueVectorSize = size;
for (unsigned int i = 0; i < configValueVectorSize; ++i)
{
- list[i] = multi_cast<int>(ConfigFileManager::getInstance().getValue(
- ConfigFileType::JoyStickCalibration, sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
+ list[i] = multi_cast<int>(ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
+ ->getOrCreateValue(sectionName, valueName, i, multi_cast<std::string>(defaultValue), false));
}
// fill the rest with default values
@@ -152,18 +152,18 @@
// Minimum values
if (configMinValues_[i] == INT_MAX)
configMinValues_[i] = -32768;
- ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
+ ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
+ ->getOrCreateValue(deviceName_, "MinValue", i, multi_cast<std::string>(configMinValues_[i]), false);
// Maximum values
if (configMaxValues_[i] == INT_MIN)
configMaxValues_[i] = 32767;
- ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
+ ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
+ ->getOrCreateValue(deviceName_, "MaxValue", i, multi_cast<std::string>(configMaxValues_[i]), false);
// Middle values
- ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
- deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
+ ConfigFileManager::getInstance().getConfigFile(ConfigFileType::JoyStickCalibration)
+ ->getOrCreateValue(deviceName_, "ZeroValue", i, multi_cast<std::string>(configZeroValues_[i]), false);
}
this->evaluateCalibration();
Modified: code/trunk/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/input/KeyBinder.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -36,6 +36,7 @@
#include "core/ConfigValueIncludes.h"
#include "core/CoreIncludes.h"
#include "core/ConfigFileManager.h"
+#include "core/PathConfig.h"
#include "InputCommands.h"
#include "JoyStick.h"
@@ -48,6 +49,8 @@
KeyBinder::KeyBinder(const std::string& filename)
: deriveTime_(0.0f)
, filename_(filename)
+ , configFile_(NULL)
+ , fallbackConfigFile_(NULL)
{
mouseRelative_[0] = 0;
mouseRelative_[1] = 0;
@@ -93,9 +96,6 @@
mouseAxes_[i].groupName_ = "MouseAxes";
}
- // We might not even load any bindings at all (KeyDetector for instance)
- this->configFile_ = ConfigFileType::NoType;
-
// initialise joy sticks separatly to allow for reloading
this->JoyStickQuantityChanged(this->getJoyStickList());
@@ -115,6 +115,10 @@
{
// almost no destructors required because most of the arrays are static.
clearBindings(); // does some destruction work
+ if (this->configFile_)
+ delete this->configFile_;
+ if (this->fallbackConfigFile_)
+ delete this->fallbackConfigFile_;
}
/**
@@ -162,14 +166,14 @@
compilePointerLists();
// load the bindings if required
- if (configFile_ != ConfigFileType::NoType)
+ if (configFile_ != NULL)
{
for (unsigned int iDev = oldValue; iDev < joySticks_.size(); ++iDev)
{
for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
- (*joyStickButtons_[iDev])[i].readBinding(this->configFile_);
+ (*joyStickButtons_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
- (*joyStickAxes_[iDev])[i].readBinding(this->configFile_);
+ (*joyStickAxes_[iDev])[i].readBinding(this->configFile_, this->fallbackConfigFile_);
}
}
@@ -248,15 +252,27 @@
{
COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
- // Get a new ConfigFileType from the ConfigFileManager
- this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
+ this->configFile_ = new ConfigFile(this->filename_, !PathConfig::isDevelopmentRun());
+ this->configFile_->load();
- ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_);
+ if (PathConfig::isDevelopmentRun())
+ {
+ // Dev users should have combined key bindings files
+ std::string defaultFilepath(PathConfig::getDataPathString() + ConfigFile::DEFAULT_CONFIG_FOLDER + '/' + this->filename_);
+ std::ifstream file(defaultFilepath.c_str());
+ if (file.is_open())
+ {
+ file.close();
+ // Open the default file for later use (use absolute path!)
+ this->fallbackConfigFile_ = new ConfigFile(defaultFilepath, false);
+ this->fallbackConfigFile_->load();
+ }
+ }
// Parse bindings and create the ConfigValueContainers if necessary
for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
{
- it->second->readBinding(this->configFile_);
+ it->second->readBinding(this->configFile_, this->fallbackConfigFile_);
addButtonToCommand(it->second->bindingString_, it->second);
}
@@ -269,7 +285,10 @@
if (it != allButtons_.end())
{
addButtonToCommand(binding, it->second);
- it->second->setBinding(this->configFile_, binding, bTemporary);
+ std::string str = binding;
+ if (PathConfig::isDevelopmentRun() && binding.empty())
+ str = "NoBinding";
+ it->second->setBinding(this->configFile_, this->fallbackConfigFile_, binding, bTemporary);
return true;
}
else
Modified: code/trunk/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/trunk/src/libraries/core/input/KeyBinder.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/core/input/KeyBinder.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -37,7 +37,6 @@
#include <map>
#include <boost/shared_ptr.hpp>
-#include "core/ConfigFileManager.h"
#include "InputHandler.h"
#include "Button.h"
#include "HalfAxis.h"
@@ -156,8 +155,10 @@
//! Name of the file used in this KeyBinder (constant!)
const std::string filename_;
- //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded.
- ConfigFileType configFile_;
+ //! Config file used. NULL in case of KeyDetector. Also indicates whether we've already loaded.
+ ConfigFile* configFile_;
+ //! Config file from the data directory that only serves as fallback
+ ConfigFile* fallbackConfigFile_;
private:
void addButtonToCommand(const std::string& command, Button* button);
Modified: code/trunk/src/libraries/util/Singleton.h
===================================================================
--- code/trunk/src/libraries/util/Singleton.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/libraries/util/Singleton.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -50,10 +50,16 @@
//! Returns a reference to the singleton instance
static T& getInstance()
{
- assert(T::singletonPtr_s != 0);
+ assert(T::singletonPtr_s != NULL);
return *T::singletonPtr_s;
}
+ //! Tells whether the singleton has been created
+ static bool exists()
+ {
+ return (T::singletonPtr_s != NULL);
+ }
+
//! Update method called by ClassSingletonManager (if used)
void preUpdateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->preUpdate(time); }
//! Empty update method for the static polymorphism
@@ -67,15 +73,15 @@
//! Constructor sets the singleton instance pointer
Singleton()
{
- assert(T::singletonPtr_s == 0);
+ assert(T::singletonPtr_s == NULL);
T::singletonPtr_s = static_cast<T*>(this);
}
//! Constructor resets the singleton instance pointer
~Singleton()
{
- assert(T::singletonPtr_s != 0);
- T::singletonPtr_s = 0;
+ assert(T::singletonPtr_s != NULL);
+ T::singletonPtr_s = NULL;
}
private:
Modified: code/trunk/src/modules/questsystem/QuestManager.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestManager.cc 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/modules/questsystem/QuestManager.cc 2010-03-16 10:22:36 UTC (rev 6536)
@@ -234,7 +234,7 @@
*/
CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
{
- PlayerInfo* player = this->retreivePlayer(guiName);
+ PlayerInfo* player = this->retrievePlayer(guiName);
if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet.
this->questGUIs_[player] = new QuestGUI(player);
@@ -252,7 +252,7 @@
@todo
This very well might be outdated. So: Check if still needed, and update if necessary.
*/
- PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName)
+ PlayerInfo* QuestManager::retrievePlayer(const std::string & guiName)
{
PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName);
if(player == NULL)
Modified: code/trunk/src/modules/questsystem/QuestManager.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestManager.h 2010-03-16 10:13:28 UTC (rev 6535)
+++ code/trunk/src/modules/questsystem/QuestManager.h 2010-03-16 10:22:36 UTC (rev 6536)
@@ -51,7 +51,7 @@
{
/**
@brief
- Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
+ Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessible (through findX()).
Quests (and QuestHints) are registered in the QuestManager with their id, and can be accessed in the same way.
@author
Damian 'Mozork' Frick
@@ -71,7 +71,7 @@
//! Returns a reference to the single instance of the Quest Manager.
static QuestManager& getInstance() { return Singleton<QuestManager>::getInstance(); } // tolua_export
- //! Retreive the main window for the GUI.
+ //! Retrieve the main window for the GUI.
CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export
bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
@@ -81,11 +81,11 @@
QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
protected:
- std::map<std::string, Quest*> & getQuests(void); //!< Retreive all Quests.
+ std::map<std::string, Quest*> & getQuests(void); //!< Retrieve all Quests.
private:
static QuestManager* singletonPtr_s;
- PlayerInfo* retreivePlayer(const std::string & guiName); //!< Retrieve the player for a certain GUI.
+ PlayerInfo* retrievePlayer(const std::string & guiName); //!< Retrieve the player for a certain GUI.
std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
More information about the Orxonox-commit
mailing list