46 #include <type_traits>
48 VTK_ABI_NAMESPACE_BEGIN
57 template <
typename U = T>
58 static void CheckTypes() noexcept
61 "vtkWeakPtr<T>'s T type has not been defined. Missing include?");
63 "Cannot store an object with undefined type in vtkWeakPtr. Missing include?");
67 "vtkWeakPtr can only be used with subclasses of vtkObjectBase.");
88 : Block(r ? r->GetWeakControlBlock() : nullptr)
90 vtkWeakPtr::CheckTypes<T>();
94 : Block(r ? r->GetWeakControlBlock() : nullptr)
96 vtkWeakPtr::CheckTypes<U>();
100 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
101 vtkWeakPtr::CheckTypes<T>();
104 template <
typename U>
107 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
108 vtkWeakPtr::CheckTypes<U>();
112 : Block(r ? r->GetWeakControlBlock() : nullptr)
114 vtkWeakPtr::CheckTypes<T>();
116 template <
typename U>
118 : Block(r ? r->GetWeakControlBlock() : nullptr)
120 vtkWeakPtr::CheckTypes<U>();
124 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
125 vtkWeakPtr::CheckTypes<T>();
128 template <
typename U>
131 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
132 vtkWeakPtr::CheckTypes<U>();
146 template <
typename U>
153 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
156 template <
typename U>
159 this->Block = r ? r->GetWeakControlBlock() :
nullptr;
160 vtkWeakPtr::CheckTypes<U>();
170 template <
typename U>
174 vtkWeakPtr::CheckTypes<U>();
177 template <
typename U>
180 this->Block = r.Block;
181 vtkWeakPtr::CheckTypes<U>();
191 template <typename U>
193 : Block(
std::move(r.Block))
195 vtkWeakPtr::CheckTypes<U>();
198 template <typename U>
201 this->Block = std::move(r.Block);
202 vtkWeakPtr::CheckTypes<U>();
224 bool Expired()
const {
return !this->Block || !this->Block->Object; }
241 std::lock_guard<std::mutex> guard(this->Block->Mutex);
244 if (T* obj = static_cast<T*>(this->Block->Object))
250 if (obj->TryUpgradeRegister(owner))
281 : Block(r ? r->GetWeakControlBlock() : nullptr)
283 vtkWeakPtr::CheckTypes<T>();
285 template <
typename U>
287 : Block(r ? r->GetWeakControlBlock() : nullptr)
289 vtkWeakPtr::CheckTypes<U>();
293 template <
typename U>
295 std::shared_ptr<vtkObjectBase::WeakControlBlock> Block;
298 VTK_ABI_NAMESPACE_END
vtkWeakPtr & Reset(T *r)
Raw pointer constructors and assignment.
vtkWeakPtr & operator=(const vtkWeakPtr< U > &r)
Copy construction and assignment.
static vtkSmartPointer< T > Take(T *t)
Transfer ownership of one reference to the given VTK object to a new smart pointer.
vtkWeakPtr(vtkSmartPointer< U > &r)
Pointer construction and assignment.
Hold a reference to a vtkObjectBase instance.
vtkWeakPtr & Reset(U *r)
Raw pointer constructors and assignment.
vtkWeakPtr & operator=(vtkNew< U > &r)
Pointer construction and assignment.
vtkWeakPtr(vtkNew< U > &r)
Pointer construction and assignment.
vtkWeakPtr & operator=(vtkSmartPointer< T > &r)
Pointer construction and assignment.
vtkWeakPtr(const vtkWeakPtr< U > &r)
Copy construction and assignment.
vtkWeakPtr & operator=(vtkNew< T > &r)
Pointer construction and assignment.
bool owner_before(const vtkWeakPtr &r) const
Compatibility with std::owner_less for use in comparison-based containers.
static vtkWeakPtr FromOwningRawPointer(T *r)
Raw pointer constructors and assignment.
static vtkWeakPtr FromOwningRawPointer(U *r)
Raw pointer constructors and assignment.
vtkWeakPtr() noexcept
Default construction.
vtkWeakPtr(const vtkSmartPointer< T > &r)
Pointer construction and assignment.
abstract base class for most VTK objects
~vtkWeakPtr() noexcept=default
bool Expired() const
Check whether the held object has expired or not.
Allocate and hold a VTK object.
vtkWeakPtr(const vtkNew< T > &r)
Pointer construction and assignment.
vtkSmartPointer< T > Lock(vtkObjectBase *owner=nullptr) const
Obtain a new reference to the held object, if available.
vtkWeakPtr & operator=(vtkSmartPointer< U > &r)
Pointer construction and assignment.
a weak reference to a vtkObjectBase.