Orxonox  0.0.5 Codename: Arcturus
ConfigValueIncludes.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Fabian 'x3n' Landau
24  * Co-authors:
25  * Reto Grieder (functions)
26  *
27  */
28 
100 #ifndef _ConfigValueIncludes_H__
101 #define _ConfigValueIncludes_H__
102 
103 #include "core/CorePrereqs.h"
104 
105 #include "core/class/Identifier.h"
106 #include "ConfigValueContainer.h"
107 
108 namespace orxonox
109 {
126  template <class T, class D, class V>
127  inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType::Value type, const std::string& sectionName, const std::string& entryName, const D& defaultValue)
128  {
129  ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName);
130  if (!container)
131  {
132  container = new ConfigValueContainer(type, ClassIdentifier<T>::getIdentifier(), sectionName, entryName, defaultValue, *variable);
133  ClassIdentifier<T>::getIdentifier()->addConfigValueContainer(entryName, container);
134  }
135  return container->getValue(variable, object);
136  }
137 }
138 
147 #define SetConfigValue(varname, defaultValue) \
148  orxonox::setConfigValueGeneric(this, &varname, ConfigFileType::Settings, this->getIdentifier()->getName(), #varname, defaultValue)
149 
160 #define SetConfigValueAlias(variable, entryName, defaultValue) \
161  orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, this->getIdentifier()->getName(), entryName, defaultValue)
162 
175 #define SetConfigValueExternal(variable, sectionName, entryName, defaultValue) \
176  orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, sectionName, entryName, defaultValue)
177 
178 
179 namespace orxonox
180 {
191  template <class T, class V>
192  inline void resetConfigValueGeneric(T* object, V* variable, const std::string& entryName)
193  {
194  ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName);
195  if (container)
196  {
197  container->reset();
198  container->getValue(variable, object);
199  }
200  else
201  {
202  orxout(user_warning, context::config) << "Couldn't reset config-value '" << entryName << "' in class '"
203  << ClassIdentifier<T>::getIdentifier()->getName() << "', corresponding container doesn't exist." << endl;
204  }
205  }
206 }
207 
214 #define ResetConfigValue(varname) \
215  orxonox::resetConfigValueGeneric(this, &varname, #varname)
216 
217 
232 #define ModifyConfigValueGeneric(object, variable, entryName, modifier, ...) \
233  if (orxonox::ConfigValueContainer* container = ClassByObjectType(object)->getConfigValueContainer(entryName)) \
234  { \
235  container->modifier(__VA_ARGS__); \
236  container->getValue(variable, object); \
237  } \
238  else \
239  { \
240  orxout(user_warning, context::config) << "Couldn't modify config-value '" << entryName << "' in class '" \
241  << ClassByObjectType(object)->getName() << "', corresponding container doesn't exist." << endl; \
242  }
243 
254 #define ModifyConfigValue(varname, modifier, ...) \
255  ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
256 
269 #define ModifyConfigValueExternal(variable, entryName, modifier, ...) \
270  ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)
271 
272 #endif /* _ConfigValueIncludes_H__ */
The ClassIdentifier is derived from Identifier and holds all class-specific functions and variables t...
Definition: Identifier.h:262
The ConfigValuecontainer contains all needed information about a configurable variable.
Definition: ConfigValueContainer.h:98
Definition: InputPrereqs.h:90
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
void resetConfigValueGeneric(T *object, V *variable, const std::string &entryName)
Resets a runtime configurable value to its default.
Definition: ConfigValueIncludes.h:192
ConfigValueContainer & setConfigValueGeneric(T *object, V *variable, ConfigFileType::Value type, const std::string &sectionName, const std::string &entryName, const D &defaultValue)
Sets a runtime configurable value.
Definition: ConfigValueIncludes.h:127
Declaration of the ConfigValueContainer class, caches a config-value.
Value
Definition: CorePrereqs.h:113
Declaration of Identifier, definition of ClassIdentifier<T>; used to identify the class of an object...
static ClassIdentifier< T > * getIdentifier()
Returns the only instance of this class.
Definition: Identifier.h:329
false defaultValue(2, false).argumentCompleter(0
OutputStream & orxout(OutputLevel level=level::debug_output, const OutputContextContainer &context=context::undefined())
This helper function returns a reference to a commonly used instance of OutputStream.
Definition: Output.h:81
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Definition: InputPrereqs.h:105
Definition: InputPrereqs.h:78
bool reset()
Sets the value of the variable back to the default value and resets the config-file entry...
Definition: ConfigValueContainer.cc:254
ConfigValueContainer & getValue(T *value, C *object)
Returns the configured value.
Definition: ConfigValueContainer.h:147
Output level, used for warnings which are important for the user.
Definition: OutputDefinitions.h:92