SharedPtr is an intrusive refcount-tracked single-object lifetime-manager. More...
#include <SharedPtr.h>
Public Member Functions | |
| SharedPtr () | |
| Constructs a zero pointer. | |
| SharedPtr (T *ptr) | |
| Constructs from a raw pointer. | |
| SharedPtr (const SharedPtr< T > &rhs) | |
| Constructs from an existing SharedPtr. | |
| template<typename T2 > | |
| SharedPtr (const SharedPtr< T2 > &rhs) | |
| Template copy constructor for types that allow conversions to other types. | |
| SharedPtr< T > & | operator= (const SharedPtr< T > &rhs) |
| Assignment from another SharedPtr. | |
| SharedPtr< T > & | operator= (T *ptr) |
| Assignment from a raw ptr. | |
| ~SharedPtr () | |
| Decreases refCount on the object and frees it if it's no longer used. | |
| unsigned int | RefCount () const |
| Returns the reference count of the currently held object. | |
| const T * | ptr () const |
| Const access to the pointer. | |
| const T * | operator-> () const |
| Const dereference and access object. | |
| const T & | operator* () const |
| Const dereference object. | |
| operator T * () | |
| Implicit conversion to a raw pointer. | |
| T * | ptr () |
| Returns a pointer to the object or 0 if empty. | |
| T * | operator-> () |
| Dereference and access object. | |
| T & | operator* () |
| Dereference object. | |
| operator bool () const | |
| Test if pointer is good. | |
| operator bool () | |
| Test if pointer is good. | |
SharedPtr is an intrusive refcount-tracked single-object lifetime-manager.
SharedPtr wraps raw pointers to objects and manages reference counting on the number of users on the pointer. When all users abandon the object, FreeFunc::free(T*) is called to clean up the memory used by the resource.
| kNet::SharedPtr< T >::SharedPtr | ( | T * | ptr_ | ) |
Constructs from a raw pointer.
This constructor takes the ownership of the raw pointer and starts managing the reference count on it, assuming that it is the first pointer to access it.
Thus, when invoking this constructor you need to be sure that the passed pointer is not being reference-counted someplace else, because the reference count is stored in the referencing smart pointers rather than the object itself.
| ptr_ | Raw pointer to an object that is not being refCounted anywhere else. |
| kNet::SharedPtr< T >::SharedPtr | ( | const SharedPtr< T > & | rhs | ) |
| kNet::SharedPtr< T >::SharedPtr | ( | const SharedPtr< T2 > & | rhs | ) |
Template copy constructor for types that allow conversions to other types.
This constructor allows to convert SharedPtr's from Derived types to SharedPtr's of Base types, or more specifically, from any type A to type B, as long as there is an implicit conversion operator available for the specified types.
| rhs | The pointer to make copy of. |
| kNet::SharedPtr< T >::~SharedPtr | ( | ) |
Decreases refCount on the object and frees it if it's no longer used.
| SharedPtr< T > & kNet::SharedPtr< T >::operator= | ( | const SharedPtr< T > & | rhs | ) |
Assignment from another SharedPtr.
Decreases refCount on old object and modifies this to point to the new object, increasing it's refCount.
| rhs | The pointer to make copy of. |
| SharedPtr< T > & kNet::SharedPtr< T >::operator= | ( | T * | ptr_ | ) |
Assignment from a raw ptr.
Decreases refCount on old object (possibly frees it) and takes the ownership of the new object, making the assumption that this is the first SharedPtr to count reference to the object.
| ptr_ | Raw pointer to an object that is not being refCounted anywhere else. |
| unsigned int kNet::SharedPtr< T >::RefCount | ( | ) | const |
| const T * kNet::SharedPtr< T >::ptr | ( | ) | const |
Const access to the pointer.
Referenced by kNet::operator==().
| const T * kNet::SharedPtr< T >::operator-> | ( | ) | const |
Const dereference and access object.
Causes an assert failure if the pointer is null.
| const T & kNet::SharedPtr< T >::operator* | ( | ) | const |
Const dereference object.
Causes an assert failure if the pointer is null.
| kNet::SharedPtr< T >::operator T * | ( | ) |
Implicit conversion to a raw pointer.
Causes an assert failure if the pointer is null.
If reading a null pointer should be considered a legal operation, use .ptr() instead.
| T * kNet::SharedPtr< T >::ptr | ( | ) |
Returns a pointer to the object or 0 if empty.
| T * kNet::SharedPtr< T >::operator-> | ( | ) |
Dereference and access object.
Causes an assert failure if the pointer is null.
| T & kNet::SharedPtr< T >::operator* | ( | ) |
Dereference object.
Causes an assert failure if the pointer is null.
| kNet::SharedPtr< T >::operator bool | ( | ) | const |
Test if pointer is good.
| kNet::SharedPtr< T >::operator bool | ( | ) |
Test if pointer is good.
1.7.1