Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/CoreIncludes.h @ 705

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

added function to add descriptions to config values

File size: 5.6 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 CoreIncludes.h
30    @brief Definition of macros and typedefs.
31
32    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
33    or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
34
35    To allow the object being created through the factory, use the CreateFactory(class) macro outside
36    the of the class implementation, so it gets executed before main().
37*/
38
39#ifndef _CoreIncludes_H__
40#define _CoreIncludes_H__
41
42#include "CorePrereqs.h"
43
44// All needed header-files
45#include "Identifier.h"
46#include "Factory.h"
47#include "ClassFactory.h"
48#include "Iterator.h"
49#include "OrxonoxClass.h"
50#include "ConfigValueContainer.h"
51#include "Debug.h"
52
53#include "OgreVector2.h"
54#include "OgreVector3.h"
55#include "OgreColourValue.h"
56#include "OgreQuaternion.h"
57#include "OgreMatrix3.h"
58
59
60// Some typedefs
61namespace orxonox
62{
63    typedef Ogre::Vector2 Vector2;
64    typedef Ogre::Vector3 Vector3;
65    typedef Ogre::ColourValue ColourValue;
66    typedef Ogre::Radian Radian;
67    typedef Ogre::Degree Degree;
68    typedef Ogre::Real Real;
69    typedef Ogre::Quaternion Quaternion;
70    typedef Ogre::Matrix3 Matrix3;
71}
72
73
74/**
75    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
76    @param ClassName The name of the class
77    @param bRootClass True if the class is directly derived from OrxonoxClass
78*/
79#define InternRegisterObject(ClassName, bRootClass) \
80    this->setIdentifier(orxonox::ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \
81    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
82        this->getParents()->add(this->getIdentifier()); \
83    orxonox::ClassIdentifier<ClassName>::addObject(this)
84
85/**
86    @brief Intern macro, containing the specific part of RegisterRootObject.
87    @param ClassName The name of the class
88*/
89#define InternRegisterRootObject(ClassName) \
90    if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \
91        this->setParents(new orxonox::IdentifierList()); \
92    InternRegisterObject(ClassName, true)
93
94/**
95    @brief RegisterObject - with and without debug output.
96    @param ClassName The name of the class
97*/
98#define RegisterObject(ClassName) \
99    COUT(4) << "*** Register Object: " << #ClassName << std::endl; \
100    InternRegisterObject(ClassName, false)
101
102/**
103    @brief RegisterRootObject - with and without debug output.
104    @param ClassName The name of the class
105*/
106#define RegisterRootObject(ClassName) \
107    COUT(4) << "*** Register Root-Object: " << #ClassName << std::endl; \
108    InternRegisterRootObject(ClassName)
109
110/**
111    @brief Returns the Identifier of the given class.
112    @param ClassName The name of the class
113*/
114#define Class(ClassName) \
115    ClassIdentifier<ClassName>::getIdentifier()
116
117/**
118    @brief Creates the entry in the Factory.
119    @param ClassName The name of the class
120*/
121#define CreateFactory(ClassName) \
122    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
123
124/**
125    @brief Returns the Identifier with either a given name or a given network ID through the factory.
126    @param StringOrInt The name or the network ID of the class
127*/
128#define ID(StringOrInt) \
129    orxonox::Factory::getIdentifier(StringOrInt)
130
131/**
132    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
133    @param varname The name of the variable
134    @param defvalue The default-value of the variable
135*/
136#define SetConfigValue(varname, defvalue) \
137    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
138    if (!container##varname) \
139    { \
140        container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \
141        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
142    } \
143    container##varname->getValue(varname)
144
145/**
146    @brief Sets the variable and the config-file entry back to the previously defined default-value.
147    @param varname The name of the variable
148*/
149#define ResetConfigValue(varname) \
150    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
151    if (container##varname##reset) \
152    { \
153        container##varname##reset->resetConfigValue(); \
154        container##varname##reset->getValue(varname); \
155    } \
156    else \
157        COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl
158
159#endif /* _CoreIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.