nux-0.9.46

nux::ObjectWeakPtr< T > Class Template Reference

A weak smart pointer class. Implemented as an intrusive smart pointer. More...

#include <NuxCore/ObjectPtr.h>

Public Member Functions

 ObjectWeakPtr ()
 Constructor.
 ObjectWeakPtr (T *ptr, bool WarnMissuse=false)
 Construction with a base pointer of type T.
template<typename O >
 ObjectWeakPtr (O *ptr, bool WarnMissuse=false)
 Construction with a base pointer of type O that inherits from type T.
 ObjectWeakPtr (const ObjectWeakPtr< T > &other)
 Copy constructor.
template<typename O >
 ObjectWeakPtr (const ObjectWeakPtr< O > &other)
 Copy constructor.
template<typename O >
 ObjectWeakPtr (const ObjectPtr< O > &other)
 Construction from a smart pointer of type O that inherits from type T.
ObjectWeakPtroperator= (const ObjectWeakPtr< T > &other)
 Assignment of a weak smart pointer of type T.
template<typename O >
ObjectWeakPtroperator= (const ObjectWeakPtr< O > &other)
 Assignment of a weak smart pointer of Type O that inherits from type T.
template<typename O >
ObjectWeakPtroperator= (const ObjectPtr< O > &other)
 Assignment of a smart pointer of Type T.
ObjectWeakPtroperator= (T *ptr)
 Construction with a base pointer of type T.
template<typename O >
ObjectWeakPtroperator= (O *ptr)
 Construction with a base pointer of type O that inherits from type T.
 ~ObjectWeakPtr ()
T & operator* () const
T * operator-> () const
bool operator< (T *ptr) const
bool operator> (T *ptr) const
bool operator< (ObjectWeakPtr< T > other) const
bool operator> (ObjectWeakPtr< T > other) const
bool operator!= (T *ptr) const
bool operator== (T *ptr) const
template<typename U >
bool operator!= (U *ptr) const
template<typename U >
bool operator== (U *ptr) const
template<typename U >
bool operator!= (const ObjectWeakPtr< U > &other) const
template<typename U >
bool operator== (const ObjectWeakPtr< U > &other) const
template<typename U >
bool operator!= (const ObjectPtr< U > &other) const
template<typename U >
bool operator== (const ObjectPtr< U > &other) const
bool operator() () const
 Return true is the hosted pointer is not null or has not been destroyed.
bool IsValid () const
 Return true is the hosted pointer is not null or has not been destroyed.
bool IsNull () const
 Return true is the hosted pointer is null or has been destroyed.
bool Release ()
 Release the hosted pointer from this object.
const T * GetPointer () const
 Return the stored pointer.
T * GetPointer ()
 Return the stored pointer.
int GetReferenceCount ()
int GetWeakReferenceCount ()

Friends

class ObjectWeakPtr
class SmartPtr
template<typename U >
bool operator== (U *, const ObjectWeakPtr< U > &a)
template<typename U >
bool operator!= (U *, const ObjectWeakPtr< U > &a)
template<typename U , typename F >
ObjectWeakPtr< U > staticCast (const ObjectWeakPtr< F > &from)
template<typename U , typename F >
ObjectWeakPtr< U > constCast (const ObjectWeakPtr< F > &from)
template<typename U , typename F >
ObjectWeakPtr< U > dynamicCast (const ObjectWeakPtr< F > &from)
template<typename U , typename F >
ObjectWeakPtr< U > checkedCast (const ObjectWeakPtr< F > &from)
template<typename U , typename F >
ObjectWeakPtr< U > queryCast (const ObjectWeakPtr< F > &from)

Detailed Description

template<typename T>
class nux::ObjectWeakPtr< T >

A weak smart pointer class. Implemented as an intrusive smart pointer.

A weak smart pointer is built from a smart pointer or another weak smart pointer. It increments and decrements the total reference count of an pointer. Even is the original pointer is destroyed, weak smart pointers still point to the RefCounts pointers of the original pointer and can use it to check if the pointer is still valid or not.


Constructor & Destructor Documentation

template<typename T>
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( ) [inline]

Constructor.

template<typename T>
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( T *  ptr,
bool  WarnMissuse = false 
) [inline, explicit]

Construction with a base pointer of type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr.
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( O *  ptr,
bool  WarnMissuse = false 
) [inline, explicit]

Construction with a base pointer of type O that inherits from type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr.
template<typename T>
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( const ObjectWeakPtr< T > &  other) [inline]

Copy constructor.

Parameters:
otherParameter with type T.
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( const ObjectWeakPtr< O > &  other) [inline]

Copy constructor.

Parameters:
otherParameter with a type derived from T.
template<typename T>
template<typename O >
nux::ObjectWeakPtr< T >::ObjectWeakPtr ( const ObjectPtr< O > &  other) [inline]

Construction from a smart pointer of type O that inherits from type T.

Parameters:
otherMaintains a weak smart pointer reference to this parameter.
template<typename T>
nux::ObjectWeakPtr< T >::~ObjectWeakPtr ( ) [inline]

Member Function Documentation

template<typename T>
T* nux::ObjectWeakPtr< T >::GetPointer ( ) [inline]

Return the stored pointer.

Caller of this function should Reference the pointer if they intend to keep it.

