#include <LeapUtil.h>
Classes | |
struct | ManagedPointerEntry |
struct | ManagedPointerPool |
Public Types | |
enum | { kManagedPointerPoolSize = ManagedPointerPoolSize } |
typedef T | ManagedType |
Public Member Functions | |
ManagedType * | GetPointer () const |
uint32_t | GetRefCount () const |
how many references are there to this managed pointer? | |
operator bool () const | |
boolean and comparison operator overloads | |
operator ManagedType * () const | |
operators for easy implicit assignment to raw pointer type or direct use of the object pointer | |
bool | operator! () const |
bool | operator!= (const ManagedType *pPointer) const |
bool | operator!= (const SmartPointer &rhs) const |
ManagedType * | operator-> () const |
const SmartPointer & | operator= (const SmartPointer &rhs) |
bool | operator== (const ManagedType *pPointer) const |
bool | operator== (const SmartPointer &rhs) const |
void | Release () |
SmartPointer () | |
default constructor - equivalent of a NULL pointer. | |
SmartPointer (ManagedType *pManaged) | |
SmartPointer (const SmartPointer &rhs) | |
copy constructor. increases reference count for shared managed pointer entry | |
~SmartPointer () | |
destructor decreases reference count for managed pointer entry. | |
Static Public Member Functions | |
static uint32_t | GetNumManagedPointers () |
static bool | IsManaged (const ManagedType *pPointer) |
returns true if the given raw pointer is managed by a smart pointer somewhere, false if not. | |
static const SmartPointer & | Null () |
convenient static method for returning in cases where a null return value is needed. | |
Private Member Functions | |
void | refDec () |
void | refInc () |
increment the reference count on our shared managed pointer entry (if any) | |
Static Private Member Functions | |
static ManagedPointerPool & | s_pool () |
Private Attributes | |
ManagedPointerEntry * | m_pManagedPointer |
smart pointer template class. maintains reference count that is incremented for each new instance of a smart pointer that refers to the same raw pointer and decremented each time a reference is released. a reference is released when a smart pointer goes out of scope OR has another value assigned to it OR .Release() is called explicitly. when the reference count reaches zero the Destructor::Destroy static method is invoked on the raw pointer. note: this smart pointer class is not thread-safe. making it thread safe would have required adding a cross-platform mutex class. the use cases in the sample code do not require it.
Definition at line 627 of file LeapUtil.h.
typedef T LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::ManagedType |
Definition at line 632 of file LeapUtil.h.
anonymous enum |
Definition at line 630 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::SmartPointer | ( | ) | [inline] |
default constructor - equivalent of a NULL pointer.
Definition at line 806 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::SmartPointer | ( | ManagedType * | pManaged | ) | [inline, explicit] |
construction of a smart pointer from a raw pointer is not implicit - they should be created once at the beginning of an object's life and passed around/dereferenced. creating a new smart pointer from a raw pointer should not happen unintentionally. assignment operator for raw pointer type does not exist for the same reason that the raw pointer constructor is explicit. creation of a smart pointer from a raw pointer should be deliberate.
Definition at line 816 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::SmartPointer | ( | const SmartPointer< T, Destructor, ManagedPointerPoolSize > & | rhs | ) | [inline] |
copy constructor. increases reference count for shared managed pointer entry
Definition at line 822 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::~SmartPointer | ( | ) | [inline] |
destructor decreases reference count for managed pointer entry.
Definition at line 843 of file LeapUtil.h.
static uint32_t LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::GetNumManagedPointers | ( | ) | [inline, static] |
returns the number of raw pointers of this type under management. use SmartPointer::kManagedPointerPoolSize to get the total number of pointers of this type that can be managed.
Definition at line 896 of file LeapUtil.h.
ManagedType* LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::GetPointer | ( | ) | const [inline] |
explicit access to the managed pointer. usually the overloaded cast and -> operators are sufficient but it is sometimes useful to have a named method to call.
Definition at line 850 of file LeapUtil.h.
uint32_t LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::GetRefCount | ( | ) | const [inline] |
how many references are there to this managed pointer?
Definition at line 853 of file LeapUtil.h.
static bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::IsManaged | ( | const ManagedType * | pPointer | ) | [inline, static] |
returns true if the given raw pointer is managed by a smart pointer somewhere, false if not.
Definition at line 889 of file LeapUtil.h.
static const SmartPointer& LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::Null | ( | ) | [inline, static] |
convenient static method for returning in cases where a null return value is needed.
Definition at line 882 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator bool | ( | ) | const [inline] |
boolean and comparison operator overloads
Definition at line 861 of file LeapUtil.h.
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator ManagedType * | ( | ) | const [inline] |
operators for easy implicit assignment to raw pointer type or direct use of the object pointer
Definition at line 856 of file LeapUtil.h.
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator! | ( | ) | const [inline] |
Definition at line 863 of file LeapUtil.h.
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator!= | ( | const ManagedType * | pPointer | ) | const [inline] |
Definition at line 867 of file LeapUtil.h.
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator!= | ( | const SmartPointer< T, Destructor, ManagedPointerPoolSize > & | rhs | ) | const [inline] |
Definition at line 871 of file LeapUtil.h.
ManagedType* LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator-> | ( | ) | const [inline] |
Definition at line 858 of file LeapUtil.h.
const SmartPointer& LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator= | ( | const SmartPointer< T, Destructor, ManagedPointerPoolSize > & | rhs | ) | [inline] |
assignment operator overload for smart pointer to smart pointer. releases old managed entry and increases reference count for new one.
Definition at line 830 of file LeapUtil.h.
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator== | ( | const ManagedType * | pPointer | ) | const [inline] |
Definition at line 865 of file LeapUtil.h.
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator== | ( | const SmartPointer< T, Destructor, ManagedPointerPoolSize > & | rhs | ) | const [inline] |
Definition at line 869 of file LeapUtil.h.
void LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::refDec | ( | ) | [inline, private] |
decrement the reference count on our shared managed pointer entry (if any) if the reference count hits 0 the raw pointer is passed to Destructor::Destroy and the managed pointer entry is returned to the pool.
Definition at line 785 of file LeapUtil.h.
void LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::refInc | ( | ) | [inline, private] |
increment the reference count on our shared managed pointer entry (if any)
Definition at line 774 of file LeapUtil.h.
void LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::Release | ( | ) | [inline] |
calling Release is an alternative to assigning SmartPointer::Null(). refDec() is called in the destructor of the smart pointer - it is not necessary to call Release() in the destructor of a class containing a smart pointer.
Definition at line 876 of file LeapUtil.h.
static ManagedPointerPool& LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::s_pool | ( | ) | [inline, static, private] |
Definition at line 767 of file LeapUtil.h.
ManagedPointerEntry* LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::m_pManagedPointer [private] |
Definition at line 899 of file LeapUtil.h.