Shared pointer class. More...
#include <SharedPtr.h>
Public Member Functions | |
SharedPtr () | |
Create empty SharedPtr not pointing to anything. More... | |
SharedPtr (T *ptr) | |
Create new SharedPtr. More... | |
~SharedPtr () | |
Destructor. More... | |
SharedPtr (const SharedPtr &source) | |
Copy constructor. More... | |
SharedPtr | operator= (const SharedPtr &source) |
Assignment operator. More... | |
void | reset (T *ptr) |
Replaces the managed pointer with a new unmanaged pointer. More... | |
void | reset () |
Replace the managed pointer with a NULL pointer. More... | |
T * | get () const |
Raw pointer accessor. More... | |
uint32_t | use_count () const |
Reference count accessor. More... | |
T & | operator* () const |
Dereference object operator. More... | |
T * | operator-> () const |
Dereference object member operator. More... | |
operator bool () const | |
Boolean conversion operator. More... | |
Shared pointer class.
A shared pointer is a "smart" pointer that retains ownership of an object using reference counting across all smart pointers referencing that object.
It is similar to the std::shared_ptr class introduced in C++11; however, this is not a compatible implementation (no weak pointer, no make_shared, no custom deleters and so on.)
Usage: SharedPtr<Class> ptr(new Class())
When ptr is passed around by value, the copy constructor and destructor manages the reference count of the raw pointer. If the counter reaches zero, delete is called on the raw pointer.
To avoid loops, use "weak" references by calling the original pointer directly through ptr.get().
Definition at line 68 of file SharedPtr.h.
SharedPtr | ( | ) |
Create empty SharedPtr not pointing to anything.
Used for variable declaration.
Definition at line 74 of file SharedPtr.h.
SharedPtr | ( | T * | ptr | ) |
Create new SharedPtr.
ptr | Pointer to take control over |
Definition at line 82 of file SharedPtr.h.
~SharedPtr | ( | ) |
Destructor.
Decrement reference counter, and delete object if no longer pointed to.
Definition at line 95 of file SharedPtr.h.
Copy constructor.
Create new SharedPtr from other SharedPtr by copying pointer to original object and pointer to counter.
source | Object being copied from. |
Definition at line 106 of file SharedPtr.h.
T* get | ( | ) | const |
Raw pointer accessor.
Get raw pointer to object pointed to.
Definition at line 171 of file SharedPtr.h.
operator bool | ( | ) | const |
Boolean conversion operator.
Definition at line 211 of file SharedPtr.h.
T& operator* | ( | ) | const |
Dereference object operator.
Override to return the object pointed to.
Definition at line 193 of file SharedPtr.h.
T* operator-> | ( | ) | const |
Dereference object member operator.
Override to return return member in object pointed to.
Definition at line 202 of file SharedPtr.h.
Assignment operator.
Cleanup previous reference and assign new pointer and counter.
source | Object being assigned from. |
Definition at line 120 of file SharedPtr.h.
void reset | ( | T * | ptr | ) |
Replaces the managed pointer with a new unmanaged pointer.
[in] | ptr | the new raw pointer to manage. |
Definition at line 143 of file SharedPtr.h.
void reset | ( | void | ) |
Replace the managed pointer with a NULL pointer.
Definition at line 161 of file SharedPtr.h.
uint32_t use_count | ( | ) | const |