- Timestamp:
- Jan 10, 2016, 1:54:11 PM (8 years ago)
- Location:
- code/branches/cpp11_v3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v3
- Property svn:mergeinfo changed
-
code/branches/cpp11_v3/src/libraries/core/object/StrongPtr.h
r10624 r11054 43 43 orxonox::StrongPtr is an implementation of a smart pointer - it wraps a pointer to an 44 44 object and keeps this object alive until no StrongPtr points to this object anymore. 45 In contrast to orxonox::SharedPtr, StrongPtr works only with classes that are derived45 In contrast to std::shared_ptr, StrongPtr works only with classes that are derived 46 46 from orxonox::Destroyable, because it's an intrusive implementation, meaning the 47 47 reference counter is stored in the object itself. … … 51 51 at any time and also convert it back to a normal pointer if you like. This is possible 52 52 because the reference counter is stored in the object itself and not in StrongPtr (in 53 contrast to SharedPtr).53 contrast to std::shared_ptr). 54 54 55 55 @b Important: If you want to delete an object, you must not use @c delete @c object but … … 138 138 public: 139 139 /// Constructor: Initializes the strong pointer with a null pointer. 140 inline StrongPtr() : pointer_( 0), base_(0)140 inline StrongPtr() : pointer_(nullptr), base_(nullptr) 141 141 { 142 142 } … … 158 158 /// Copy-constructor for strong pointers to objects of another class. 159 159 template <class O> 160 inline StrongPtr(const StrongPtr<O>& other) : pointer_(other.get()), base_(other. base_)160 inline StrongPtr(const StrongPtr<O>& other) : pointer_(other.get()), base_(other.getBase()) 161 161 { 162 162 if (this->base_) … … 172 172 } 173 173 174 /// Move-constructor 175 inline StrongPtr(StrongPtr&& other) : pointer_(other.pointer_), base_(other.base_) 176 { 177 other.pointer_ = nullptr; 178 other.base_ = nullptr; 179 } 180 174 181 /// Destructor: Decrements the reference counter. 175 182 inline ~StrongPtr() … … 187 194 188 195 /// Assigns the wrapped pointer of another StrongPtr. 189 inline StrongPtr& operator=( const StrongPtr&other)190 { 191 StrongPtr(other).swap(*this);196 inline StrongPtr& operator=(StrongPtr other) 197 { 198 other.swap(*this); 192 199 return *this; 193 200 } … … 230 237 inline T* operator->() const 231 238 { 232 assert(this->pointer_ != 0);239 assert(this->pointer_ != nullptr); 233 240 return this->pointer_; 234 241 } … … 237 244 inline T& operator*() const 238 245 { 239 assert(this->pointer_ != 0);246 assert(this->pointer_ != nullptr); 240 247 return *this->pointer_; 241 248 } 242 249 243 /// Returns true if the wrapped pointer is NULL.244 inline bool operator!() const245 { 246 return (this->pointer_ == 0);250 /// Returns true if the pointer is not nullptr. 251 inline explicit operator bool() const 252 { 253 return (this->pointer_ != nullptr); 247 254 } 248 255 … … 262 269 } 263 270 264 /// Resets the strong pointer (equivalent to assigning a NULL pointer).271 /// Resets the strong pointer (equivalent to assigning a nullptr). 265 272 inline void reset() 266 273 {
Note: See TracChangeset
for help on using the changeset viewer.