Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/core/CoreIncludes.h @ 7363

Last change on this file since 7363 was 7363, checked in by landauf, 14 years ago

assigned a group to each header file in the core library

  • Property svn:eol-style set to native
File size: 4.3 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    @defgroup Factory RegisterObject() and CreateFactory()
31    @ingroup Object
32*/
33
34/**
35    @file
36    @ingroup Object Factory
37    @brief Definition of macros for Identifiers
38
39    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
40    or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
41
42    To allow the object being created through the factory, use the CreateFactory(class) macro outside
43    the of the class implementation, so it gets executed before main().
44*/
45
46#ifndef _CoreIncludes_H__
47#define _CoreIncludes_H__
48
49#include "CorePrereqs.h"
50
51#include "util/Debug.h"
52#include "Identifier.h"
53#include "SubclassIdentifier.h"
54#include "ClassFactory.h"
55#include "ObjectList.h"
56
57
58/**
59    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
60    @param ClassName The name of the class
61    @param bRootClass True if the class is directly derived from OrxonoxClass
62*/
63#define InternRegisterObject(ClassName, bRootClass) \
64    if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \
65        return; \
66    else \
67        ((void)0)
68
69/**
70    @brief RegisterObject - with and without debug output.
71    @param ClassName The name of the class
72*/
73#define RegisterObject(ClassName) \
74    InternRegisterObject(ClassName, false)
75
76/**
77    @brief RegisterRootObject - with and without debug output.
78    @param ClassName The name of the class
79*/
80#define RegisterRootObject(ClassName) \
81    InternRegisterObject(ClassName, true)
82
83/**
84    @brief Creates the Factory.
85    @param ClassName The name of the class
86*/
87#define CreateFactory(ClassName) \
88    Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)
89
90/**
91    @brief Creates the Factory for classes which should not be loaded through XML.
92    @param ClassName The name of the class
93*/
94#define CreateUnloadableFactory(ClassName) \
95    Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)
96
97/**
98    @brief Returns the Identifier of the given class.
99    @param ClassName The name of the class
100*/
101#define Class(ClassName) \
102    orxonox::ClassIdentifier<ClassName>::getIdentifier()
103
104
105namespace orxonox
106{
107    /**
108        @brief Returns the Identifier with a given name.
109        @param name The name of the class
110    */
111    inline Identifier* ClassByString(const std::string& name)
112    {
113        return Identifier::getIdentifierByString(name);
114    }
115
116    /**
117        @brief Returns the Identifier with a given lowercase name.
118        @param name The lowercase name of the class
119    */
120    inline Identifier* ClassByLowercaseString(const std::string& name)
121    {
122        return Identifier::getIdentifierByLowercaseString(name);
123    }
124
125    /**
126        @brief Returns the Identifier with a given network ID.
127        @param id The network ID of the class
128    */
129    inline Identifier* ClassByID(uint32_t id)
130    {
131        return Identifier::getIdentifierByID(id);
132    }
133
134    /**
135        @brief Returns the Identifier with a given 'this' pointer.
136        @note This of course only works with OrxonoxClasses.
137              The only use is in conjunction with macros that don't know the class type.
138        @param object Pointer to an OrxonoxClass
139    */
140    template <class T>
141    inline Identifier* ClassByObjectType(const T* object)
142    {
143        return ClassIdentifier<T>::getIdentifier();
144    }
145}
146
147#endif /* _CoreIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.