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 for Identifier and Factory. |
---|
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 "Identifier.h" |
---|
43 | #include "ClassManager.h" |
---|
44 | #include "Factory.h" |
---|
45 | #include "ClassFactory.h" |
---|
46 | #include "Debug.h" |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | @brief Intern macro, containing the common parts of RegisterObject and RegisterRootObject. |
---|
51 | @param ClassName The name of the class |
---|
52 | @param bRootClass True if the class is directly derived from OrxonoxClass |
---|
53 | */ |
---|
54 | #define InternRegisterObject(ClassName, bRootClass) \ |
---|
55 | this->setIdentifier(orxonox::ClassManager<ClassName>::getIdentifier()->registerClass(this->getParents(), #ClassName, bRootClass)); \ |
---|
56 | if (orxonox::Identifier::isCreatingHierarchy() && this->getParents()) \ |
---|
57 | this->getParents()->insert(this->getParents()->end(), this->getIdentifier()); \ |
---|
58 | orxonox::ClassManager<ClassName>::getIdentifier()->addObject(this) |
---|
59 | |
---|
60 | /** |
---|
61 | @brief Intern macro, containing the specific part of RegisterRootObject. |
---|
62 | @param ClassName The name of the class |
---|
63 | */ |
---|
64 | #define InternRegisterRootObject(ClassName) \ |
---|
65 | if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents()) \ |
---|
66 | this->createParents(); \ |
---|
67 | InternRegisterObject(ClassName, true) |
---|
68 | |
---|
69 | /** |
---|
70 | @brief RegisterObject - with and without debug output. |
---|
71 | @param ClassName The name of the class |
---|
72 | */ |
---|
73 | #define RegisterObject(ClassName) \ |
---|
74 | COUT(5) << "*** Register Object: " << #ClassName << std::endl; \ |
---|
75 | InternRegisterObject(ClassName, false) |
---|
76 | |
---|
77 | /** |
---|
78 | @brief RegisterRootObject - with and without debug output. |
---|
79 | @param ClassName The name of the class |
---|
80 | */ |
---|
81 | #define RegisterRootObject(ClassName) \ |
---|
82 | COUT(5) << "*** Register Root-Object: " << #ClassName << std::endl; \ |
---|
83 | InternRegisterRootObject(ClassName) |
---|
84 | |
---|
85 | /** |
---|
86 | @brief Returns the Identifier of the given class. |
---|
87 | @param ClassName The name of the class |
---|
88 | */ |
---|
89 | #define Class(ClassName) \ |
---|
90 | ClassManager<ClassName>::getIdentifier() |
---|
91 | |
---|
92 | /** |
---|
93 | @brief Creates the entry in the Factory. |
---|
94 | @param ClassName The name of the class |
---|
95 | */ |
---|
96 | #define CreateFactory(ClassName) \ |
---|
97 | bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) |
---|
98 | |
---|
99 | /** |
---|
100 | @brief Returns the Identifier with either a given name or a given network ID through the factory. |
---|
101 | @param StringOrInt The name or the network ID of the class |
---|
102 | */ |
---|
103 | #define ID(StringOrInt) \ |
---|
104 | orxonox::Factory::getIdentifier(StringOrInt) |
---|
105 | |
---|
106 | #endif /* _CoreIncludes_H__ */ |
---|