Changeset 10624 for code/trunk/src/libraries/core/CoreIncludes.h
- Timestamp:
- Oct 4, 2015, 9:12:21 PM (10 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
-
code/trunk/src/libraries/core/CoreIncludes.h
r10208 r10624 84 84 #include "object/ClassFactory.h" 85 85 #include "object/ObjectList.h" 86 #include "module/StaticallyInitializedInstance.h" 86 87 87 88 // resolve macro conflict on windows … … 126 127 */ 127 128 #define RegisterClassWithFactory(ClassName, FactoryInstance, bLoadable) \ 128 Identifier& _##ClassName##Identifier = orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable)129 orxonox::SI_I& _##ClassName##Identifier = (*new orxonox::SI_I(orxonox::registerClass<ClassName>(#ClassName, FactoryInstance, bLoadable))) 129 130 130 131 /** … … 133 134 */ 134 135 #define RegisterObject(ClassName) \ 135 if (ClassIdentifier<ClassName>::getIdentifier( #ClassName)->initializeObject(this)) \136 if (ClassIdentifier<ClassName>::getIdentifier()->initializeObject(this)) \ 136 137 return; \ 137 138 else \ … … 152 153 */ 153 154 template <class T> 154 inline Identifier ®isterClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true)155 inline Identifier* registerClass(const std::string& name, ClassFactory<T>* factory, bool bLoadable = true) 155 156 { 156 157 return registerClass<T>(name, static_cast<Factory*>(factory), bLoadable); … … 164 165 */ 165 166 template <class T> 166 inline Identifier& registerClass(const std::string& name, Factory* factory, bool bLoadable = true) 167 { 168 orxout(verbose, context::misc::factory) << "Create entry for " << name << " in Factory." << endl; 169 Identifier* identifier = ClassIdentifier<T>::getIdentifier(name); 170 identifier->setFactory(factory); 171 identifier->setLoadable(bLoadable); 172 return *identifier; 167 inline Identifier* registerClass(const std::string& name, Factory* factory, bool bLoadable = true) 168 { 169 return new ClassIdentifier<T>(name, factory, bLoadable); 173 170 } 174 171 … … 211 208 return ClassIdentifier<T>::getIdentifier(); 212 209 } 210 211 212 213 214 /** 215 * The static initializer stores the parent classes of this identifier. The corresponding identifiers are later loaded. This prevents identifiers from 216 * being used before they are completely initialized. 217 */ 218 class _CoreExport StaticallyInitializedIdentifier : public StaticallyInitializedInstance 219 { 220 template <class T> 221 struct InheritsFromClass : public Identifier::InheritsFrom 222 { 223 virtual Identifier* getParent() const { return Class(T); } 224 }; 225 226 public: 227 StaticallyInitializedIdentifier(Identifier* identifier) 228 : StaticallyInitializedInstance(StaticInitialization::IDENTIFIER) 229 , identifier_(identifier) 230 {} 231 ~StaticallyInitializedIdentifier() { delete identifier_; } 232 233 virtual void load() 234 { 235 IdentifierManager::getInstance().addIdentifier(this->identifier_); 236 } 237 238 virtual void unload() 239 { 240 IdentifierManager::getInstance().removeIdentifier(this->identifier_); 241 } 242 243 inline Identifier& getIdentifier() 244 { return *this->identifier_; } 245 246 template <class T> 247 inline StaticallyInitializedIdentifier& inheritsFrom() 248 { this->identifier_->inheritsFrom(new InheritsFromClass<T>()); return *this; } 249 250 inline StaticallyInitializedIdentifier& virtualBase() 251 { this->identifier_->setVirtualBase(true); return *this; } 252 253 private: 254 Identifier* identifier_; 255 }; 256 257 typedef StaticallyInitializedIdentifier SI_I; 213 258 } 214 259
Note: See TracChangeset
for help on using the changeset viewer.