Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/core/IdentifierIncludes.h @ 434

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

added a config-file-parser and a makro ( SetConfigValue(variable, defaultvalue) ) to get user-modified values from the config-file (or to write the defaultvalue into it if the variable isn't yet in the file).

File size: 3.1 KB
Line 
1/**
2    @file IDentifierIncludes.h
3    @brief Definition of macros for the class-hierarchy and the factory.
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 "OgreVector3.h"
21#include "OgreColourValue.h"
22
23namespace orxonox
24{
25    typedef Ogre::Vector3 Vector3;
26    typedef Ogre::ColourValue ColourValue;
27}
28
29// Intern macro, containing the common parts of RegisterObject and RegisterRootObject
30#define InternRegisterObject(ClassName, bRootClass) \
31    this->setIdentifier(ClassIdentifier<ClassName>::registerClass(this->getParents(), #ClassName, bRootClass)); \
32    if (Identifier::isCreatingHierarchy() && this->getParents()) \
33        this->getParents()->add(this->getIdentifier()); \
34    ClassIdentifier<ClassName>::addObject(this)
35
36// Intern macro, containing the specific part of RegisterRootObject
37#define InternRegisterRootObject(ClassName) \
38    if (Identifier::isCreatingHierarchy() && !this->getParents()) \
39        this->setParents(new IdentifierList()); \
40    InternRegisterObject(ClassName, true)
41
42// RegisterObject - with and without debug output
43#if HIERARCHY_VERBOSE
44#define RegisterObject(ClassName) \
45    std::cout << "*** Register Object: " << #ClassName << "\n"; \
46    InternRegisterObject(ClassName, false)
47#else
48#define RegisterObject(ClassName) \
49    InternRegisterObject(ClassName, false)
50#endif
51
52// RegisterRootObject - with and without debug output
53#if HIERARCHY_VERBOSE
54#define RegisterRootObject(ClassName) \
55    std::cout << "*** Register Root-Object: " << #ClassName << "\n"; \
56    InternRegisterRootObject(ClassName)
57#else
58#define RegisterRootObject(ClassName) \
59    InternRegisterRootObject(ClassName)
60#endif
61
62// Class(ClassName) returns the Identifier of the given class
63#define Class(ClassName) \
64    ClassIdentifier<ClassName>::getIdentifier()
65
66// Creates the entry in the Factory
67#define CreateFactory(ClassName) \
68    bool bCreated##ClassName##Factory = ClassFactory<ClassName>::create()
69
70// ID(StringOrInt) returns the Identifier with either a given name or a given NetworkID through the factory
71#define ID(StringOrInt) \
72    Factory::getIdentifier(StringOrInt)
73
74// bla
75#define SetConfigValue(varname, defvalue) \
76    ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
77    if (!container##varname) \
78    { \
79        container##varname = new ConfigValueContainer(this->getIdentifier()->getName(), #varname, defvalue); \
80        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
81    } \
82    this->varname = container##varname->getValue(varname)
Note: See TracBrowser for help on using the repository browser.