Open CASCADE Technology  7.6.0
Public Types | Public Member Functions | Static Public Member Functions

opencascade::handle< T > Class Template Reference

Intrusive smart pointer for use with Standard_Transient class and its descendants. More...

#include <Standard_Handle.hxx>

Public Types

typedef T element_type
 STL-compliant typedef of contained type. More...
 

Public Member Functions

 handle ()
 Empty constructor. More...
 
 handle (const T *thePtr)
 Constructor from pointer to new object. More...
 
 handle (const handle &theHandle)
 Copy constructor. More...
 
 handle (handle &&theHandle)
 Move constructor. More...
 
 ~handle ()
 Destructor. More...
 
void Nullify ()
 Nullify the handle. More...
 
bool IsNull () const
 Check for being null. More...
 
void reset (T *thePtr)
 Reset by new pointer. More...
 
handleoperator= (const handle &theHandle)
 Assignment operator. More...
 
handleoperator= (const T *thePtr)
 Assignment to pointer. More...
 
handleoperator= (handle &&theHandle)
 Move operator. More...
 
T * get () const
 STL-like cast to pointer to referred object (note non-const). More...
 
T * operator-> () const
 Member access operator (note non-const) More...
 
T & operator* () const
 Dereferencing operator (note non-const) More...
 
template<class T2 >
bool operator== (const handle< T2 > &theHandle) const
 Check for equality. More...
 
template<class T2 >
bool operator== (const T2 *thePtr) const
 Check for equality. More...
 
template<class T2 >
bool operator!= (const handle< T2 > &theHandle) const
 Check for inequality. More...
 
template<class T2 >
bool operator!= (const T2 *thePtr) const
 Check for inequality. More...
 
template<class T2 >
bool operator< (const handle< T2 > &theHandle) const
 Compare operator for possible use in std::map<> etc. More...
 
 operator Standard_Transient *handle::* () const
 Conversion to bool-compatible type for use in conditional expressions. More...
 
template<class T2 >
 operator const handle< T2 > & () const
 Upcast to const reference to base type. NB: this implementation will cause ambiguity errors on calls to overloaded functions accepting handles to different types, since compatibility is checked in the cast code rather than ensured by SFINAE (possible with C++11) More...
 
template<class T2 >
 operator handle< T2 > & ()
 Upcast to non-const reference to base type. NB: this cast can be dangerous, but required for legacy code; see #26377. More...
 

Static Public Member Functions

template<class T2 >
static opencascade::std::enable_if< is_base_but_not_same< T2, T >::value, handle >::type DownCast (const handle< T2 > &theObject)
 Down casting operator from handle to base type. More...
 
template<class T2 >
static opencascade::std::enable_if< is_base_but_not_same< T2, T >::value, handle >::type DownCast (const T2 *thePtr)
 Down casting operator from pointer to base type. More...
 
template<class T2 >
static handle DownCast (const handle< T2 > &theObject, typename opencascade::std::enable_if<!is_base_but_not_same< T2, T >::value, void * >::type=0)
 For compatibility, define down casting operator from non-base type, as deprecated. More...
 
template<class T2 >
static handle DownCast (const T2 *thePtr, typename opencascade::std::enable_if<!is_base_but_not_same< T2, T >::value, void * >::type=0)
 For compatibility, define down casting operator from non-base type, as deprecated. More...
 

Detailed Description

template<class T>
class opencascade::handle< T >

Intrusive smart pointer for use with Standard_Transient class and its descendants.

This class is similar to boost::intrusive_ptr<>. The reference counter is part of the base class (Standard_Transient), thus creation of a handle does not require allocation of additional memory for the counter. All handles to the same object share the common counter; object is deleted when the last handle pointing on it is destroyed. It is safe to create a new handle from plain C pointer to the object already pointed by another handle. The same object can be referenced by handles of different types (as soon as they are compatible with the object type).

Handle has type cast operator to const reference to handle to the base types, which allows it to be passed by reference in functions accepting reference to handle to base class, without copying.

By default, the type cast operator is provided also for non-const reference. These casts (potentially unsafe) can be disabled by defining macro OCCT_HANDLE_NOCAST; if it is defined, generalized copy constructor and assignment operators are defined allowing to initialize handle of base type from handle to derived type.

Weak pointers are not supported.

Member Typedef Documentation

◆ element_type

template<class T >
typedef T opencascade::handle< T >::element_type

STL-compliant typedef of contained type.

Constructor & Destructor Documentation

◆ handle() [1/4]

template<class T >
opencascade::handle< T >::handle ( )
inline

Empty constructor.

◆ handle() [2/4]

template<class T >
opencascade::handle< T >::handle ( const T *  thePtr)
inline

Constructor from pointer to new object.

◆ handle() [3/4]

template<class T >
opencascade::handle< T >::handle ( const handle< T > &  theHandle)
inline

