ITK  6.0.0
Insight Toolkit
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
itk::SmartPointer< TObjectType > Class Template Reference

#include <itkSmartPointer.h>

Detailed Description

template<typename TObjectType>
class itk::SmartPointer< TObjectType >

Implements transparent reference counting.

SmartPointer implements reference counting by overloading operator -> (and *) among others. This allows natural interface to the class referred to by the pointer without having to invoke special Register()/UnRegister() methods directly.

To compile / test this class Windows: cl SmartPointerTest.cxx; .\SmartPointerTest.exe linux: c++ SmartPointerTest.cxx ./a.out other: CCcompiler SmartPointerTest.cxx ./a.out

The state of the SmartPointer after a move is with a value of nullptr.

Definition at line 51 of file itkSmartPointer.h.

Public Types

template<typename T >
using EnableIfConvertible = typename std::enable_if< std::is_convertible_v< T *, TObjectType * > >
 
using ObjectType = TObjectType
 

Public Member Functions

ObjectTypeget () const noexcept
 
ObjectTypeGetPointer () const noexcept
 
bool IsNotNull () const noexcept
 
bool IsNull () const noexcept
 
 operator bool () const noexcept
 
 operator ObjectType * () const noexcept
 
ObjectTypeoperator* () const noexcept
 
ObjectTypeoperator-> () const noexcept
 
SmartPointeroperator= (std::nullptr_t) noexcept
 
constexpr SmartPointer () noexcept=default
 
 SmartPointer (const SmartPointer &p) noexcept
 
template<typename T , typename = typename EnableIfConvertible<T>::type>
 SmartPointer (const SmartPointer< T > &p) noexcept
 
 SmartPointer (ObjectType *p) noexcept
 
 SmartPointer (SmartPointer< ObjectType > &&p) noexcept
 
template<typename T , typename = typename EnableIfConvertible<T>::type>
 SmartPointer (SmartPointer< T > &&p) noexcept
 
constexpr SmartPointer (std::nullptr_t) noexcept
 
void Swap (SmartPointer &other) noexcept
 
 ~SmartPointer ()
 
SmartPointeroperator= (SmartPointer r) noexcept
 
ObjectTypePrint (std::ostream &os) const
 

Private Member Functions

void Register () noexcept
 
void UnRegister () noexcept
 

Private Attributes

ObjectTypem_Pointer { nullptr }
 

Friends

template<typename T >
class SmartPointer
 

Member Typedef Documentation

◆ EnableIfConvertible

template<typename TObjectType >
template<typename T >
using itk::SmartPointer< TObjectType >::EnableIfConvertible = typename std::enable_if<std::is_convertible_v<T *, TObjectType *> >

Definition at line 57 of file itkSmartPointer.h.

◆ ObjectType

template<typename TObjectType >
using itk::SmartPointer< TObjectType >::ObjectType = TObjectType

Definition at line 54 of file itkSmartPointer.h.

Constructor & Destructor Documentation

◆ SmartPointer() [1/7]

template<typename TObjectType >
constexpr itk::SmartPointer< TObjectType >::SmartPointer ( )
constexprdefaultnoexcept

Default-constructor

◆ SmartPointer() [2/7]

template<typename TObjectType >
itk::SmartPointer< TObjectType >::SmartPointer ( const SmartPointer< TObjectType > &  p)
inlinenoexcept

Copy constructor

Definition at line 63 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::Register().

◆ SmartPointer() [3/7]

template<typename TObjectType >
constexpr itk::SmartPointer< TObjectType >::SmartPointer ( std::nullptr_t  )
inlineconstexprnoexcept

Constructor for implicit conversion from nullptr

Definition at line 70 of file itkSmartPointer.h.

◆ SmartPointer() [4/7]

template<typename TObjectType >
template<typename T , typename = typename EnableIfConvertible<T>::type>
itk::SmartPointer< TObjectType >::SmartPointer ( const SmartPointer< T > &  p)
inlinenoexcept

constructor with implicit conversion of pointer type

Definition at line 74 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::Register().

◆ SmartPointer() [5/7]

template<typename TObjectType >
itk::SmartPointer< TObjectType >::SmartPointer ( SmartPointer< ObjectType > &&  p)
inlinenoexcept

Move constructor

Definition at line 81 of file itkSmartPointer.h.

◆ SmartPointer() [6/7]

