Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/ConfigValueIncludes.h @ 7166

Last change on this file since 7166 was 7166, checked in by landauf, 14 years ago

added new macro to ConfigValueIncludes.h, "SetConfigValueExternal" for values with user-defined name AND user-defined section

added new config value for models to enable/disable LOD (aimed towards people which experience crashes when using LOD)
moved config value for the LOD of ParticleInterface to the same section (GraphicsSettings) using the new macro

  • Property svn:eol-style set to native
File size: 8.1 KB
Line 
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
29/**
30@file
31@brief
32    Definition of macros and functions for config-values.
33*/
34
35#ifndef _ConfigValueIncludes_H__
36#define _ConfigValueIncludes_H__
37
38#include "CorePrereqs.h"
39
40#include "Identifier.h"
41#include "ConfigValueContainer.h"
42
43namespace orxonox
44{
45    /** Sets a runtime configurable value.
46        If the container for the value doesn't yet exist, a new one is created.
47        Also, the @a variable argument will be modified and set to the new value (default or from ini file).
48    @param object
49        Class instance that the config value should belong to (usually just 'this')
50    @param variable
51        Pointer to the variable where the value should be written to
52    @param type
53        Type of the config file, usually ConfigFileType::Settings
54    @param sectionName
55        Name of the section in the ini file (e.g. [MySection])
56    @param entryName
57        Name of the entry in the ini file (e.g. [MySection] myValue)
58    @param defaultValue
59        Value to be used if it cannot be read from the ini file
60    */
61    template <class T, class D, class V>
62    inline ConfigValueContainer& setConfigValueGeneric(T* object, V* variable, ConfigFileType::Value type, const std::string& sectionName, const std::string& entryName, const D& defaultValue)
63    {
64        ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName);
65        if (!container)
66        {
67            container = new ConfigValueContainer(type, ClassIdentifier<T>::getIdentifier(), sectionName, entryName, defaultValue, *variable);
68            ClassIdentifier<T>::getIdentifier()->addConfigValueContainer(entryName, container);
69        }
70        return container->getValue(variable, object);
71    }
72}
73
74/** Sets a runtime configurable value (simplified macro version of setConfigValueGeneric)
75    If the container for the value doesn't yet exist, a new one is created.
76    Also, the @a varname argument will be modified and set to the new value (default or from ini file).
77@param varname
78    Variable name as C++ identifier. It will be used as entry name and as variable pointer
79@param defaultValue
80    Value to be used if it cannot be read from the ini file
81*/
82#define SetConfigValue(varname, defaultValue) \
83    orxonox::setConfigValueGeneric(this, &varname, ConfigFileType::Settings, this->getIdentifier()->getName(), #varname, defaultValue)
84
85/** Sets a runtime configurable value (simplified macro version of setConfigValueGeneric)
86    If the container for the value doesn't yet exist, a new one is created.
87    Also, the @a varname argument will be modified and set to the new value (default or from ini file).
88@param variable
89    Variable name as C++ identifier.
90@param entryName
91    Name of the entry in the ini file (e.g. [MySection] myValue)
92@param defaultValue
93    Value to be used if it cannot be read from the ini file
94*/
95#define SetConfigValueAlias(variable, entryName, defaultValue) \
96    orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, this->getIdentifier()->getName(), entryName, defaultValue)
97
98/** Sets a runtime configurable value (simplified macro version of setConfigValueGeneric)
99    If the container for the value doesn't yet exist, a new one is created.
100    Also, the @a varname argument will be modified and set to the new value (default or from ini file).
101@param variable
102    Variable name as C++ identifier.
103@param sectionName
104    Name of the section in the ini file (e.g. [MySection])
105@param entryName
106    Name of the entry in the ini file (e.g. [MySection] myValue)
107@param defaultValue
108    Value to be used if it cannot be read from the ini file
109*/
110#define SetConfigValueExternal(variable, sectionName, entryName, defaultValue) \
111    orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, sectionName, entryName, defaultValue)
112
113
114namespace orxonox
115{
116    /** Resets a runtime configurable value to its default.
117        If the container for the value doesn't yet exist, a warning is displayed.
118        Also, the @a variable argument will be modified and set to the default value.
119    @param object
120        Class instance that the config value should belong to (usually just 'this')
121    @param variable
122        Pointer to the variable where the value should be written to
123    @param entryName
124        Name of the entry in the ini file (e.g. [MySection] myValue)
125    */
126    template <class T, class V>
127    inline void resetConfigValueGeneric(T* object, V* variable, const std::string& entryName)
128    {
129        ConfigValueContainer* container = ClassIdentifier<T>::getIdentifier()->getConfigValueContainer(entryName);
130        if (container)
131        {
132            container->reset();
133            container->getValue(variable, object);
134        }
135        else
136        {
137            COUT(2) << "Warning: Couldn't reset config-value '" << entryName << "' in class '"
138                    << ClassIdentifier<T>::getIdentifier()->getName() << "', corresponding container doesn't exist." << std::endl;
139        }
140    }
141}
142
143/** Resets a runtime configurable value to its default (simplified macro version of modifyConfigValueGeneric)
144    If the container for the value doesn't yet exist, a warning is displayed.
145    Also, the @a varname argument will be modified and set to the default value.
146@param varname
147    Variable name as C++ identifier. It will be used as entry name and as variable pointer
148*/
149#define ResetConfigValue(varname) \
150    orxonox::resetConfigValueGeneric(this, &varname, #varname)
151
152
153/** Modifies a runtime configurable value by using a modifier and some arguments.
154    If the container for the value doesn't yet exist, a warning is displayed.
155    Also, the @a variable argument will be modified and set to the current value.
156@param object
157    Class instance that the config value should belong to (usually just 'this')
158@param variable
159    Pointer to the variable where the value should be written to
160@param entryName
161    Name of the entry in the ini file (e.g. [MySection] myValue)
162@param modifier
163    On of these functions: set, tset, add, remove, reset, update
164@param ...
165    Arguments for the modifier function
166*/
167#define ModifyConfigValueGeneric(object, variable, entryName, modifier, ...) \
168    if (orxonox::ConfigValueContainer* container = ClassByObjectType(object)->getConfigValueContainer(entryName)) \
169    { \
170        container->modifier(__VA_ARGS__); \
171        container->getValue(variable, object); \
172    } \
173    else \
174    { \
175        COUT(2) << "Warning: Couln't modify config-value '" << entryName << "' in class '" \
176                << ClassByObjectType(object)->getName() << "', corresponding container doesn't exist." << std::endl; \
177    }
178
179/** Modifies a runtime configurable value by using a modifier and some arguments.
180    If the container for the value doesn't yet exist, a warning is displayed.
181    Also, the @a varname argument will be modified and set to the current value.
182@param varname
183    Variable name as C++ identifier. It will be used as entry name and as variable pointer
184@param modifier
185    On of these functions: set, tset, add, remove, reset, update
186@param ...
187    Arguments for the modifier function
188*/
189#define ModifyConfigValue(varname, modifier, ...) \
190    ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
191
192#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.