Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1055 was 1052, checked in by landauf, 16 years ago

merged core2 back to trunk
there might be some errors, wasn't able to test it yet due to some strange g++ and linker behaviour.

File size: 4.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28/**
29    @file ConfigValueIncludes.h
30    @brief Definition of macros for config-values.
31*/
32
33#ifndef _ConfigValueIncludes_H__
34#define _ConfigValueIncludes_H__
35
36#include "Identifier.h"
37#include "ConfigValueContainer.h"
38#include "ConfigFileManager.h"
39
40
41/**
42    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
43    @param varname The name of the variable
44    @param defvalue The default-value of the variable
45*/
46#define SetConfigValue(varname, defvalue) \
47    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
48    if (!container##varname) \
49    { \
50        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
51        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
52    } \
53    container##varname->getValue(&varname)
54
55/**
56    @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).
57    @param varname The name of the std::vector
58    @param defvalue The default-value
59*/
60#define SetConfigValueVector(varname, defvalue) \
61    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
62    if (!container##varname) \
63    { \
64        std::vector<MultiTypeMath> temp; \
65        for (unsigned int i = 0; i < defvalue.size(); i++) \
66            temp.push_back(MultiTypeMath(defvalue[i])); \
67        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
68        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
69    } \
70    container##varname->getValue(&varname)
71
72/**
73    @brief Sets the variable and the config-file entry back to the previously defined default-value.
74    @param varname The name of the variable
75*/
76#define ResetConfigValue(varname) \
77    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
78    if (container##varname##reset) \
79    { \
80        container##varname##reset->reset(); \
81        container##varname##reset->getValue(&varname); \
82    } \
83    else \
84    { \
85        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
86    }
87
88/**
89    @brief Modifies a config-value by using a modifier and some arguments.
90    @param varname The name of the config-value
91    @param modifier The name of the modifier: set, tset, add, remove, reset, update
92*/
93#define ModifyConfigValue(varname, modifier, ...) \
94    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
95    if (container##varname##modify##modifier) \
96    { \
97        container##varname##modify##modifier->modifier(__VA_ARGS__); \
98        container##varname##modify##modifier->getValue(&varname); \
99    } \
100    else \
101    { \
102        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
103    }
104
105/**
106    @brief Assigns the command, defined in the keybind-file, to the key-variable (or an empty string, if there is no entry in the file).
107    @param varname The name of the key-variable
108*/
109#define SetKeybind(keyname) \
110    orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
111    if (!container##keyname) \
112    { \
113        container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
114        this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
115    } \
116    container##keyname->getValue(&varname)
117
118#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.