Changeset 9667 for code/trunk/src/libraries/core/CoreIncludes.h
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core6 merged: 9552-9554,9556-9574,9577-9579,9585-9593,9596-9612,9626-9662
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/CoreIncludes.h
r8858 r9667 28 28 29 29 /** 30 @defgroup Factory RegisterObject() and CreateFactory()30 @defgroup Factory RegisterObject() and RegisterClass() 31 31 @ingroup Object 32 32 */ … … 35 35 @file 36 36 @ingroup Object Factory Class Identifier 37 @brief Defines several very important macros used to register objects, create factories, and to work with identifiers. 38 39 Every class needs the @c RegisterObject(class) macro in its constructor. If the class is an interface 40 or the @c BaseObject itself, it needs the macro @c RegisterRootObject(class) instead. 41 42 To allow the object being created through the factory, use the @c CreateFactory(class) macro outside 43 of the class implementation, so it gets executed statically before @c main(). This will at the same time 44 register @a class in the class-hierarchy. If you don't want @a class to be loadable, but still 45 register it, call @c CreateUnloadableFactory(class). 37 @brief Defines several very important macros used to register objects, register classes, and to work with identifiers. 38 39 Every class needs the @c RegisterObject(class) macro in its constructor. 40 41 To register @a class in the class-hierarchy, use the @c RegisterClass(class) macro outside of the class implementation, 42 so it gets executed statically before @c main(). If you don't want @a class to be loadable, but still register it, call 43 @c RegisterUnloadableClass(class). 44 45 Abstract classes are registered with @c RegisterAbstractClass(class). For abstract classes, the inheritance must be 46 defined manually with @c RegisterAbstractClass(class).inheritsFrom(Class(parent)). Multiple parent classes can be defined 47 by chaining the above command. 46 48 47 49 Example: 48 50 @code 49 // Create the factory for MyClass50 CreateFactory(MyClass);51 // register MyClass 52 RegisterClass(MyClass); 51 53 52 54 // Constructor: … … 79 81 80 82 #include "util/Output.h" 81 #include "Identifier.h" 82 #include "ClassFactory.h" 83 #include "ObjectList.h" 84 85 86 /** 87 @brief Intern macro, containing the common parts of @c RegisterObject and @c RegisterRootObject. 88 @param ClassName The name of the class 89 @param bRootClass True if the class is directly derived from orxonox::OrxonoxClass 90 */ 91 #define InternRegisterObject(ClassName, bRootClass) \ 92 if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initialiseObject(this, #ClassName, bRootClass)) \ 83 #include "class/IdentifierManager.h" 84 #include "object/ClassFactory.h" 85 #include "object/ObjectList.h" 86 87 // resolve macro conflict on windows 88 #if defined(ORXONOX_PLATFORM_WINDOWS) 89 # include <windows.h> 90 # undef RegisterClass 91 #endif 92 93 94 /** 95 @brief Registers the class in the framework. 96 @param ClassName The name of the class 97 */ 98 #define RegisterClass(ClassName) \ 99 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), true) 100 101 /** 102 @brief Registers the class in the framework (for classes without arguments in their constructor). 103 @param ClassName The name of the class 104 */ 105 #define RegisterClassNoArgs(ClassName) \ 106 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryNoArgs<ClassName>(), true) 107 108 /** 109 @brief Registers the class in the framework (for classes which should not be loaded through XML). 110 @param ClassName The name of the class 111 */ 112 #define RegisterUnloadableClass(ClassName) \ 113 RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false) 114 115 /** 116 @brief Registers an abstract class in the framework. 117 @param ClassName The name of the class 118 */ 119 #define RegisterAbstractClass(ClassName) \ 120 RegisterClassWithFactory(ClassName, static_cast<ClassFactory<ClassName>*>(NULL), false) 121 122 /** 123 @brief Registers the class in the framework with a given Factory. 124 @param ClassName The name of the class 125 */ 126 #define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \ 127 Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable) 128 129 /** 130 @brief Registers a newly created object in the framework. Has to be called at the beginning of the constructor of @a ClassName. 131 @param ClassName The name of the class 132 */ 133 #define RegisterObject(ClassName) \ 134 if (ClassIdentifier<ClassName>::getIdentifier(#ClassName)->initializeObject(this)) \ 93 135 return; \ 94 136 else \ … … 96 138 97 139 /** 98 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.99 @param ClassName The name of the class100 */101 #define RegisterObject(ClassName) \102 InternRegisterObject(ClassName, false)103 104 /**105 @brief Registers a newly created object in the core. Has to be called at the beginning of the constructor of @a ClassName.106 @param ClassName The name of the class107 108 In contrast to RegisterObject, this is used for classes that inherit directly from109 orxonox::OrxonoxClass, namely all interfaces and orxonox::BaseObject.110 */111 #define RegisterRootObject(ClassName) \112 InternRegisterObject(ClassName, true)113 114 /**115 @brief Creates the Factory.116 @param ClassName The name of the class117 */118 #define CreateFactory(ClassName) \119 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true)120 121 /**122 @brief Creates the Factory for classes which should not be loaded through XML.123 @param ClassName The name of the class124 */125 #define CreateUnloadableFactory(ClassName) \126 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false)127 128 /**129 140 @brief Returns the Identifier of the given class. 130 141 @param ClassName The name of the class … … 137 148 { 138 149 /** 150 * @brief Overload of registerClass() which determines T implicitly by the template argument of the ClassFactory. 151 */ 152 template <class T> 153 inline Identifier& registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true) 154 { 155 return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable); 156 } 157 158 /** 159 * @brief Registers a class in the framework. 160 * @param name The name of the class 161 * @param factory The factory which is able to create new instances of this class 162 * @param bLoadable Whether the class is allowed to be loaded through XML 163 */ 164 template <class T> 165 inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true) 166 { 167 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl; 168 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 169 identifier->setFactory(factory); 170 identifier->setLoadable(bLoadable); 171 return *identifier; 172 } 173 174 /** 139 175 @brief Returns the Identifier with a given name. 140 176 @param name The name of the class … … 142 178 inline Identifier* ClassByString(const std::string& name) 143 179 { 144 return Identifier ::getIdentifierByString(name);180 return IdentifierManager::getInstance().getIdentifierByString(name); 145 181 } 146 182 … … 151 187 inline Identifier* ClassByLowercaseString(const std::string& name) 152 188 { 153 return Identifier ::getIdentifierByLowercaseString(name);189 return IdentifierManager::getInstance().getIdentifierByLowercaseString(name); 154 190 } 155 191 … … 160 196 inline Identifier* ClassByID(uint32_t id) 161 197 { 162 return Identifier ::getIdentifierByID(id);198 return IdentifierManager::getInstance().getIdentifierByID(id); 163 199 } 164 200 165 201 /** 166 202 @brief Returns the Identifier with a given 'this' pointer. 167 @note This of course only works with OrxonoxClasses.203 @note This of course only works with Identifiables. 168 204 The only use is in conjunction with macros that don't know the class type. 169 @param object Pointer to an OrxonoxClass205 @param object Pointer to an Identifiable 170 206 */ 171 207 template <class T>
Note: See TracChangeset
for help on using the changeset viewer.