- Timestamp:
- Apr 25, 2015, 10:49:34 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core7/src/libraries/core/class/Identifier.h
r10381 r10395 82 82 83 83 #include "util/Output.h" 84 #include "util/OrxAssert.h" 84 85 #include "core/object/ObjectList.h" 85 86 #include "core/object/Listable.h" … … 109 110 { 110 111 public: 111 Identifier( );112 Identifier(const std::string& name, Factory* factory, bool bLoadable); 112 113 Identifier(const Identifier& identifier); // don't copy 113 114 virtual ~Identifier(); … … 115 116 /// Returns the name of the class the Identifier belongs to. 116 117 inline const std::string& getName() const { return this->name_; } 117 void setName(const std::string& name);118 118 119 119 /// Returns the name of the class as it is returned by typeid(T).name() … … 127 127 ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; } 128 128 129 /// Sets the Factory.130 void setFactory(Factory* factory);131 129 /// Returns true if the Identifier has a Factory. 132 130 inline bool hasFactory() const { return (this->factory_ != 0); } … … 136 134 /// Returns true if the class can be loaded through XML. 137 135 inline bool isLoadable() const { return this->bLoadable_; } 138 /// Set the class to be loadable through XML or not.139 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; }140 136 141 137 /// Returns true if child classes should inherit virtually from this class. … … 264 260 265 261 public: 266 static ClassIdentifier<T>* getIdentifier(); 267 static ClassIdentifier<T>* getIdentifier(const std::string& name); 268 269 bool initializeObject(T* object); 270 271 void setConfigValues(T* object, Configurable*) const; 272 void setConfigValues(T* object, Identifiable*) const; 273 274 void addObjectToList(T* object, Listable*); 275 void addObjectToList(T* object, Identifiable*); 276 277 virtual void updateConfigValues(bool updateChildren = true) const; 278 279 virtual const std::string& getTypeidName() 280 { return this->typeidName_; } 281 282 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 283 { return dynamic_cast<T*>(object) != 0; } 284 285 private: 286 static void initializeIdentifier(); 287 288 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 289 ClassIdentifier() 262 ClassIdentifier(const std::string& name, Factory* factory, bool bLoadable) : Identifier(name, factory, bLoadable) 290 263 { 264 OrxVerify(ClassIdentifier<T>::classIdentifier_s == NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 265 ClassIdentifier<T>::classIdentifier_s = this; 266 291 267 this->typeidName_ = typeid(T).name(); 292 268 SuperFunctionInitialization<0, T>::initialize(this); … … 297 273 } 298 274 275 bool initializeObject(T* object); 276 277 void setConfigValues(T* object, Configurable*) const; 278 void setConfigValues(T* object, Identifiable*) const; 279 280 void addObjectToList(T* object, Listable*); 281 void addObjectToList(T* object, Identifiable*); 282 283 virtual void updateConfigValues(bool updateChildren = true) const; 284 285 virtual const std::string& getTypeidName() 286 { return this->typeidName_; } 287 288 virtual bool canDynamicCastObjectToIdentifierClass(Identifiable* object) const 289 { return dynamic_cast<T*>(object) != 0; } 290 291 static ClassIdentifier<T>* getIdentifier(); 292 293 private: 294 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 295 299 296 void updateConfigValues(bool updateChildren, Listable*) const; 300 297 void updateConfigValues(bool updateChildren, Identifiable*) const; … … 312 309 */ 313 310 template <class T> 314 inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier()315 { 316 // check if the Identifier already exists317 if (!ClassIdentifier<T>::classIdentifier_s)318 ClassIdentifier<T>::initializeIdentifier(); 319 311 /*static*/ inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 312 { 313 if (ClassIdentifier<T>::classIdentifier_s == NULL) 314 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*) IdentifierManager::getInstance().getIdentifierByTypeidName(typeid(T).name()); 315 316 OrxVerify(ClassIdentifier<T>::classIdentifier_s != NULL, "Assertion failed in ClassIdentifier of type " << typeid(T).name()); 320 317 return ClassIdentifier<T>::classIdentifier_s; 321 }322 323 /**324 @brief Does the same as getIdentifier() but sets the name if this wasn't done yet.325 @param name The name of this Identifier326 @return The Identifier327 */328 template <class T>329 inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier(const std::string& name)330 {331 ClassIdentifier<T>* identifier = ClassIdentifier<T>::getIdentifier();332 identifier->setName(name);333 return identifier;334 }335 336 /**337 @brief Assigns the static field for the identifier singleton.338 */339 template <class T>340 /*static */ void ClassIdentifier<T>::initializeIdentifier()341 {342 // create a new identifier anyway. Will be deleted if not used.343 ClassIdentifier<T>* proposal = new ClassIdentifier<T>();344 345 // Get the entry from the map346 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal);347 348 if (ClassIdentifier<T>::classIdentifier_s == proposal)349 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl;350 else351 {352 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl;353 delete proposal; // delete proposal (it is not used anymore)354 }355 318 } 356 319
Note: See TracChangeset
for help on using the changeset viewer.