Changeset 7849 for code/trunk
- Timestamp:
- Feb 10, 2011, 9:52:23 PM (14 years ago)
- Location:
- code/trunk/src/libraries/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/CorePrereqs.h
r7284 r7849 138 138 class ConfigValueContainer; 139 139 class Core; 140 class DestructionListener; 140 141 class DynLib; 141 142 class DynLibManager; -
code/trunk/src/libraries/core/OrxonoxClass.cc
r7401 r7849 37 37 #include "MetaObjectList.h" 38 38 #include "Identifier.h" 39 #include "WeakPtr.h"40 39 41 40 namespace orxonox … … 56 55 57 56 /** 58 @brief Destructor: Removes the object from the object-lists, notifies all @ref WeakPtr "weak pointers"that this object is being deleted.57 @brief Destructor: Removes the object from the object-lists, notifies all DestructionListener (for example @ref WeakPtr "weak pointers") that this object is being deleted. 59 58 */ 60 59 OrxonoxClass::~OrxonoxClass() … … 71 70 delete this->parents_; 72 71 73 // reset all weak pointers pointing to this object74 for (std::set< WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); )72 // notify all destruction listeners 73 for (std::set<DestructionListener*>::iterator it = this->destructionListeners_.begin(); it != this->destructionListeners_.end(); ) 75 74 (*(it++))->objectDeleted(); 76 75 } -
code/trunk/src/libraries/core/OrxonoxClass.h
r7401 r7849 74 74 friend class SmartPtr; 75 75 76 template <class T> 77 friend class WeakPtr; 76 friend class DestructionListener; 78 77 79 78 public: … … 169 168 } 170 169 171 /// Register a weak pointer which points to this object. 172 template <class T> 173 inline void registerWeakPtr(WeakPtr<T>* pointer) 174 { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 175 /// Unegister a weak pointer which pointed to this object before. 176 template <class T> 177 inline void unregisterWeakPtr(WeakPtr<T>* pointer) 178 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 179 180 Identifier* identifier_; //!< The Identifier of the object 181 std::set<const Identifier*>* parents_; //!< List of all parents of the object 182 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 183 int referenceCount_; //!< Counts the references from smart pointers to this object 184 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 185 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 170 /// Register a destruction listener (for example a weak pointer which points to this object). 171 inline void registerDestructionListener(DestructionListener* pointer) 172 { this->destructionListeners_.insert(pointer); } 173 /// Unegister a destruction listener (for example a weak pointer which pointed to this object before). 174 inline void unregisterDestructionListener(DestructionListener* pointer) 175 { this->destructionListeners_.erase(pointer); } 176 177 Identifier* identifier_; //!< The Identifier of the object 178 std::set<const Identifier*>* parents_; //!< List of all parents of the object 179 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 180 int referenceCount_; //!< Counts the references from smart pointers to this object 181 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 182 std::set<DestructionListener*> destructionListeners_; //!< All destruction listeners (for example weak pointers which point to this object and like to get notified if it dies) 186 183 187 184 /// 'Fast map' that holds this-pointers of all derived types … … 189 186 }; 190 187 188 /** 189 @brief This listener is used to inform weak pointers if an object of type OrxonoxClass gets destroyed. 190 */ 191 class _CoreExport DestructionListener 192 { 193 friend class OrxonoxClass; 194 195 protected: 196 inline void registerAsDestructionListener(OrxonoxClass* object) 197 { object->registerDestructionListener(this); } 198 inline void unregisterAsDestructionListener(OrxonoxClass* object) 199 { object->unregisterDestructionListener(this); } 200 201 virtual void objectDeleted() = 0; 202 }; 203 191 204 SUPER_FUNCTION(11, OrxonoxClass, clone, false); 192 193 205 } 194 206 -
code/trunk/src/libraries/core/WeakPtr.h
r7401 r7849 96 96 */ 97 97 template <class T> 98 class WeakPtr 99 { 100 friend class OrxonoxClass; 101 98 class WeakPtr : public DestructionListener 99 { 102 100 public: 103 101 /// Constructor: Initializes the weak pointer with a null pointer. … … 115 113 { 116 114 if (this->base_) 117 this-> base_->registerWeakPtr(this);115 this->registerAsDestructionListener(this->base_); 118 116 } 119 117 … … 122 120 { 123 121 if (this->base_) 124 this-> base_->registerWeakPtr(this);122 this->registerAsDestructionListener(this->base_); 125 123 } 126 124 … … 130 128 { 131 129 if (this->base_) 132 this-> base_->registerWeakPtr(this);130 this->registerAsDestructionListener(this->base_); 133 131 } 134 132 … … 137 135 { 138 136 if (this->base_) 139 this-> base_->unregisterWeakPtr(this);137 this->unregisterAsDestructionListener(this->base_); 140 138 141 139 } … … 212 210 { 213 211 if (this->base_) 214 this-> base_->unregisterWeakPtr(this);212 this->unregisterAsDestructionListener(this->base_); 215 213 if (other.base_) 216 other. base_->unregisterWeakPtr(&other);214 other.unregisterAsDestructionListener(other.base_); 217 215 218 216 { … … 228 226 229 227 if (this->base_) 230 this-> base_->registerWeakPtr(this);228 this->registerAsDestructionListener(this->base_); 231 229 if (other.base_) 232 other. base_->registerWeakPtr(&other);230 other.registerAsDestructionListener(other.base_); 233 231 } 234 232
Note: See TracChangeset
for help on using the changeset viewer.