VTK  9.4.20241222
Public Member Functions | Friends | List of all members
vtkNew< T > Class Template Reference

Allocate and hold a VTK object. More...

#include <vtkNew.h>

Public Member Functions

 vtkNew ()
 Create a new T on construction.
 
T * operator-> () const noexcept
 Enable pointer-like dereference syntax.
 
T & operator* () const noexcept
 Dereference the pointer and return a reference to the contained object.
 
vtkNew< T > & operator= (vtkNew< T > &&other) noexcept
 Move assignment operator.
 
 vtkNew (vtkNew &&o) noexcept
 Move the object into the constructed vtkNew wrapper, stealing its reference.
 
template<typename U >
 vtkNew (vtkNew< U > &&o) noexcept
 Move the object into the constructed vtkNew wrapper, stealing its reference.
 
void Reset ()
 Deletes reference to instance of T.
 
T * GetPointer () const noexcept
 Get a raw pointer to the contained object.
 
T * Get () const noexcept
 Get a raw pointer to the contained object.
 
 operator T* () const noexcept
 Get a raw pointer to the contained object.
 

Friends

template<typename U >
class vtkNew
 
template<typename U >
class vtkSmartPointer
 
template<typename U >
class vtkWeakPointer
 
void vtkGarbageCollectorReport (vtkGarbageCollector *collector, vtkNew< T > &ptr, const char *desc)
 Function to report a reference held by a vtkNew to a collector.
 

Detailed Description

template<class T>
class vtkNew< T >

Allocate and hold a VTK object.

vtkNew is a class template that on construction allocates and initializes an instance of its template argument using T::New(). It assumes ownership of one reference during its lifetime, and calls T->Delete() on destruction.

Automatic casting to raw pointer is available for convenience, but users of this method should ensure that they do not return this pointer if the vtkNew will go out of scope without incrementing its reference count.

vtkNew is a drop in replacement for vtkSmartPointer, for example,

renWin->AddRenderer(ren);
iren->SetRenderWindow(renWin);
Allocate and hold a VTK object.
Definition vtkNew.h:167
See also
vtkSmartPointer vtkWeakPointer
Examples:
vtkNew (Examples)
Online Examples:

Tests:
vtkNew (Tests)

Definition at line 166 of file vtkNew.h.

Constructor & Destructor Documentation

◆ vtkNew() [1/3]

template<class T >
vtkNew< T >::vtkNew ( )
inline

Create a new T on construction.

Definition at line 199 of file vtkNew.h.

◆ vtkNew() [2/3]

template<class T >
vtkNew< T >::vtkNew ( vtkNew< T > &&  o)
inlinenoexcept

Move the object into the constructed vtkNew wrapper, stealing its reference.

The argument is reset to nullptr.

Definition at line 210 of file vtkNew.h.

◆ vtkNew() [3/3]

template<class T >
template<typename U >
vtkNew< T >::vtkNew ( vtkNew< U > &&  o)
inlinenoexcept

Move the object into the constructed vtkNew wrapper, stealing its reference.

The argument is reset to nullptr.

Definition at line 217 of file vtkNew.h.

◆ ~vtkNew()

template<class T >
vtkNew< T >::~vtkNew ( )
inline

Deletes reference to instance of T.

Definition at line 230 of file vtkNew.h.

Member Function Documentation

◆ Reset()

template<class T >
void vtkNew< T >::Reset ( )
inline

Deletes reference to instance of T.

Definition at line 232 of file vtkNew.h.

◆ operator->()

template<class T >
T * vtkNew< T >::operator-> ( ) const
inlinenoexcept

Enable pointer-like dereference syntax.

Returns a pointer to the contained object.

Definition at line 247 of file vtkNew.h.

◆ GetPointer()

template<class T >
T * vtkNew< T >::GetPointer ( ) const
inlinenoexcept

Get a raw pointer to the contained object.

When using this function be careful that the reference count does not drop to 0 when using the pointer returned. This will happen when the vtkNew object goes out of scope for example.

Definition at line 256 of file vtkNew.h.

◆ Get()

template<class T >
T * vtkNew< T >::Get ( ) const
inlinenoexcept

Get a raw pointer to the contained object.

When using this function be careful that the reference count does not drop to 0 when using the pointer returned. This will happen when the vtkNew object goes out of scope for example.

Definition at line 257 of file vtkNew.h.

◆ operator T*()

template<class T >
vtkNew< T >::operator T* ( ) const
inlinenoexcept

Get a raw pointer to the contained object.

When using this function be careful that the reference count does not drop to 0 when using the pointer returned. This will happen when the vtkNew object goes out of scope for example.

Definition at line 258 of file vtkNew.h.

◆ operator*()

template<class T >
T & vtkNew< T >::operator* ( ) const
inlinenoexcept

Dereference the pointer and return a reference to the contained object.

When using this function be careful that the reference count does not drop to 0 when using the pointer returned. This will happen when the vtkNew object goes out of scope for example.

Definition at line 266 of file vtkNew.h.

◆ operator=()

template<class T >
vtkNew< T > & vtkNew< T >::operator= ( vtkNew< T > &&  other)
inlinenoexcept

Move assignment operator.

Definition at line 271 of file vtkNew.h.

Friends And Related Symbol Documentation

◆ vtkNew

template<class T >
template<typename U >
friend class vtkNew
friend

Definition at line 170 of file vtkNew.h.

◆ vtkSmartPointer

template<class T >
template<typename U >
friend class vtkSmartPointer
friend

Definition at line 172 of file vtkNew.h.

◆ vtkWeakPointer

template<class T >
template<typename U >
friend class vtkWeakPointer
friend

Definition at line 174 of file vtkNew.h.

◆ vtkGarbageCollectorReport

template<class T >
void vtkGarbageCollectorReport ( vtkGarbageCollector collector,
vtkNew< T > &  ptr,
const char *  desc 
)
friend

Function to report a reference held by a vtkNew to a collector.

Definition at line 192 of file vtkGarbageCollector.h.


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