Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/ConfigValueIncludes.h @ 1600

Last change on this file since 1600 was 1543, checked in by rgrieder, 16 years ago
  • applied patch to remove ClassManager (wouldn't wanna maintain it anymore ;))
  • sorted core CMLs a little bit
  • updated OrxonoxStableHeaders.h
  • Property svn:eol-style set to native
File size: 5.0 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    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
51    if (!container##varname) \
52    { \
53        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
54        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
55    } \
56    container##varname->getValue(&varname)
57
58/**
59    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
60    @param classname name in which the config value should be stored
61    @param varname The name of the variable
62    @param defvalue The default-value of the variable
63*/
64#define SetConfigValueGeneric(classname, varname, defvalue) \
65    orxonox::ConfigValueContainer* container##varname = ClassIdentifier<classname>::getIdentifier()->getConfigValueContainer(#varname); \
66    if (!container##varname) \
67    { \
68        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, ClassIdentifier<classname>::getIdentifier(), #varname, varname = defvalue); \
69        ClassIdentifier<classname>::getIdentifier()->addConfigValueContainer(#varname, container##varname); \
70    } \
71    container##varname->getValue(&varname)
72
73/**
74    @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).
75    @param varname The name of the std::vector
76    @param defvalue The default-value
77*/
78#define SetConfigValueVector(varname, defvalue) \
79    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
80    if (!container##varname) \
81    { \
82        std::vector<MultiTypeMath> temp; \
83        for (unsigned int i = 0; i < defvalue.size(); i++) \
84            temp.push_back(MultiTypeMath(defvalue[i])); \
85        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
86        container##varname->setVectorType(varname); \
87        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
88    } \
89    container##varname->getValue(&varname)
90
91/**
92    @brief Sets the variable and the config-file entry back to the previously defined default-value.
93    @param varname The name of the variable
94*/
95#define ResetConfigValue(varname) \
96    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
97    if (container##varname##reset) \
98    { \
99        container##varname##reset->reset(); \
100        container##varname##reset->getValue(&varname); \
101    } \
102    else \
103    { \
104        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
105    }
106
107/**
108    @brief Modifies a config-value by using a modifier and some arguments.
109    @param varname The name of the config-value
110    @param modifier The name of the modifier: set, tset, add, remove, reset, update
111*/
112#define ModifyConfigValue(varname, modifier, ...) \
113    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
114    if (container##varname##modify##modifier) \
115    { \
116        container##varname##modify##modifier->modifier(__VA_ARGS__); \
117        container##varname##modify##modifier->getValue(&varname); \
118    } \
119    else \
120    { \
121        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
122    }
123
124#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.