[Orxonox-commit 1525] r6243 - in code/branches/presentation2/src: libraries/core orxonox/gametypes orxonox/infos
rgrieder at orxonox.net
rgrieder at orxonox.net
Fri Dec 4 15:12:10 CET 2009
Author: rgrieder
Date: 2009-12-04 15:12:10 +0100 (Fri, 04 Dec 2009)
New Revision: 6243
Modified:
code/branches/presentation2/src/libraries/core/CMakeLists.txt
code/branches/presentation2/src/libraries/core/ConfigValueContainer.h
code/branches/presentation2/src/libraries/core/ConfigValueIncludes.h
code/branches/presentation2/src/libraries/core/Core.cc
code/branches/presentation2/src/libraries/core/Shell.cc
code/branches/presentation2/src/orxonox/gametypes/TeamDeathmatch.cc
code/branches/presentation2/src/orxonox/infos/Bot.cc
Log:
Modified config value macros so you can use them as one-liner.
And the macro code also gone: it can now be easily debugged in an inline function.
(Changes do not apply to ModifyConfigValue because it was impossible to do).
Modified: code/branches/presentation2/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/libraries/core/CMakeLists.txt 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/libraries/core/CMakeLists.txt 2009-12-04 14:12:10 UTC (rev 6243)
@@ -85,7 +85,7 @@
FIND_HEADER_FILES
TOLUA_FILES
CommandExecutor.h
- ConfigFileManager.h
+ ConfigFileManager.h
Game.h
Loader.h
LuaState.h
Modified: code/branches/presentation2/src/libraries/core/ConfigValueContainer.h
===================================================================
--- code/branches/presentation2/src/libraries/core/ConfigValueContainer.h 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/libraries/core/ConfigValueContainer.h 2009-12-04 14:12:10 UTC (rev 6243)
@@ -120,8 +120,8 @@
@param varname The name of the variable
@param defvalue The default-value
*/
- template <class V>
- ConfigValueContainer(ConfigFileType type, Identifier* identifier, const std::string& sectionname, const std::string& varname, const std::vector<V>& defvalue)
+ 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)
{
this->init(type, identifier, sectionname, varname);
Modified: code/branches/presentation2/src/libraries/core/ConfigValueIncludes.h
===================================================================
--- code/branches/presentation2/src/libraries/core/ConfigValueIncludes.h 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/libraries/core/ConfigValueIncludes.h 2009-12-04 14:12:10 UTC (rev 6243)
@@ -22,13 +22,14 @@
* Author:
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Reto Grieder (functions)
*
*/
/**
- @file
- @brief Definition of macros for config-values.
+ at file
+ at brief
+ Definition of macros and functions for config-values.
*/
#ifndef _ConfigValueIncludes_H__
@@ -40,75 +41,125 @@
#include "ConfigValueContainer.h"
#include "ConfigFileManager.h"
+namespace orxonox
+{
+ /** Sets a runtime configurable value.
+ If the container for the value doesn't yet exist, a new one is created.
+ Also, the @a variable argument will be modified and set to the new value (default or from ini file).
+ @param object
+ Class instance that the config value should belong to (usually just 'this')
+ @param variable
+ Pointer to the variable where the value should be written to
+ @param type
+ Type of the config file, usually ConfigFileType::Settings
+ @param sectionName
+ Name of the section in the ini file (e.g. [MySection])
+ @param entryName
+ Name of the entry in the ini file (e.g. [MySection] myValue)
+ @param defaultValue
+ 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)
+ {
+ ConfigValueContainer* container = object->getIdentifier()->getConfigValueContainer(entryName);
+ if (!container)
+ {
+ container = new ConfigValueContainer(type, object->getIdentifier(), sectionName, entryName, defaultValue, *variable);
+ object->getIdentifier()->addConfigValueContainer(entryName, container);
+ }
+ return container->getValue(variable, object);
+ }
+}
-/**
- @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
- @param varname The name of the variable
- @param defvalue The default-value of the variable
+/** Sets a runtime configurable value (simplified macro version of setConfigValueGeneric)
+ If the container for the value doesn't yet exist, a new one is created.
+ Also, the @a varname argument will be modified and set to the new value (default or from ini file).
+ at param varname
+ Variable name as C++ identifier. It will be used as entry name and as variable pointer
+ at param defaultValue
+ Value to be used if it cannot be read from the ini file
*/
-#define SetConfigValueGeneric(type, varname, entryname, sectionname, defvalue) \
- static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
- orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(entryname); \
- if (!container##varname) \
- { \
- container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, sectionname, entryname, defvalue, varname); \
- identifier##varname->addConfigValueContainer(entryname, container##varname); \
- } \
- container##varname->getValue(&varname, this)
+#define SetConfigValue(varname, defaultValue) \
+ orxonox::setConfigValueGeneric(this, &varname, ConfigFileType::Settings, this->getIdentifier()->getName(), #varname, defaultValue)
-#define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, #varname, identifier##varname->getName(), defvalue)
+namespace orxonox
+{
+ /** Resets a runtime configurable value to its default.
+ If the container for the value doesn't yet exist, a warning is displayed.
+ Also, the @a variable argument will be modified and set to the default value.
+ @param object
+ Class instance that the config value should belong to (usually just 'this')
+ @param variable
+ Pointer to the variable where the value should be written to
+ @param entryName
+ Name of the entry in the ini file (e.g. [MySection] myValue)
+ */
+ template <class T, class V>
+ inline void resetConfigValueGeneric(T* object, V* variable, const std::string& entryName)
+ {
+ ConfigValueContainer* container = object->getIdentifier()->getConfigValueContainer(entryName);
+ if (container)
+ {
+ container->reset();
+ container->getValue(variable, object);
+ }
+ else
+ {
+ COUT(2) << "Warning: Couldn't reset config-value '" << entryName << "' in class '"
+ << object->getIdentifier()->getName() << "', corresponding container doesn't exist." << std::endl;
+ }
+ }
+}
-/**
- @brief Assigns the vector-values, defined in the config-file, to the vector (or the default-value, if there are no entries in the file).
- @param varname The name of the std::vector
- @param defvalue The default-value
+/** Resets a runtime configurable value to its default (simplified macro version of modifyConfigValueGeneric)
+ If the container for the value doesn't yet exist, a warning is displayed.
+ Also, the @a varname argument will be modified and set to the default value.
+ at param varname
+ Variable name as C++ identifier. It will be used as entry name and as variable pointer
*/
-#define SetConfigValueVectorGeneric(type, varname, defvalue) \
- static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
- orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
- if (!container##varname) \
- { \
- container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue); \
- identifier##varname->addConfigValueContainer(#varname, container##varname); \
- } \
- container##varname->getValue(&varname, this)
+#define ResetConfigValue(varname) \
+ orxonox::resetConfigValueGeneric(this, &varname, #varname)
-#define SetConfigValueVector(varname, defvalue) SetConfigValueVectorGeneric(ConfigFileType::Settings, varname, defvalue)
-
-/**
- @brief Sets the variable and the config-file entry back to the previously defined default-value.
- @param varname The name of the variable
+/** Modifies a runtime configurable value by using a modifier and some arguments.
+ If the container for the value doesn't yet exist, a warning is displayed.
+ Also, the @a variable argument will be modified and set to the current value.
+ at param object
+ Class instance that the config value should belong to (usually just 'this')
+ at param variable
+ Pointer to the variable where the value should be written to
+ at param entryName
+ Name of the entry in the ini file (e.g. [MySection] myValue)
+ at param modifier
+ On of these functions: set, tset, add, remove, reset, update
+ at param ...
+ Arguments for the modifier function
*/
-#define ResetConfigValue(varname) \
- orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
- if (container##varname##reset) \
+#define ModifyConfigValueGeneric(object, variable, entryName, modifier, ...) \
+ if (orxonox::ConfigValueContainer* container = object->getIdentifier()->getConfigValueContainer(entryName)) \
{ \
- container##varname##reset->reset(); \
- container##varname##reset->getValue(&varname, this); \
+ container->modifier(__VA_ARGS__); \
+ container->getValue(variable, object); \
} \
else \
{ \
- COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
+ COUT(2) << "Warning: Couln't modify config-value '" << entryName << "' in class '" \
+ << object->getIdentifier()->getName() << "', corresponding container doesn't exist." << std::endl; \
}
-
-/**
- @brief Modifies a config-value by using a modifier and some arguments.
- @param varname The name of the config-value
- @param modifier The name of the modifier: set, tset, add, remove, reset, update
+/** Modifies a runtime configurable value by using a modifier and some arguments.
+ If the container for the value doesn't yet exist, a warning is displayed.
+ Also, the @a varname argument will be modified and set to the current value.
+ at param varname
+ Variable name as C++ identifier. It will be used as entry name and as variable pointer
+ at param modifier
+ On of these functions: set, tset, add, remove, reset, update
+ at param ...
+ Arguments for the modifier function
*/
#define ModifyConfigValue(varname, modifier, ...) \
- orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
- if (container##varname##modify##modifier) \
- { \
- container##varname##modify##modifier->modifier(__VA_ARGS__); \
- container##varname##modify##modifier->getValue(&varname, this); \
- } \
- else \
- { \
- COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
- }
+ ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
#endif /* _ConfigValueIncludes_H__ */
Modified: code/branches/presentation2/src/libraries/core/Core.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Core.cc 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/libraries/core/Core.cc 2009-12-04 14:12:10 UTC (rev 6243)
@@ -182,7 +182,7 @@
#else
const unsigned int defaultLevelLogFile = 4;
#endif
- SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevelLogFile_, "softDebugLevelLogFile", "OutputHandler", defaultLevelLogFile)
+ setConfigValueGeneric(this, &this->softDebugLevelLogFile_, ConfigFileType::Settings, "OutputHandler", "softDebugLevelLogFile", defaultLevelLogFile)
.description("The maximum level of debug output shown in the log file");
OutputHandler::getInstance().setSoftDebugLevel(OutputHandler::logFileOutputListenerName_s, this->softDebugLevelLogFile_);
Modified: code/branches/presentation2/src/libraries/core/Shell.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Shell.cc 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/libraries/core/Shell.cc 2009-12-04 14:12:10 UTC (rev 6243)
@@ -97,14 +97,14 @@
.callback(this, &Shell::commandHistoryLengthChanged);
SetConfigValue(historyOffset_, 0)
.callback(this, &Shell::commandHistoryOffsetChanged);
- SetConfigValueVectorGeneric(commandHistoryConfigFileType_, commandHistory_, std::vector<std::string>());
+ setConfigValueGeneric(this, &commandHistory_, commandHistoryConfigFileType_, "Shell", "commandHistory_", std::vector<std::string>());
#ifdef ORXONOX_RELEASE
const unsigned int defaultLevel = 1;
#else
const unsigned int defaultLevel = 3;
#endif
- SetConfigValueGeneric(ConfigFileType::Settings, softDebugLevel_, "softDebugLevel" + this->consoleName_, "OutputHandler", defaultLevel)
+ setConfigValueGeneric(this, &softDebugLevel_, ConfigFileType::Settings, "OutputHandler", "softDebugLevel" + this->consoleName_, defaultLevel)
.description("The maximal level of debug output shown in the Shell");
this->setSoftDebugLevel(this->softDebugLevel_);
}
Modified: code/branches/presentation2/src/orxonox/gametypes/TeamDeathmatch.cc
===================================================================
--- code/branches/presentation2/src/orxonox/gametypes/TeamDeathmatch.cc 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/orxonox/gametypes/TeamDeathmatch.cc 2009-12-04 14:12:10 UTC (rev 6243)
@@ -60,7 +60,7 @@
};
static std::vector<ColourValue> defaultcolours(colours, colours + sizeof(colours) / sizeof(ColourValue));
- SetConfigValueVector(teamcolours_, defaultcolours);
+ SetConfigValue(teamcolours_, defaultcolours);
}
void TeamDeathmatch::playerEntered(PlayerInfo* player)
Modified: code/branches/presentation2/src/orxonox/infos/Bot.cc
===================================================================
--- code/branches/presentation2/src/orxonox/infos/Bot.cc 2009-12-04 12:56:56 UTC (rev 6242)
+++ code/branches/presentation2/src/orxonox/infos/Bot.cc 2009-12-04 14:12:10 UTC (rev 6243)
@@ -93,6 +93,6 @@
};
static std::vector<std::string> defaultnames(names, names + sizeof(names) / sizeof(std::string));
- SetConfigValueVector(names_, defaultnames);
+ SetConfigValue(names_, defaultnames);
}
}
More information about the Orxonox-commit
mailing list