Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network64/src/core/CoreIncludes.h @ 2309

Last change on this file since 2309 was 2309, checked in by scheusso, 15 years ago

made some adjustments mostly to the networkid (classid) in order to have it platform independent

  • Property svn:eol-style set to native
File size: 4.7 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    @file
31    @brief Definition of macros for Identifier and Factory.
32
33    Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface
34    or the BaseObject itself, it needs the macro RegisterRootObject(class) instead.
35
36    To allow the object being created through the factory, use the CreateFactory(class) macro outside
37    the of the class implementation, so it gets executed before main().
38*/
39
40#ifndef _CoreIncludes_H__
41#define _CoreIncludes_H__
42
43#include "CorePrereqs.h"
44
45#include "Identifier.h"
46#include "Factory.h"
47#include "ClassFactory.h"
48#include "Functor.h"
49#include "util/Debug.h"
50#include "util/Integers.h"
51
52
53/**
54    @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject.
55    @param ClassName The name of the class
56    @param bRootClass True if the class is directly derived from OrxonoxClass
57*/
58#define InternRegisterObject(ClassName, bRootClass) \
59    this->setIdentifier(orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)); \
60    if (orxonox::Identifier::isCreatingHierarchy()) \
61    { \
62        if (this->getParents()) \
63        { \
64            orxonox::ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeClassHierarchy(this->getParents(), bRootClass); \
65            this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \
66        } \
67        this->setConfigValues(); \
68        return; \
69    } \
70    orxonox::ClassIdentifier<ClassName>::getIdentifier()->addObject(this)
71
72/**
73    @brief Intern macro, containing the specific part of RegisterRootObject.
74    @param ClassName The name of the class
75*/
76#define InternRegisterRootObject(ClassName) \
77    if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \
78        this->createParents(); \
79    InternRegisterObject(ClassName, true)
80
81/**
82    @brief RegisterObject - with and without debug output.
83    @param ClassName The name of the class
84*/
85#define RegisterObject(ClassName) \
86    COUT(5) << "*** Register Object: " << #ClassName << std::endl; \
87    InternRegisterObject(ClassName, false)
88
89/**
90    @brief RegisterRootObject - with and without debug output.
91    @param ClassName The name of the class
92*/
93#define RegisterRootObject(ClassName) \
94    COUT(5) << "*** Register Root-Object: " << #ClassName << std::endl; \
95    InternRegisterRootObject(ClassName)
96
97/**
98    @brief Creates the entry in the Factory.
99    @param ClassName The name of the class
100*/
101#define CreateFactory(ClassName) \
102    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true)
103
104/**
105    @brief Creates the entry in the Factory for classes which should not be loaded through XML.
106    @param ClassName The name of the class
107*/
108#define CreateUnloadableFactory(ClassName) \
109    bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false)
110
111/**
112    @brief Returns the Identifier of the given class.
113    @param ClassName The name of the class
114*/
115#define Class(ClassName) \
116    orxonox::ClassIdentifier<ClassName>::getIdentifier()
117
118/**
119    @brief Returns the Identifier with a given name through the factory.
120    @param String The name of the class
121*/
122#define ClassByString(String) \
123    orxonox::Factory::getIdentifier(String)
124
125/**
126    @brief Returns the Identifier with a given network ID through the factory.
127    @param networkID The network ID of the class
128*/
129#define ClassByID(networkID) \
130    orxonox::Factory::getIdentifier(networkID)
131
132/**
133    @brief Registers a member function as callback when an object of 'type' is created.
134    @param
135*/
136#define RegisterConstructionCallback(ThisClassName, TargetClassName, FunctionName) \
137    orxonox::ClassIdentifier<TargetClassName>::getIdentifier()->addConstructionCallback( \
138        orxonox::createFunctor(&ThisClassName::FunctionName)->setObject(this))
139
140#endif /* _CoreIncludes_H__ */
Note: See TracBrowser for help on using the repository browser.