Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize > Class Template Reference

#include <LeapUtil.h>

Classes

struct  ManagedPointerEntry
 
struct  ManagedPointerPool
 

Public Types

enum  { kManagedPointerPoolSize = ManagedPointerPoolSize }
 
typedef T ManagedType
 

Public Member Functions

ManagedTypeGetPointer () const
 
uint32_t GetRefCount () const
 how many references are there to this managed pointer? More...
 
 operator bool () const
 boolean and comparison operator overloads More...
 
 operator ManagedType * () const
 operators for easy implicit assignment to raw pointer type or direct use of the object pointer More...
 
bool operator! () const
 
bool operator!= (const ManagedType *pPointer) const
 
bool operator!= (const SmartPointer &rhs) const
 
ManagedTypeoperator-> () const
 
const SmartPointeroperator= (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. More...
 
 SmartPointer (ManagedType *pManaged)
 
 SmartPointer (const SmartPointer &rhs)
 copy constructor. increases reference count for shared managed pointer entry More...
 
 ~SmartPointer ()
 destructor decreases reference count for managed pointer entry. More...
 

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. More...
 
static const SmartPointerNull ()
 convenient static method for returning in cases where a null return value is needed. More...
 

Private Member Functions

void refDec ()
 
void refInc ()
 increment the reference count on our shared managed pointer entry (if any) More...
 

Static Private Member Functions

static ManagedPointerPools_pool ()
 

Private Attributes

ManagedPointerEntrym_pManagedPointer
 

Detailed Description

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
class LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >

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.

Member Typedef Documentation

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
typedef T LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::ManagedType

Definition at line 632 of file LeapUtil.h.

Member Enumeration Documentation

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
anonymous enum
Enumerator
kManagedPointerPoolSize 

Definition at line 630 of file LeapUtil.h.

Constructor & Destructor Documentation

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::SmartPointer ( )
inline

default constructor - equivalent of a NULL pointer.

Definition at line 806 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::SmartPointer ( ManagedType pManaged)
inlineexplicit

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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::~SmartPointer ( )
inline

destructor decreases reference count for managed pointer entry.

Definition at line 843 of file LeapUtil.h.

Member Function Documentation

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
static uint32_t LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::GetNumManagedPointers ( )
inlinestatic

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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
static bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::IsManaged ( const ManagedType pPointer)
inlinestatic

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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
static const SmartPointer& LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::Null ( )
inlinestatic

convenient static method for returning in cases where a null return value is needed.

Definition at line 882 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator bool ( ) const
inline

boolean and comparison operator overloads

Definition at line 861 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator! ( ) const
inline

Definition at line 863 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator!= ( const ManagedType pPointer) const
inline

Definition at line 867 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator!= ( const SmartPointer< T, Destructor, ManagedPointerPoolSize > &  rhs) const
inline

Definition at line 871 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
ManagedType* LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator-> ( ) const
inline

Definition at line 858 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator== ( const ManagedType pPointer) const
inline

Definition at line 865 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
bool LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::operator== ( const SmartPointer< T, Destructor, ManagedPointerPoolSize > &  rhs) const
inline

Definition at line 869 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
void LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::refDec ( )
inlineprivate

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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
void LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::refInc ( )
inlineprivate

increment the reference count on our shared managed pointer entry (if any)

Definition at line 774 of file LeapUtil.h.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
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.

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
static ManagedPointerPool& LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::s_pool ( )
inlinestaticprivate

Definition at line 767 of file LeapUtil.h.

Member Data Documentation

template<typename T, class Destructor = SmartInstanceDestructor<T>, unsigned int ManagedPointerPoolSize = 512>
ManagedPointerEntry* LeapUtil::SmartPointer< T, Destructor, ManagedPointerPoolSize >::m_pManagedPointer
private

Definition at line 899 of file LeapUtil.h.


The documentation for this class was generated from the following file:


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Tue Jun 2 2020 03:58:01