template<typename TObjectType >
template<typename T , typename = typename EnableIfConvertible<T>::type>
itk::SmartPointer< TObjectType >::SmartPointer ( SmartPointer< T > &&  p)
inlinenoexcept

move constructor with implicit conversion of pointer type

Definition at line 89 of file itkSmartPointer.h.

◆ SmartPointer() [7/7]

template<typename TObjectType >
itk::SmartPointer< TObjectType >::SmartPointer ( ObjectType p)
inlinenoexcept

Constructor to pointer p

Definition at line 96 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::Register().

◆ ~SmartPointer()

template<typename TObjectType >
itk::SmartPointer< TObjectType >::~SmartPointer ( )
inline

Destructor

Definition at line 103 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::UnRegister().

Member Function Documentation

◆ get()

template<typename TObjectType >
ObjectType * itk::SmartPointer< TObjectType >::get ( ) const
inlinenoexcept

Returns the stored (raw) pointer. Equivalent to GetPointer(), but then following the Standard C++ Library naming conversion (like std::shared_ptr::get()).

Definition at line 140 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

◆ GetPointer()

template<typename TObjectType >
ObjectType * itk::SmartPointer< TObjectType >::GetPointer ( ) const
inlinenoexcept

◆ IsNotNull()

template<typename TObjectType >
bool itk::SmartPointer< TObjectType >::IsNotNull ( ) const
inlinenoexcept

Test if the pointer is not NULL.

Definition at line 117 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

Referenced by itk::BSplineResampleImageFunction< TImageType, TCoordRep >::SetInputImage().

◆ IsNull()

template<typename TObjectType >
bool itk::SmartPointer< TObjectType >::IsNull ( ) const
inlinenoexcept

Test if the pointer is NULL.

Definition at line 124 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

Referenced by itk::SmartPointer< TObjectType >::Print().

◆ operator bool()

template<typename TObjectType >
itk::SmartPointer< TObjectType >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 110 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

◆ operator ObjectType *()

template<typename TObjectType >
itk::SmartPointer< TObjectType >::operator ObjectType * ( ) const
inlinenoexcept

Return pointer to object.

Definition at line 113 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

◆ operator*()

template<typename TObjectType >
ObjectType & itk::SmartPointer< TObjectType >::operator* ( ) const
inlinenoexcept

Definition at line 108 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

◆ operator->()

template<typename TObjectType >
ObjectType * itk::SmartPointer< TObjectType >::operator-> ( ) const
inlinenoexcept

Overload operator ->

Definition at line 106 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::m_Pointer.

◆ operator=() [1/2]

template<typename TObjectType >
SmartPointer & itk::SmartPointer< TObjectType >::operator= ( SmartPointer< TObjectType >  r)
inlinenoexcept

Overload operator assignment.

This method is also implicitly used for move semantics.
Additionally, it relies on constructors for additional conversion
for pointer types.

Definition at line 154 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::Swap().

◆ operator=() [2/2]

template<typename TObjectType >
SmartPointer & itk::SmartPointer< TObjectType >::operator= ( std::nullptr_t  )
inlinenoexcept

◆ Print()

template<typename TObjectType >
ObjectType * itk::SmartPointer< TObjectType >::Print ( std::ostream &  os) const
inline

Function to print object pointed to

Definition at line 173 of file itkSmartPointer.h.

References itk::SmartPointer< TObjectType >::IsNull(), and itk::SmartPointer< TObjectType >::m_Pointer.

Referenced by itk::operator<<().

◆ Register()

template<typename TObjectType >
void itk::SmartPointer< TObjectType >::Register ( )
inlineprivatenoexcept

◆ Swap()

template<typename TObjectType >
void itk::SmartPointer< TObjectType >::Swap ( SmartPointer< TObjectType > &  other)
inlinenoexcept

◆ UnRegister()

template<typename TObjectType >
void itk::SmartPointer< TObjectType >::UnRegister ( )
inlineprivatenoexcept

Friends And Related Function Documentation

◆ SmartPointer

template<typename TObjectType >
template<typename T >
friend class SmartPointer
friend

Definition at line 209 of file itkSmartPointer.h.

Member Data Documentation

◆ m_Pointer

template<typename TObjectType >
ObjectType* itk::SmartPointer< TObjectType >::m_Pointer { nullptr }
private

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