VTK  9.6.20260315
vtkWeakPtr< T > Class Template Reference

a weak reference to a vtkObjectBase. More...

#include <vtkWeakPtr.h>

Public Member Functions

 vtkWeakPtr () noexcept
 Default construction.
 
 vtkWeakPtr (const vtkNew< T > &r)
 Pointer construction and assignment.
 
template<typename U>
 vtkWeakPtr (vtkNew< U > &r)
 Pointer construction and assignment.
 
vtkWeakPtroperator= (vtkNew< T > &r)
 Pointer construction and assignment.
 
template<typename U>
vtkWeakPtroperator= (vtkNew< U > &r)
 Pointer construction and assignment.
 
 vtkWeakPtr (const vtkSmartPointer< T > &r)
 Pointer construction and assignment.
 
template<typename U>
 vtkWeakPtr (vtkSmartPointer< U > &r)
 Pointer construction and assignment.
 
vtkWeakPtroperator= (vtkSmartPointer< T > &r)
 Pointer construction and assignment.
 
template<typename U>
vtkWeakPtroperator= (vtkSmartPointer< U > &r)
 Pointer construction and assignment.
 
 vtkWeakPtr (const vtkWeakPtr &r)=default
 Copy construction and assignment.
 
template<typename U>
 vtkWeakPtr (const vtkWeakPtr< U > &r)
 Copy construction and assignment.
 
vtkWeakPtroperator= (const vtkWeakPtr &r)=default
 Copy construction and assignment.
 
template<typename U>
vtkWeakPtroperator= (const vtkWeakPtr< U > &r)
 Copy construction and assignment.
 
 vtkWeakPtr (vtkWeakPtr &&r) noexcept=default
 Move construction and assignment.
 
template<typename U>
 vtkWeakPtr (vtkWeakPtr< U > &&r) noexcept
 Move construction and assignment.
 
vtkWeakPtroperator= (vtkWeakPtr &&r) noexcept=default
 Move construction and assignment.
 
template<typename U>
vtkWeakPtroperator= (vtkWeakPtr< U > &&r) noexcept
 Move construction and assignment.
 
 ~vtkWeakPtr () noexcept=default
 
bool Expired () const
 Check whether the held object has expired or not.
 
vtkSmartPointer< T > Lock (vtkObjectBase *owner=nullptr) const
 Obtain a new reference to the held object, if available.
 
bool owner_before (const vtkWeakPtr &r) const
 Compatibility with std::owner_less for use in comparison-based containers.
 

Friends

template<typename U>
class vtkWeakPtr
 
vtkWeakPtrReset (T *r)
 Raw pointer constructors and assignment.
 
template<typename U>
vtkWeakPtrReset (U *r)
 Raw pointer constructors and assignment.
 
static vtkWeakPtr FromOwningRawPointer (T *r)
 Raw pointer constructors and assignment.
 
template<typename U>
static vtkWeakPtr FromOwningRawPointer (U *r)
 Raw pointer constructors and assignment.
 

Detailed Description

template<typename T>
class vtkWeakPtr< T >

a weak reference to a vtkObjectBase.

A weak reference to a vtkObjectBase, which means that assigning a vtkObjectBase to the vtkWeakPtr does not affect the reference count of the vtkObjectBase.

vtkWeakPtr<vtkTable> weakTable = table;
A table, which contains similar-typed columns of data.
Definition vtkTable.h:169
static vtkTable * New()
friend class vtkWeakPtr
Definition vtkWeakPtr.h:294

Some time later the table may be deleted, but if it is tested for null then the weak pointer will not leave a dangling pointer.

table->Delete();
if (auto strongTable = weakTable.Lock())
{
// Never executed as the weak table pointer will be null here
cout << "Number of columns in table: " << strongTable->GetNumberOfColumns()
<< endl;
}
virtual void Delete()
Delete a VTK object.
vtkSmartPointer< T > Lock(vtkObjectBase *owner=nullptr) const
Obtain a new reference to the held object, if available.
Definition vtkWeakPtr.h:235

Note that, unlike vtkWeakPointer, the pointer itself is only accessible after calling lock to avoid the situation of another thread deleting the last instance between the check and its usage inside the conditional.

Tests:
vtkWeakPtr (Tests)

Definition at line 51 of file vtkWeakPtr.h.

Constructor & Destructor Documentation

◆ vtkWeakPtr() [1/9]

template<typename T>
vtkWeakPtr< T >::vtkWeakPtr ( )
inlinenoexcept

Default construction.

Definition at line 75 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [2/9]

