Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4070 was 3280, checked in by rgrieder, 15 years ago

Merged most of the core4 revisions back to the trunk except for:

  • orxonox_cast
  • all the radical changes in the input library
  • Property svn:eol-style set to native
File size: 4.4 KB
RevLine 
[1505]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/**
[2171]30    @file
[1505]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*/
[1747]49#define SetConfigValueGeneric(type, varname, defvalue) \
50    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
51    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
[1505]52    if (!container##varname) \
53    { \
[3280]54        container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue, varname); \
[1747]55        identifier##varname->addConfigValueContainer(#varname, container##varname); \
[1505]56    } \
[1747]57    container##varname->getValue(&varname, this)
[1505]58
[2103]59#define SetConfigValue(varname, defvalue) SetConfigValueGeneric(ConfigFileType::Settings, varname, defvalue)
[1505]60
[1747]61
[1505]62/**
63    @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).
64    @param varname The name of the std::vector
65    @param defvalue The default-value
66*/
[1747]67#define SetConfigValueVectorGeneric(type, varname, defvalue) \
68    static orxonox::Identifier* identifier##varname = this->getIdentifier(); \
69    orxonox::ConfigValueContainer* container##varname = identifier##varname->getConfigValueContainer(#varname); \
[1505]70    if (!container##varname) \
71    { \
[3280]72        container##varname = new orxonox::ConfigValueContainer(type, identifier##varname, identifier##varname->getName(), #varname, defvalue); \
[1747]73        identifier##varname->addConfigValueContainer(#varname, container##varname); \
[1505]74    } \
[1747]75    container##varname->getValue(&varname, this)
[1505]76
[2103]77#define SetConfigValueVector(varname, defvalue) SetConfigValueVectorGeneric(ConfigFileType::Settings, varname, defvalue)
[1747]78
79
[1505]80/**
81    @brief Sets the variable and the config-file entry back to the previously defined default-value.
82    @param varname The name of the variable
83*/
84#define ResetConfigValue(varname) \
85    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
86    if (container##varname##reset) \
87    { \
88        container##varname##reset->reset(); \
[1747]89        container##varname##reset->getValue(&varname, this); \
[1505]90    } \
91    else \
92    { \
93        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
94    }
95
[1747]96
[1505]97/**
98    @brief Modifies a config-value by using a modifier and some arguments.
99    @param varname The name of the config-value
100    @param modifier The name of the modifier: set, tset, add, remove, reset, update
101*/
102#define ModifyConfigValue(varname, modifier, ...) \
103    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
104    if (container##varname##modify##modifier) \
105    { \
106        container##varname##modify##modifier->modifier(__VA_ARGS__); \
[1747]107        container##varname##modify##modifier->getValue(&varname, this); \
[1505]108    } \
109    else \
110    { \
111        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
112    }
113
114#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.