Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

don't panic, no codechanges!
added a link to www.orxonox.net

File size: 4.9 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 "Identifier.h"
38#include "ConfigValueContainer.h"
39#include "ConfigFileManager.h"
40
41
42/**
43    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
44    @param varname The name of the variable
45    @param defvalue The default-value of the variable
46*/
47#define SetConfigValue(varname, defvalue) \
48    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
49    if (!container##varname) \
50    { \
51        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, varname = defvalue); \
52        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
53    } \
54    container##varname->getValue(&varname)
55
56/**
57    @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).
58    @param varname The name of the std::vector
59    @param defvalue The default-value
60*/
61#define SetConfigValueVector(varname, defvalue) \
62    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
63    if (!container##varname) \
64    { \
65        std::vector<MultiTypeMath> temp; \
66        for (unsigned int i = 0; i < defvalue.size(); i++) \
67            temp.push_back(MultiTypeMath(defvalue[i])); \
68        container##varname = new orxonox::ConfigValueContainer(CFT_Settings, this->getIdentifier(), #varname, temp); \
69        this->getIdentifier()->addConfigValueContainer(#varname, container##varname); \
70    } \
71    container##varname->getValue(&varname)
72
73/**
74    @brief Sets the variable and the config-file entry back to the previously defined default-value.
75    @param varname The name of the variable
76*/
77#define ResetConfigValue(varname) \
78    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
79    if (container##varname##reset) \
80    { \
81        container##varname##reset->reset(); \
82        container##varname##reset->getValue(&varname); \
83    } \
84    else \
85    { \
86        COUT(2) << "Warning: Couldn't reset config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
87    }
88
89/**
90    @brief Modifies a config-value by using a modifier and some arguments.
91    @param varname The name of the config-value
92    @param modifier The name of the modifier: set, tset, add, remove, reset, update
93*/
94#define ModifyConfigValue(varname, modifier, ...) \
95    orxonox::ConfigValueContainer* container##varname##modify##modifier = this->getIdentifier()->getConfigValueContainer(#varname); \
96    if (container##varname##modify##modifier) \
97    { \
98        container##varname##modify##modifier->modifier(__VA_ARGS__); \
99        container##varname##modify##modifier->getValue(&varname); \
100    } \
101    else \
102    { \
103        COUT(2) << "Warning: Couln't modify config-value '" << #varname << "', corresponding container doesn't exist." << std::endl; \
104    }
105
106/**
107    @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).
108    @param varname The name of the key-variable
109*/
110#define SetKeybind(keyname) \
111    orxonox::ConfigValueContainer* container##keyname = this->getIdentifier()->getConfigValueContainer(#keyname); \
112    if (!container##keyname) \
113    { \
114        container##keyname = new orxonox::ConfigValueContainer(CFT_Keybindings, this->getIdentifier(), #keyname, keyname = ""); \
115        this->getIdentifier()->addConfigValueContainer(#keyname, container##keyname); \
116    } \
117    container##keyname->getValue(&varname)
118
119#endif /* _ConfigValueIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.