Changeset 9570 for code/branches/core6/src/libraries/core/class
- Timestamp:
- Mar 24, 2013, 8:51:37 PM (12 years ago)
- Location:
- code/branches/core6/src/libraries/core/class
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core6/src/libraries/core/class/Identifiable.h
r9565 r9570 57 57 virtual ~Identifiable(); 58 58 59 void destroy();60 59 void unregisterObject(); 61 60 -
code/branches/core6/src/libraries/core/class/OrxonoxClass.cc
r9565 r9570 35 35 36 36 #include <cassert> 37 #include "core/object/MetaObjectList.h"38 #include "core/object/Context.h"39 #include "Identifier.h"40 37 41 38 namespace orxonox … … 46 43 OrxonoxClass::OrxonoxClass() 47 44 { 48 this->referenceCount_ = 0;49 this->requestedDestruction_ = false;50 45 } 51 46 … … 55 50 OrxonoxClass::~OrxonoxClass() 56 51 { 57 assert(this->referenceCount_ <= 0);58 59 // notify all destruction listeners60 for (std::set<DestructionListener*>::iterator it = this->destructionListeners_.begin(); it != this->destructionListeners_.end(); )61 (*(it++))->objectDeleted();62 }63 64 /**65 @brief Deletes the object if no @ref orxonox::SmartPtr "smart pointers" point to this object. Otherwise schedules the object to be deleted as soon as possible.66 */67 void OrxonoxClass::destroy()68 {69 assert(this); // Just in case someone tries to delete a NULL pointer70 this->requestedDestruction_ = true;71 if (this->referenceCount_ == 0)72 {73 this->preDestroy();74 if (this->referenceCount_ == 0)75 delete this;76 }77 52 } 78 53 } -
code/branches/core6/src/libraries/core/class/OrxonoxClass.h
r9565 r9570 43 43 #include "core/CorePrereqs.h" 44 44 45 #include <set>46 //#include "Super.h"47 45 #include "Identifiable.h" 46 #include "core/object/Destroyable.h" 48 47 49 48 namespace orxonox … … 54 53 The BaseObject and Interfaces are derived with @c virtual @c public @c OrxonoxClass from OrxonoxClass. 55 54 */ 56 class _CoreExport OrxonoxClass : public Identifiable 55 class _CoreExport OrxonoxClass : public Identifiable, public Destroyable 57 56 { 58 template <class T>59 friend class SmartPtr;60 61 friend class DestructionListener;62 63 57 public: 64 58 OrxonoxClass(); 65 59 virtual ~OrxonoxClass(); 66 60 67 void destroy();68 69 61 /// Function to collect the SetConfigValue-macro calls. 70 62 void setConfigValues() {}; 71 72 /// Returns the number of @ref orxonox::SmartPtr "smart pointers" that point to this object.73 inline unsigned int getReferenceCount() const74 { return this->referenceCount_; }75 76 protected:77 /// This virtual function is called if destroy() is called and no SmartPtr points to this object. Used in some cases to create a new SmartPtr to prevent destruction.78 virtual void preDestroy() {}79 80 private:81 /// Increments the reference counter (for smart pointers).82 inline void incrementReferenceCount()83 { ++this->referenceCount_; }84 /// Decrements the reference counter (for smart pointers).85 inline void decrementReferenceCount()86 {87 --this->referenceCount_;88 if (this->referenceCount_ == 0 && this->requestedDestruction_)89 this->destroy();90 }91 92 /// Register a destruction listener (for example a weak pointer which points to this object).93 inline void registerDestructionListener(DestructionListener* pointer)94 { this->destructionListeners_.insert(pointer); }95 /// Unegister a destruction listener (for example a weak pointer which pointed to this object before).96 inline void unregisterDestructionListener(DestructionListener* pointer)97 { this->destructionListeners_.erase(pointer); }98 99 int referenceCount_; //!< Counts the references from smart pointers to this object100 bool requestedDestruction_; //!< Becomes true after someone called delete on this object101 std::set<DestructionListener*> destructionListeners_; //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies)102 63 }; 103 104 /**105 @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed.106 */107 class _CoreExport DestructionListener108 {109 friend class OrxonoxClass;110 111 protected:112 virtual ~DestructionListener() {}113 114 inline void registerAsDestructionListener(OrxonoxClass* object)115 { if (object) { object->registerDestructionListener(this); } }116 inline void unregisterAsDestructionListener(OrxonoxClass* object)117 { if (object) { object->unregisterDestructionListener(this); } }118 119 virtual void objectDeleted() = 0;120 };121 122 64 } 123 65
Note: See TracChangeset
for help on using the changeset viewer.