Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core3/src/core/ConfigValueIncludes.h @ 1607

Last change on this file since 1607 was 1596, checked in by landauf, 16 years ago
  • added feature to add a callback function to configvalues. they get called if the value changes. an examples is in Core.cc.
  • changed the SetConfigValue macro and the Identifier::updateConfigValues() function to work properly with inherited classes in both possible cases: 1) they overwrite the config-value or 2) they don't. an example is ParticleProjectile that defines it's own speed_ configvalue.
  • Property svn:eol-style set to native
File size: 5.2 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 *      ...
26 *
27 */
28
29/**
30    @file ConfigValueIncludes.h
31    @brief Definition of macros for config-values.
32*/
33
34#ifndef _ConfigValueIncludes_H__
35#define _ConfigValueIncludes_H__
36
37#include "CorePrereqs.h"
38
39#include "Identifier.h"
40#include "ConfigValueContainer.h"
41#include "ConfigFileManager.h"
42
43
44/**
45    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
46    @param varname The name of the variable
47    @param defvalue The default-value of the variable
48*/
49#define SetConfigValue(varname, defvalue) \
50    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
51    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
52    if (!container##varname) \
53    { \
54        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \
55        identifier##varname->addConfigValueContainer(#varname, container##varname); \
56    } \
57    container##varname->getValue(&varname, this)
58
59/**
60    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
61    @param classname name in which the config value should be stored
62    @param varname The name of the variable
63    @param defvalue The default-value of the variable
64*/
65#define SetConfigValueGeneric(classname, varname, defvalue) \
66    static orxonox::Identifier* identifier##varname = ClassIdentifier<classname>::getIdentifier(); \
67    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
68    if (!container##varname) \
69    { \
70        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, varname = defvalue); \
71        identifier##varname->addConfigValueContainer(#varname, container##varname); \
72    } \
73    container##varname->getValue(&varname, this)
74
75/**
76    @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).
77    @param varname The name of the std::vector
78    @param defvalue The default-value
79*/
80#define SetConfigValueVector(varname, defvalue) \
81    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
82    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
83    if (!container##varname) \
84    { \
85        std::vector<MultiTypeMath> temp; \
86        for (unsigned int i = 0; i < defvalue.size(); i++) \
87            temp.push_back(MultiTypeMath(defvalue[i])); \
88        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, identifier##varname, #varname, temp); \
89        container##varname->setVectorType(varname); \
90        identifier##varname->addConfigValueContainer(#varname, container##varname); \
91    } \
92    container##varname->getValue(&varname, this)
93
94/**
95    @brief Sets the variable and the config-file entry back to the previously defined default-value.
96    @param varname The name of the variable
97*/
98#define ResetConfigValue(varname) \
99    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
100    if (container##varname##reset) \
101    { \
102        container##varname##reset->reset(); \
103        container##varname##reset->getValue(&varname, this); \
104    } \
105    else \
106    { \
107        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
108    }
109
110/**
111    @brief Modifies a config-value by using a modifier and some arguments.
112    @param varname The name of the config-value
113    @param modifier The name of the modifier: set, tset, add, remove, reset, update
114*/
115#define ModifyConfigValue(varname, modifier, ...) \
116    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
117    if (container##varname##modify##modifier) \
118    { \
119        container##varname##modify##modifier->modifier(__VA_ARGS__); \
120        container##varname##modify##modifier->getValue(&varname, this); \
121    } \
122    else \
123    { \
124        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
125    }
126
127#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.