Changeset 9667 for code/trunk/src/libraries/core/class/Identifier.h
- Timestamp:
- Aug 25, 2013, 9:08:42 PM (12 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
- 1 copied
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/class/Identifier.h
r9593 r9667 56 56 object->getIdentifier()->getName(); // returns "MyClass" 57 57 58 OrxonoxClass* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 59 60 61 // iterate through all objects of type MyClass: 62 ObjectListBase* objects = object->getIdentifier()->getObjects(); // get a pointer to the object-list 63 int count; 64 for (Iterator<MyClass> it = objects.begin(); it != objects.end(); ++it) // iterate through the objects 65 ++count; 66 orxout() << count << endl; // prints "2" because we created 2 instances of MyClass so far 58 Identifiable* other = object->getIdentifier()->fabricate(0); // fabricates a new instance of MyClass 67 59 68 60 … … 90 82 91 83 #include "util/Output.h" 92 #include "core/object/MetaObjectList.h"93 84 #include "core/object/ObjectList.h" 94 #include "core/object/ObjectListBase.h" 85 #include "core/object/Listable.h" 86 #include "core/object/Context.h" 87 #include "core/object/Destroyable.h" 88 #include "core/object/WeakPtr.h" 95 89 #include "IdentifierManager.h" 96 90 #include "Super.h" … … 112 106 @note You can't directly create an Identifier, it's just the base-class of ClassIdentifier<T>. 113 107 */ 114 class _CoreExport Identifier 115 { 116 friend class IdentifierManager; 117 108 class _CoreExport Identifier : public Destroyable 109 { 118 110 public: 111 Identifier(); 112 Identifier(const Identifier& identifier); // don't copy 113 virtual ~Identifier(); 114 119 115 /// Returns the name of the class the Identifier belongs to. 120 116 inline const std::string& getName() const { return this->name_; } 121 117 void setName(const std::string& name); 122 118 119 /// Returns the name of the class as it is returned by typeid(T).name() 120 virtual const std::string& getTypeidName() = 0; 121 123 122 /// Returns the network ID to identify a class through the network. 124 123 inline uint32_t getNetworkID() const { return this->networkID_; } … … 128 127 ORX_FORCEINLINE unsigned int getClassID() const { return this->classID_; } 129 128 130 /// Returns the list of all existing objects of this class.131 inline ObjectListBase* getObjects() const { return this->objects_; }132 133 129 /// Sets the Factory. 134 inline void addFactory(Factory* factory) { this->factory_ = factory; }130 void setFactory(Factory* factory); 135 131 /// Returns true if the Identifier has a Factory. 136 132 inline bool hasFactory() const { return (this->factory_ != 0); } 137 133 138 OrxonoxClass* fabricate(BaseObject* creator);134 Identifiable* fabricate(Context* context); 139 135 140 136 /// Returns true if the class can be loaded through XML. … … 142 138 /// Set the class to be loadable through XML or not. 143 139 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 140 141 /// Returns true if the Identifier was completely initialized. 142 inline bool isInitialized() const { return this->bInitialized_; } 143 144 145 ///////////////////////////// 146 ////// Class Hierarchy ////// 147 ///////////////////////////// 148 Identifier& inheritsFrom(Identifier* directParent); 149 150 void initializeParents(const std::set<const Identifier*>& identifiers); 151 void initializeDirectParentsOfAbstractClass(); 152 void finishInitialization(); 144 153 145 154 bool isA(const Identifier* identifier) const; … … 150 159 bool isDirectParentOf(const Identifier* identifier) const; 151 160 152 153 /////////////////////////////154 ////// Class Hierarchy //////155 /////////////////////////////156 161 /// Returns the parents of the class the Identifier belongs to. 157 162 inline const std::set<const Identifier*>& getParents() const { return this->parents_; } … … 220 225 221 226 protected: 222 Identifier();223 Identifier(const Identifier& identifier); // don't copy224 virtual ~Identifier();225 226 227 virtual void createSuperFunctionCaller() const = 0; 227 228 228 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);229 230 /// Returns the children of the class the Identifier belongs to.231 inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; }232 /// Returns the direct children of the class the Identifier belongs to.233 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; }234 235 ObjectListBase* objects_; //!< The list of all objects of this class236 237 229 private: 238 void initialize(std::set<const Identifier*>* parents);239 240 230 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 241 mutable std::set<const Identifier*> children_;//!< The children of the class the Identifier belongs to231 std::set<const Identifier*> children_; //!< The children of the class the Identifier belongs to 242 232 243 233 std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 244 mutable std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to 245 246 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 247 bool bSetName_; //!< True if the name is set 234 std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to 235 236 bool bInitialized_; //!< Is true if the Identifier was completely initialized 248 237 bool bLoadable_; //!< False = it's not permitted to load the object through XML 249 238 std::string name_; //!< The name of the class the Identifier belongs to … … 287 276 static ClassIdentifier<T>* getIdentifier(const std::string& name); 288 277 289 bool initiali seObject(T* object, const std::string& className, bool bRootClass);278 bool initializeObject(T* object); 290 279 291 280 void setConfigValues(T* object, Configurable*) const; … … 295 284 void addObjectToList(T* object, Identifiable*); 296 285 297 void updateConfigValues(bool updateChildren = true) const; 286 virtual void updateConfigValues(bool updateChildren = true) const; 287 288 virtual const std::string& getTypeidName() 289 { return this->typeidName_; } 298 290 299 291 private: 300 static void initialiseIdentifier(); 292 static void initializeIdentifier(); 293 301 294 ClassIdentifier(const ClassIdentifier<T>& identifier) {} // don't copy 302 295 ClassIdentifier() 303 296 { 297 this->typeidName_ = typeid(T).name(); 304 298 SuperFunctionInitialization<0, T>::initialize(this); 305 299 } … … 309 303 } 310 304 311 static ClassIdentifier<T>* classIdentifier_s; 305 void updateConfigValues(bool updateChildren, Listable*) const; 306 void updateConfigValues(bool updateChildren, Identifiable*) const; 307 308 std::string typeidName_; 309 static WeakPtr<ClassIdentifier<T> > classIdentifier_s; 312 310 }; 313 311 314 312 template <class T> 315 ClassIdentifier<T>* ClassIdentifier<T>::classIdentifier_s = 0;313 WeakPtr<ClassIdentifier<T> > ClassIdentifier<T>::classIdentifier_s; 316 314 317 315 /** … … 324 322 // check if the Identifier already exists 325 323 if (!ClassIdentifier<T>::classIdentifier_s) 326 ClassIdentifier<T>::initiali seIdentifier();324 ClassIdentifier<T>::initializeIdentifier(); 327 325 328 326 return ClassIdentifier<T>::classIdentifier_s; … … 346 344 */ 347 345 template <class T> 348 void ClassIdentifier<T>::initialiseIdentifier() 349 { 350 // Get the name of the class 351 std::string name = typeid(T).name(); 352 353 // create a new identifier anyway. Will be deleted in Identifier::getIdentifier if not used. 346 /*static */ void ClassIdentifier<T>::initializeIdentifier() 347 { 348 // create a new identifier anyway. Will be deleted if not used. 354 349 ClassIdentifier<T>* proposal = new ClassIdentifier<T>(); 355 350 356 351 // Get the entry from the map 357 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getI dentifierSingleton(name,proposal);352 ClassIdentifier<T>::classIdentifier_s = (ClassIdentifier<T>*)IdentifierManager::getInstance().getGloballyUniqueIdentifier(proposal); 358 353 359 354 if (ClassIdentifier<T>::classIdentifier_s == proposal) 360 { 361 orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was not yet existing and got created." << endl; 362 } 355 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was not yet existing and got created." << endl; 363 356 else 364 357 { 365 orxout(verbose, context::identifier) << "Requested Identifier for " << name << " was already existing and got assigned." << endl; 358 orxout(verbose, context::identifier) << "Requested Identifier for " << proposal->getTypeidName() << " was already existing and got assigned." << endl; 359 delete proposal; // delete proposal (it is not used anymore) 366 360 } 367 361 } … … 370 364 @brief Adds an object of the given type to the ObjectList. 371 365 @param object The object to add 372 @param className The name of the class T 373 @param bRootClass True if this is a root class (i.e. it inherits directly from OrxonoxClass) 374 */ 375 template <class T> 376 bool ClassIdentifier<T>::initialiseObject(T* object, const std::string& className, bool bRootClass) 377 { 378 if (bRootClass) 379 orxout(verbose, context::object_list) << "Register Root-Object: " << className << endl; 380 else 381 orxout(verbose, context::object_list) << "Register Object: " << className << endl; 366 */ 367 template <class T> 368 bool ClassIdentifier<T>::initializeObject(T* object) 369 { 370 orxout(verbose, context::object_list) << "Register Object: " << this->getName() << endl; 382 371 383 372 object->identifier_ = this; 384 if (IdentifierManager:: isCreatingHierarchy())373 if (IdentifierManager::getInstance().isCreatingHierarchy()) 385 374 { 386 if (bRootClass && !object->parents_) 387 object->parents_ = new std::set<const Identifier*>(); 388 389 if (object->parents_) 390 { 391 this->initializeClassHierarchy(object->parents_, bRootClass); 392 object->parents_->insert(object->parents_->end(), this); 393 } 375 IdentifierManager::getInstance().createdObject(object); 394 376 395 377 this->setConfigValues(object, object); … … 425 407 */ 426 408 template <class T> 427 void ClassIdentifier<T>::addObjectToList(T* object, Listable* )428 { 429 orxout(verbose, context::object_list) << "Added object to " << this->getName() << "-list." << endl;430 object->metaList_->add(this->objects_, this->objects_->add(object));409 void ClassIdentifier<T>::addObjectToList(T* object, Listable* listable) 410 { 411 if (listable->getContext()) 412 listable->getContext()->addObject(object); 431 413 } 432 414 … … 442 424 template <class T> 443 425 void ClassIdentifier<T>::updateConfigValues(bool updateChildren) const 426 { 427 this->updateConfigValues(updateChildren, static_cast<T*>(NULL)); 428 } 429 430 template <class T> 431 void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Listable*) const 444 432 { 445 433 if (!this->hasConfigValues()) … … 452 440 for (std::set<const Identifier*>::const_iterator it = this->getChildrenBegin(); it != this->getChildrenEnd(); ++it) 453 441 (*it)->updateConfigValues(false); 442 } 443 444 template <class T> 445 void ClassIdentifier<T>::updateConfigValues(bool updateChildren, Identifiable*) const 446 { 447 // no action 454 448 } 455 449
Note: See TracChangeset
for help on using the changeset viewer.