- Timestamp:
- Sep 28, 2009, 5:16:36 PM (15 years ago)
- Location:
- code/branches/core5/src/libraries/core
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/OrxonoxClass.cc
r5805 r5823 36 36 #include "MetaObjectList.h" 37 37 #include "Identifier.h" 38 #include "WeakPtr.h" 38 39 39 40 namespace orxonox … … 62 63 if (this->parents_) 63 64 delete this->parents_; 65 66 // reset all weak pointers pointing to this object 67 for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); ) 68 (*(it++))->reset(); 64 69 } 65 70 -
code/branches/core5/src/libraries/core/OrxonoxClass.h
r5805 r5823 57 57 template <class T> 58 58 friend class SmartPtr; 59 60 template <class T> 61 friend class WeakPtr; 59 62 60 63 public: … … 131 134 inline void decrementReferenceCount() 132 135 { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } } 136 137 /** @brief Register a weak pointer which points to this object. */ 138 template <class T> 139 inline void registerWeakPtr(WeakPtr<T>* pointer) 140 { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 141 /** @brief Unegister a weak pointer which pointed to this object before. */ 142 template <class T> 143 inline void unregisterWeakPtr(WeakPtr<T>* pointer) 144 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 133 145 134 146 Identifier* identifier_; //!< The Identifier of the object … … 137 149 int referenceCount_; //!< Counts the references from smart pointers to this object 138 150 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 151 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 139 152 140 153 //! 'Fast map' that holds this-pointers of all derived types -
code/branches/core5/src/libraries/core/SmartPtr.h
r5807 r5823 35 35 36 36 #include <cassert> 37 #include <ostream> 37 38 38 #include "OrxonoxClass.h" 39 #include "WeakPtr.h" 39 40 40 41 namespace orxonox … … 71 72 } 72 73 74 template <class O> 75 inline SmartPtr(const WeakPtr<O>& other) : pointer_(other.get()), base_(other.getBase()) 76 { 77 if (this->base_) 78 this->base_->incrementReferenceCount(); 79 } 80 73 81 inline ~SmartPtr() 74 82 { … … 102 110 } 103 111 112 template <class O> 113 inline const SmartPtr& operator=(const WeakPtr<O>& other) 114 { 115 SmartPtr(other).swap(*this); 116 return *this; 117 } 118 104 119 inline T* get() const 105 120 { 106 121 return this->pointer_; 122 } 123 124 inline OrxonoxClass* getBase() const 125 { 126 return this->base_; 107 127 } 108 128 … … 153 173 }; 154 174 155 template <class A, class B>156 inline bool operator==(const SmartPtr<A>& a, const SmartPtr<B>& b)157 {158 return (a.get() == b.get());159 }160 161 template <class A, class B>162 inline bool operator!=(const SmartPtr<A>& a, const SmartPtr<B>& b)163 {164 return (a.get() != b.get());165 }166 167 template <class T>168 inline bool operator<(const SmartPtr<T>& a, const SmartPtr<T>& b)169 {170 return std::less<T*>()(a.get(), b.get());171 }172 173 175 template <class T> 174 176 void swap(SmartPtr<T>& a, SmartPtr<T>& b) … … 194 196 return dynamic_cast<T*>(p.get()); 195 197 } 196 197 template <class T>198 std::ostream& operator<<(std::ostream& os, const SmartPtr<T>& p)199 {200 os << p.get();201 return os;202 }203 198 } 204 199
Note: See TracChangeset
for help on using the changeset viewer.