template<typename T>
vtkWeakPtr< T >::vtkWeakPtr ( const vtkNew< T > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 87 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [3/9]

template<typename T>
template<typename U>
vtkWeakPtr< T >::vtkWeakPtr ( vtkNew< U > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 93 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [4/9]

template<typename T>
vtkWeakPtr< T >::vtkWeakPtr ( const vtkSmartPointer< T > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 111 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [5/9]

template<typename T>
template<typename U>
vtkWeakPtr< T >::vtkWeakPtr ( vtkSmartPointer< U > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 117 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [6/9]

template<typename T>
vtkWeakPtr< T >::vtkWeakPtr ( const vtkWeakPtr< T > & r)
default

Copy construction and assignment.

◆ vtkWeakPtr() [7/9]

template<typename T>
template<typename U>
vtkWeakPtr< T >::vtkWeakPtr ( const vtkWeakPtr< U > & r)
inline

Copy construction and assignment.

Definition at line 171 of file vtkWeakPtr.h.

◆ vtkWeakPtr() [8/9]

template<typename T>
vtkWeakPtr< T >::vtkWeakPtr ( vtkWeakPtr< T > && r)
defaultnoexcept

Move construction and assignment.

◆ vtkWeakPtr() [9/9]

template<typename T>
template<typename U>
vtkWeakPtr< T >::vtkWeakPtr ( vtkWeakPtr< U > && r)
inlinenoexcept

Move construction and assignment.

Definition at line 192 of file vtkWeakPtr.h.

◆ ~vtkWeakPtr()

template<typename T>
vtkWeakPtr< T >::~vtkWeakPtr ( )
defaultnoexcept

Member Function Documentation

◆ operator=() [1/8]

template<typename T>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkNew< T > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 98 of file vtkWeakPtr.h.

◆ operator=() [2/8]

template<typename T>
template<typename U>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkNew< U > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 105 of file vtkWeakPtr.h.

◆ operator=() [3/8]

template<typename T>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkSmartPointer< T > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 122 of file vtkWeakPtr.h.

◆ operator=() [4/8]

template<typename T>
template<typename U>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkSmartPointer< U > & r)
inline

Pointer construction and assignment.

Only vtkNew and vtkSmartPointer instance may be used with the default constructors and assignments because these classes imply that the caller has a strong ownership in the object which guarantees it will exist for at least the duration of the vtkWeakPtr constructor.

Definition at line 129 of file vtkWeakPtr.h.

◆ FromOwningRawPointer() [1/2]

template<typename T>
static vtkWeakPtr vtkWeakPtr< T >::FromOwningRawPointer ( T * r)
inlinestatic

Raw pointer constructors and assignment.

Not immediately accessible because the caller must declare that it owns a reference to the pointer so that it does not become invalid before the vtkWeakPtr is done with its construction.

Definition at line 145 of file vtkWeakPtr.h.

◆ FromOwningRawPointer() [2/2]

template<typename T>
template<typename U>
static vtkWeakPtr vtkWeakPtr< T >::FromOwningRawPointer ( U * r)
inlinestatic

Raw pointer constructors and assignment.

Not immediately accessible because the caller must declare that it owns a reference to the pointer so that it does not become invalid before the vtkWeakPtr is done with its construction.

Definition at line 147 of file vtkWeakPtr.h.

◆ Reset() [1/2]

template<typename T>
vtkWeakPtr & vtkWeakPtr< T >::Reset ( T * r)
inline

Raw pointer constructors and assignment.

Not immediately accessible because the caller must declare that it owns a reference to the pointer so that it does not become invalid before the vtkWeakPtr is done with its construction.

Definition at line 151 of file vtkWeakPtr.h.

◆ Reset() [2/2]

template<typename T>
template<typename U>
vtkWeakPtr & vtkWeakPtr< T >::Reset ( U * r)
inline

Raw pointer constructors and assignment.

Not immediately accessible because the caller must declare that it owns a reference to the pointer so that it does not become invalid before the vtkWeakPtr is done with its construction.

Definition at line 157 of file vtkWeakPtr.h.

◆ operator=() [5/8]

template<typename T>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( const vtkWeakPtr< T > & r)
default

Copy construction and assignment.

◆ operator=() [6/8]

template<typename T>
template<typename U>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( const vtkWeakPtr< U > & r)
inline

Copy construction and assignment.

Definition at line 178 of file vtkWeakPtr.h.

◆ operator=() [7/8]

template<typename T>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkWeakPtr< T > && r)
defaultnoexcept

Move construction and assignment.

◆ operator=() [8/8]

template<typename T>
template<typename U>
vtkWeakPtr & vtkWeakPtr< T >::operator= ( vtkWeakPtr< U > && r)
inlinenoexcept

Move construction and assignment.

Definition at line 199 of file vtkWeakPtr.h.

◆ Expired()

template<typename T>
bool vtkWeakPtr< T >::Expired ( ) const
inline

Check whether the held object has expired or not.

The only trustworthy result from this method is true. That is, once the pointed-to object has expired, the state will not change without modifying the vtkWeakPtr itself. Any indication of non-expiration is a point-in-time check and does not guarantee that the object will not expire between the check and any future use.

Use of Lock is required to actually get access to the pointed-to object and guarantees that it is accessible afterwards by adding a new reference.

Definition at line 224 of file vtkWeakPtr.h.

◆ Lock()

template<typename T>
vtkSmartPointer< T > vtkWeakPtr< T >::Lock ( vtkObjectBase * owner = nullptr) const
inline

Obtain a new reference to the held object, if available.

If passed, the given object will be the owner of the new reference.

"It is better to ask for forgiveness than permission."

Definition at line 235 of file vtkWeakPtr.h.

◆ owner_before()

template<typename T>
bool vtkWeakPtr< T >::owner_before ( const vtkWeakPtr< T > & r) const
inline

Compatibility with std::owner_less for use in comparison-based containers.

Definition at line 272 of file vtkWeakPtr.h.

Friends And Related Symbol Documentation

◆ vtkWeakPtr

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

Definition at line 294 of file vtkWeakPtr.h.


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