Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/core/CoreIncludes.h @ 450

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

added Ogre::Vector2 as configurable type

File size: 3.8 KB
Line 
1/**
2    @file CoreIncludes.h
3    @brief Definition of macros and typedefs.
4
5    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
6    or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
7
8    To allow the object being created through the factory, use the CreateFactory(class) macro outside
9    the of the class implementation, so it gets executed before main().
10*/
11
12// All needed header-files
13#include "Identifier.h"
14#include "Factory.h"
15#include "ClassFactory.h"
16#include "Iterator.h"
17#include "OrxonoxClass.h"
18#include "ConfigValueContainer.h"
19
20#include "OgreVector2.h"
21#include "OgreVector3.h"
22#include "OgreColourValue.h"
23
24
25// Some typedefs
26namespace orxonox
27{
28    typedef Ogre::Vector2 Vector2;
29    typedef Ogre::Vector3 Vector3;
30    typedef Ogre::ColourValue ColourValue;
31}
32
33
34/**
35    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
36    @param ClassName The name of the class
37    @param bRootClass True if the class is directly derived from OrxonoxClass
38*/
39#define InternRegisterObject(ClassName, bRootClass) \
40    this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \
41    if (Identifier::isCreatingHierarchy() && this->getParents()) \
42        this->getParents()->add(this->getIdentifier()); \
43    ClassIdentifier<ClassName>::addObject(this)
44
45/**
46    @brief Intern macro, containing the specific part of RegisterRootObject.
47    @param ClassName The name of the class
48*/
49#define InternRegisterRootObject(ClassName) \
50    if (Identifier::isCreatingHierarchy() && !this->getParents()) \
51        this->setParents(new IdentifierList()); \
52    InternRegisterObject(ClassName, true)
53
54/**
55    @brief RegisterObject - with and without debug output.
56    @param ClassName The name of the class
57*/
58#if HIERARCHY_VERBOSE
59#define RegisterObject(ClassName) \
60    std::cout << "*** Register Object: " << #ClassName << "\n"; \
61    InternRegisterObject(ClassName, false)
62#else
63#define RegisterObject(ClassName) \
64    InternRegisterObject(ClassName, false)
65#endif
66
67/**
68    @brief RegisterRootObject - with and without debug output.
69    @param ClassName The name of the class
70*/
71#if HIERARCHY_VERBOSE
72#define RegisterRootObject(ClassName) \
73    std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \
74    InternRegisterRootObject(ClassName)
75#else
76#define RegisterRootObject(ClassName) \
77    InternRegisterRootObject(ClassName)
78#endif
79
80/**
81    @brief Returns the Identifier of the given class.
82    @param ClassName The name of the class
83*/
84#define Class(ClassName) \
85    ClassIdentifier<ClassName>::getIdentifier()
86
87/**
88    @brief Creates the entry in the Factory.
89    @param ClassName The name of the class
90*/
91#define CreateFactory(ClassName) \
92    bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create()
93
94/**
95    @brief Returns the Identifier with either a given name or a given network ID through the factory.
96    @param StringOrInt The name or the network ID of the class
97*/
98#define ID(StringOrInt) \
99    Factory::getIdentifier(StringOrInt)
100
101/**
102    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
103    @param varname The name of the variable
104    @param defvalue The default-value of the variable
105*/
106#define SetConfigValue(varname, defvalue) \
107    ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
108    if (!container##varname) \
109    { \
110        container##varname = new ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \
111        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
112    } \
113    varname = container##varname->getValue(varname)
Note: See TracBrowser for help on using the repository browser.