Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added two new classes:

  • ClassManager, a helper class for ClassIdentifier
  • IdentifierDistributor, a class that hopefully allows unique ClassIdentifiers even with several libraries

In a first try it seemed to work, but it needs more testing. At least it solved a problem I discovered yesterday with multiple Identifiers for the type "BaseObject" on windows.

File size: 6.1 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 "ClassManager.h"
47#include "Factory.h"
48#include "ClassFactory.h"
49#include "Iterator.h"
50#include "OrxonoxClass.h"
51#include "ConfigValueContainer.h"
52#include "Debug.h"
53
54/**
55    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
56    @param ClassName The name of the class
57    @param bRootClass True if the class is directly derived from OrxonoxClass
58*/
59#define InternRegisterObject(ClassName, bRootClass) \
60    this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->registerClass(this->getParents(), #ClassName, bRootClass)); \
61    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \
62        this->getParents()->add(this->getIdentifier()); \
63    orxonox::ClassManager<ClassName>::getIdentifier(#ClassName)->addObject(this)
64
65/**
66    @brief Intern macro, containing the specific part of RegisterRootObject.
67    @param ClassName The name of the class
68*/
69#define InternRegisterRootObject(ClassName) \
70    if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \
71        this->setParents(new orxonox::IdentifierList()); \
72    InternRegisterObject(ClassName, true)
73
74/**
75    @brief RegisterObject - with and without debug output.
76    @param ClassName The name of the class
77*/
78#define RegisterObject(ClassName) \
79    COUT(4) << "*** Register Object: " << #ClassName << std::endl; \
80    InternRegisterObject(ClassName, false)
81
82/**
83    @brief RegisterRootObject - with and without debug output.
84    @param ClassName The name of the class
85*/
86#define RegisterRootObject(ClassName) \
87    COUT(4) << "*** Register Root-Object: " << #ClassName << std::endl; \
88    InternRegisterRootObject(ClassName)
89
90/**
91    @brief Exports the necessary templates in order to make them available to all libraries.
92    @param ClassName The name of the Class
93    @param LibraryName The name of the Library
94*/
95#define ExportClass(ClassName, LibraryName) \
96    template class _##LibraryName##Export orxonox::ClassIdentifier<ClassName>; \
97    template class _##LibraryName##Export orxonox::ObjectList<ClassName>; \
98    template class _##LibraryName##Export orxonox::ClassFactory<ClassName>
99
100/**
101    @brief Exports the necessary templates in order to make them available to all libraries.
102    @param ClassName The name of the Class
103    @param LibraryName The name of the Library
104*/
105#define ExportAbstractClass(ClassName, LibraryName) \
106    template class _##LibraryName##Export orxonox::ClassIdentifier<ClassName>; \
107    template class _##LibraryName##Export orxonox::ObjectList<ClassName>
108
109/**
110    @brief Returns the Identifier of the given class.
111    @param ClassName The name of the class
112*/
113#define Class(ClassName) \
114    ClassManager<ClassName>::getIdentifier(#ClassName)
115
116/**
117    @brief Creates the entry in the Factory.
118    @param ClassName The name of the class
119*/
120#define CreateFactory(ClassName) \
121    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName)
122
123/**
124    @brief Returns the Identifier with either a given name or a given network ID through the factory.
125    @param StringOrInt The name or the network ID of the class
126*/
127#define ID(StringOrInt) \
128    orxonox::Factory::getIdentifier(StringOrInt)
129
130/**
131    @brief Assigns the value, defined in the config-file, to the variable (or the default-value, if there is no entry in the file).
132    @param varname The name of the variable
133    @param defvalue The default-value of the variable
134*/
135#define SetConfigValue(varname, defvalue) \
136    orxonox::ConfigValueContainer* container##varname = this->getIdentifier()->getConfigValueContainer(#varname); \
137    if (!container##varname) \
138    { \
139        container##varname = new orxonox::ConfigValueContainer(this->getIdentifier()->getName(), #varname, varname = defvalue); \
140        this->getIdentifier()->setConfigValueContainer(#varname, container##varname); \
141    } \
142    container##varname->getValue(&varname)
143
144/**
145    @brief Sets the variable and the config-file entry back to the previously defined default-value.
146    @param varname The name of the variable
147*/
148#define ResetConfigValue(varname) \
149    orxonox::ConfigValueContainer* container##varname##reset = this->getIdentifier()->getConfigValueContainer(#varname); \
150    if (container##varname##reset) \
151    { \
152        container##varname##reset->resetConfigValue(); \
153        container##varname##reset->getValue(&varname); \
154    } \
155    else \
156        COUT(2) << "Warning: Couldn't reset variable " << #varname << ", corresponding container doesn't exist." << std::endl
157
158#endif /* _CoreIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.