Copy constructor.

◆ handle() [4/4]

template<class T >
opencascade::handle< T >::handle ( handle< T > &&  theHandle)
inline

Move constructor.

◆ ~handle()

template<class T >
opencascade::handle< T >::~handle ( )
inline

Destructor.

Member Function Documentation

◆ DownCast() [1/4]

template<class T >
template<class T2 >
static opencascade::std::enable_if<is_base_but_not_same<T2, T>::value, handle>::type opencascade::handle< T >::DownCast ( const handle< T2 > &  theObject)
inlinestatic

Down casting operator from handle to base type.

◆ DownCast() [2/4]

template<class T >
template<class T2 >
static handle opencascade::handle< T >::DownCast ( const handle< T2 > &  theObject,
typename opencascade::std::enable_if<!is_base_but_not_same< T2, T >::value, void * >::type  = 0 
)
inlinestatic

For compatibility, define down casting operator from non-base type, as deprecated.

Deprecated:
("down-casting from object of the same or unrelated type is meaningless")

◆ DownCast() [3/4]

template<class T >
template<class T2 >
static opencascade::std::enable_if<is_base_but_not_same<T2, T>::value, handle>::type opencascade::handle< T >::DownCast ( const T2 *  thePtr)
inlinestatic

Down casting operator from pointer to base type.

◆ DownCast() [4/4]

template<class T >
template<class T2 >
static handle opencascade::handle< T >::DownCast ( const T2 *  thePtr,
typename opencascade::std::enable_if<!is_base_but_not_same< T2, T >::value, void * >::type  = 0 
)
inlinestatic

For compatibility, define down casting operator from non-base type, as deprecated.

Deprecated:
("down-casting from object of the same or unrelated type is meaningless")

◆ get()

template<class T >
T* opencascade::handle< T >::get ( ) const
inline

STL-like cast to pointer to referred object (note non-const).

See also
std::shared_ptr::get()

◆ IsNull()

template<class T >
bool opencascade::handle< T >::IsNull ( ) const
inline

Check for being null.

◆ Nullify()

template<class T >
void opencascade::handle< T >::Nullify ( )
inline

Nullify the handle.

◆ operator const handle< T2 > &()

template<class T >
template<class T2 >
opencascade::handle< T >::operator const handle< T2 > & ( ) const
inline

Upcast to const reference to base type. NB: this implementation will cause ambiguity errors on calls to overloaded functions accepting handles to different types, since compatibility is checked in the cast code rather than ensured by SFINAE (possible with C++11)

◆ operator handle< T2 > &()

template<class T >
template<class T2 >
opencascade::handle< T >::operator handle< T2 > & ( )
inline

Upcast to non-const reference to base type. NB: this cast can be dangerous, but required for legacy code; see #26377.

Deprecated:
("Passing non-const reference to handle of base type in function is unsafe; use variable of exact type")

◆ operator Standard_Transient *handle::*()

template<class T >
opencascade::handle< T >::operator Standard_Transient *handle::* ( ) const
inline

Conversion to bool-compatible type for use in conditional expressions.

◆ operator!=() [1/2]

template<class T >
template<class T2 >
bool opencascade::handle< T >::operator!= ( const handle< T2 > &  theHandle) const
inline

Check for inequality.

◆ operator!=() [2/2]

template<class T >
template<class T2 >
bool opencascade::handle< T >::operator!= ( const T2 *  thePtr) const
inline

Check for inequality.

◆ operator*()

template<class T >
T& opencascade::handle< T >::operator* ( ) const
inline

Dereferencing operator (note non-const)

◆ operator->()

template<class T >
T* opencascade::handle< T >::operator-> ( ) const
inline

Member access operator (note non-const)

◆ operator<()

template<class T >
template<class T2 >
bool opencascade::handle< T >::operator< ( const handle< T2 > &  theHandle) const
inline

Compare operator for possible use in std::map<> etc.

◆ operator=() [1/3]

template<class T >
handle& opencascade::handle< T >::operator= ( const handle< T > &  theHandle)
inline

Assignment operator.

◆ operator=() [2/3]

template<class T >
handle& opencascade::handle< T >::operator= ( const T *  thePtr)
inline

Assignment to pointer.

◆ operator=() [3/3]

template<class T >
handle& opencascade::handle< T >::operator= ( handle< T > &&  theHandle)
inline

Move operator.

◆ operator==() [1/2]

template<class T >
template<class T2 >
bool opencascade::handle< T >::operator== ( const handle< T2 > &  theHandle) const
inline

Check for equality.

◆ operator==() [2/2]

template<class T >
template<class T2 >
bool opencascade::handle< T >::operator== ( const T2 *  thePtr) const
inline

Check for equality.

◆ reset()

template<class T >
void opencascade::handle< T >::reset ( T *  thePtr)
inline

Reset by new pointer.


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