Parameters:
Returnthe stored pointer.
template<typename T>
int nux::ObjectWeakPtr< T >::GetReferenceCount ( ) [inline]
template<typename T>
int nux::ObjectWeakPtr< T >::GetWeakReferenceCount ( ) [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::IsNull ( ) const [inline]

Return true is the hosted pointer is null or has been destroyed.

Returns:
True if the internal pointer is null or has been destroyed.
template<typename T>
bool nux::ObjectWeakPtr< T >::IsValid ( ) const [inline]

Return true is the hosted pointer is not null or has not been destroyed.

Returns:
True if the internal pointer is not null or has not been destroyed.
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator!= ( const ObjectPtr< U > &  other) const [inline]

An object pointer

Returns:
True is this weak pointer host a different pointer as the object pointer passed as parameter.
template<typename T>
bool nux::ObjectWeakPtr< T >::operator!= ( T *  ptr) const [inline]
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator!= ( const ObjectWeakPtr< U > &  other) const [inline]

A weak pointer

Returns:
True is this weak pointer host a different pointer as the weak pointer passed as parameter.
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator!= ( U *  ptr) const [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::operator() ( ) const [inline]

Return true is the hosted pointer is not null or has not been destroyed.

Returns:
True if the internal pointer is not null.
template<typename T>
T& nux::ObjectWeakPtr< T >::operator* ( void  ) const [inline]
template<typename T>
T* nux::ObjectWeakPtr< T >::operator-> ( ) const [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::operator< ( T *  ptr) const [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::operator< ( ObjectWeakPtr< T >  other) const [inline]
template<typename T>
template<typename O >
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( const ObjectWeakPtr< O > &  other) [inline]

Assignment of a weak smart pointer of Type O that inherits from type T.

Parameters:
otherWeak smart pointer of type O.
template<typename T>
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( T *  ptr) [inline]

Construction with a base pointer of type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr.
template<typename T>
template<typename O >
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( O *  ptr) [inline]

Construction with a base pointer of type O that inherits from type T.

Parameters:
ptrStart maintaining a reference count of the passed pointer.
WarnMissuseIf True, then ObjectPtr test is ptr is owned or not. If ptr is not owned and WarnMissuse is True, then Print a warning message. This is a debug feature to detect cases such as "ObjectPtr(ObjectA) myobject(ptr);", because the calling code will no longer have a reference on ptr.
template<typename T>
template<typename O >
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( const ObjectPtr< O > &  other) [inline]

Assignment of a smart pointer of Type T.

Parameters:
otherMaintains a smart pointer reference to this parameter. Assignment of a smart pointer of Type O that inherits from type T.
otherMaintains a weak smart pointer reference to this parameter.
template<typename T>
ObjectWeakPtr& nux::ObjectWeakPtr< T >::operator= ( const ObjectWeakPtr< T > &  other) [inline]

Assignment of a weak smart pointer of type T.

Parameters:
otherWeak smart pointer of type T.
template<typename T>
bool nux::ObjectWeakPtr< T >::operator== ( T *  ptr) const [inline]
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator== ( const ObjectPtr< U > &  other) const [inline]

An object pointer

Returns:
True is this weak pointer host the same pointer as the object pointer passed as parameter.
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator== ( U *  ptr) const [inline]
template<typename T>
template<typename U >
bool nux::ObjectWeakPtr< T >::operator== ( const ObjectWeakPtr< U > &  other) const [inline]

A weak pointer

Returns:
True is this weak pointer host the same pointer as the weak pointer passed as parameter.
template<typename T>
bool nux::ObjectWeakPtr< T >::operator> ( ObjectWeakPtr< T >  other) const [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::operator> ( T *  ptr) const [inline]
template<typename T>
bool nux::ObjectWeakPtr< T >::Release ( ) [inline]

Release the hosted pointer from this object.

Release the hosted pointer from this object. After this call, the following members are null: _reference_count _weak_reference_count ptr_ This call decreases the count of weak reference before setting _weak_reference_count to null.

Returns:
True this was the last weak reference on the hosted object.

Friends And Related Function Documentation

template<typename T>
template<typename U , typename F >
ObjectWeakPtr<U> checkedCast ( const ObjectWeakPtr< F > &  from) [friend]
template<typename T>
template<typename U , typename F >
ObjectWeakPtr<U> constCast ( const ObjectWeakPtr< F > &  from) [friend]
template<typename T>
template<typename U , typename F >
ObjectWeakPtr<U> dynamicCast ( const ObjectWeakPtr< F > &  from) [friend]
template<typename T>
friend class ObjectWeakPtr [friend]
template<typename T>
template<typename U >
bool operator!= ( U *  ,
const ObjectWeakPtr< U > &  a 
) [friend]
template<typename T>
template<typename U >
bool operator== ( U *  ,
const ObjectWeakPtr< U > &  a 
) [friend]
template<typename T>
template<typename U , typename F >
ObjectWeakPtr<U> queryCast ( const ObjectWeakPtr< F > &  from) [friend]
template<typename T>
friend class SmartPtr [friend]
template<typename T>
template<typename U , typename F >
ObjectWeakPtr<U> staticCast ( const ObjectWeakPtr< F > &  from) [friend]

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