Changeset 5824
- Timestamp:
- Sep 28, 2009, 5:50:31 PM (15 years ago)
- Location:
- code/branches/core5/src/libraries/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/OrxonoxClass.cc
r5823 r5824 66 66 // reset all weak pointers pointing to this object 67 67 for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); ) 68 (*(it++))-> reset();68 (*(it++))->objectDeleted(); 69 69 } 70 70 -
code/branches/core5/src/libraries/core/WeakPtr.h
r5823 r5824 36 36 #include <cassert> 37 37 #include "OrxonoxClass.h" 38 #include "Functor.h" 38 39 39 40 namespace orxonox … … 42 43 class WeakPtr 43 44 { 45 friend class OrxonoxClass; 46 44 47 public: 45 inline WeakPtr() : pointer_(0), base_(0) 46 { 47 } 48 49 inline WeakPtr(int) : pointer_(0), base_(0) 50 { 51 } 52 53 inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer) 48 inline WeakPtr() : pointer_(0), base_(0), callback_(0) 49 { 50 } 51 52 inline WeakPtr(int) : pointer_(0), base_(0), callback_(0) 53 { 54 } 55 56 inline WeakPtr(T* pointer) : pointer_(pointer), base_(pointer), callback_(0) 54 57 { 55 58 if (this->base_) … … 57 60 } 58 61 59 inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_) 62 inline WeakPtr(const WeakPtr& other) : pointer_(other.pointer_), base_(other.base_), callback_(0) 60 63 { 61 64 if (this->base_) … … 64 67 65 68 template <class O> 66 inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_) 69 inline WeakPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.base_), callback_(0) 67 70 { 68 71 if (this->base_) … … 74 77 if (this->base_) 75 78 this->base_->unregisterWeakPtr(this); 79 if (this->callback_) 80 delete this->callback_; 81 76 82 } 77 83 … … 151 157 WeakPtr().swap(*this); 152 158 } 159 160 inline void addCallback(Functor* callback) 161 { 162 this->callback_ = callback; 163 } 164 165 inline Functor* getFunctor() const 166 { 167 return this->callback_; 168 } 153 169 154 170 private: 171 inline void objectDeleted() 172 { 173 this->reset(); 174 if (this->callback_) 175 (*this->callback_)(); 176 } 177 155 178 T* pointer_; 156 179 OrxonoxClass* base_; 180 Functor* callback_; 157 181 }; 158 182
Note: See TracChangeset
for help on using the changeset viewer.