Free Electron
Public Member Functions | Private Attributes | Related Functions | List of all members
fe::hp< T > Class Template Reference

Safe handle for shared pointer. More...

#include <Handled.h>

Public Member Functions

 hp (const T *pT)
 
template<class X >
 hp (const X *pX)
 
 hp (const hp< T > &rhpT)
 
template<class X >
 hp (const sp< X > &rspX)
 
template<class X >
 hp (const hp< X > &rhpX)
 
void initialize (T *pObject)
 Initialize during Handled construction. More...
 
template<class X >
const hp< T > & operator= (const sp< X > &rspX)
 Converts from a smart pointer of any type. More...
 
template<class X >
const hp< T > & operator= (const X *pX)
 
hp< T > & operator= (const hp< T > &rhpT)
 
BWORD operator< (const hp< T > &rhpT) const
 
T * raw (void) const
 Returns the handled pointer, potentially NULL. More...
 
T * operator-> (void) const
 Use the handled pointer. More...
 
T & operator* (void) const
 Dereference to the handled pointer. More...
 
sp< T > object (void) const
 Returns a smart pointer of the same templated type. More...
 
BWORD isValid (void) const
 Returns true if the pointer is set. More...
 
BWORD isNull (void) const
 Returns true if the pointer is not set. More...
 
void invalidate (void)
 Nulls the shared pointer. More...
 
HandleToken * handleToken (void) const
 Access the shared token. More...
 

Private Attributes

sp< HandleToken > m_spHandleToken
 
T * m_pObject
 

Related Functions

(Note that these are not member functions.)

template<class T , class X >
BWORD operator== (const hp< T > &rhpLeft, const hp< X > &rhpRight)
 
template<class T , class X >
BWORD operator== (const hp< T > &rhpLeft, const sp< X > &rspRight)
 
template<class T , class X >
BWORD operator== (const sp< X > &rspLeft, const hp< T > &rhpRight)
 
template<class T >
BWORD operator!= (const hp< T > &rhpLeft, const hp< T > &rhpRight)
 
template<class T , class X >
BWORD operator!= (const hp< T > &rhpLeft, const sp< X > &rspRight)
 
template<class T , class X >
BWORD operator!= (const sp< X > &rspLeft, const hp< T > &rhpRight)
 

Detailed Description

template<class T>
class fe::hp< T >

Safe handle for shared pointer.

Unlike sp<>, the pointed to object can easily become invalid since the handle's existance doesn't prop up the object's existance. Unless there is another mechanism, such as a known sp<>, that is known to guarantee the object's persistence, it would be wise to judiciously verify currency with isValid().

A hp<> can be automatically cast to a sp<> (smart pointer).

A sp<> based on a Handled object can be automatically cast to a hp<>.

Member Function Documentation

◆ handleToken()

template<class T>
HandleToken* fe::hp< T >::handleToken ( void  ) const
inline

◆ initialize()

template<class T>
void fe::hp< T >::initialize ( T *  pObject)
inline

Initialize during Handled construction.

◆ invalidate()

template<class T>
void fe::hp< T >::invalidate ( void  )
inline

Nulls the shared pointer.

◆ isNull()

template<class T>
BWORD fe::hp< T >::isNull ( void  ) const
inline

Returns true if the pointer is not set.

◆ isValid()

template<class T>
BWORD fe::hp< T >::isValid ( void  ) const
inline

Returns true if the pointer is set.

Referenced by fe::Scope::initialize(), and fe::Component::registry().

◆ object()

template<class T>
sp<T> fe::hp< T >::object ( void  ) const
inline

Returns a smart pointer of the same templated type.

You usually don't need to use this method directly since sp<> can auto-convert.

◆ operator*()

template<class T>
T& fe::hp< T >::operator* ( void  ) const
inline

Dereference to the handled pointer.

◆ operator->()

template<class T>
T* fe::hp< T >::operator-> ( void  ) const
inline

Use the handled pointer.

◆ operator=()

template<class T>
template<class X >
const hp<T>& fe::hp< T >::operator= ( const sp< X > &  rspX)
inline

Converts from a smart pointer of any type.

If the object in the smart pointer does not have a method getHandle returning a hp<>, the conversion should fail to compile.

◆ raw()

template<class T>
T* fe::hp< T >::raw ( void  ) const
inline

Returns the handled pointer, potentially NULL.

Referenced by fe::hp< fe::ext::JobQueue< I32 > >::operator!=(), and fe::hp< fe::ext::JobQueue< I32 > >::operator==().

Friends And Related Function Documentation

◆ operator!=() [1/3]

template<class T >
BWORD operator!= ( const hp< T > &  rhpLeft,
const hp< T > &  rhpRight 
)
related

◆ operator!=() [2/3]

template<class T , class X >
BWORD operator!= ( const hp< T > &  rhpLeft,
const sp< X > &  rspRight 
)
related

◆ operator!=() [3/3]

template<class T , class X >
BWORD operator!= ( const sp< X > &  rspLeft,
const hp< T > &  rhpRight 
)
related

◆ operator==() [1/3]

template<class T , class X >
BWORD operator== ( const hp< T > &  rhpLeft,
const hp< X > &  rhpRight 
)
related

◆ operator==() [2/3]

template<class T , class X >
BWORD operator== ( const hp< T > &  rhpLeft,
const sp< X > &  rspRight 
)
related

◆ operator==() [3/3]

template<class T , class X >
BWORD operator== ( const sp< X > &  rspLeft,
const hp< T > &  rhpRight 
)
related

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