VTK: Common/Core/vtkSmartPointerBase.h Source File

| VTK 9.3.1

vtkSmartPointerBase.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
14 #ifndef vtkSmartPointerBase_h
15 #define vtkSmartPointerBase_h
16
17 #include "vtkCommonCoreModule.h" // For export macro
18 #include "vtkObjectBase.h"
19
20 VTK_ABI_NAMESPACE_BEGIN
21 class VTKCOMMONCORE_EXPORT vtkSmartPointerBase
22 {
23 public:
27 vtkSmartPointerBase() noexcept;
28
32 vtkSmartPointerBase(vtkObjectBase* r);
33
38 vtkSmartPointerBase(const vtkSmartPointerBase& r);
39
43 vtkSmartPointerBase(vtkSmartPointerBase&& r) noexcept
44 : Object(r.Object)
45 {
46 r.Object = nullptr;
47 }
48
52 ~vtkSmartPointerBase();
53
55
59 vtkSmartPointerBase& operator=(vtkObjectBase* r);
60 vtkSmartPointerBase& operator=(const vtkSmartPointerBase& r);
62
66 vtkObjectBase* GetPointer() const noexcept
67 {
68 // Inline implementation so smart pointer comparisons can be fully
69 // inlined.
70 return this->Object;
71 }
72
76 void Report(vtkGarbageCollector* collector, const char* desc);
77
78 protected:
79 // Initialize smart pointer to given object, but do not increment
80 // reference count. The destructor will still decrement the count.
81 // This effectively makes it an auto-ptr.
82 class NoReference
83 {
84 };
85 vtkSmartPointerBase(vtkObjectBase* r, const NoReference&);
86
87 // Pointer to the actual object.
88 vtkObjectBase* Object;
89
90 private:
91 // Internal utility methods.
92 void Swap(vtkSmartPointerBase& r) noexcept;
93 void Register();
94 };
95
96 //----------------------------------------------------------------------------
97 #define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
98 inline bool operator op(const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
99 { \
100 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r.GetPointer())); \
101 } \
102 inline bool operator op(vtkObjectBase* l, const vtkSmartPointerBase& r) \
103 { \
104 return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
105 } \
106 inline bool operator op(const vtkSmartPointerBase& l, vtkObjectBase* r) \
107 { \
108 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
109 }
113 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(==)
114 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(!=)
115 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<)
116 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(<=)
117 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>)
118 VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(>=)
119
120 #undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
121
125 VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkSmartPointerBase& p);
126
127 VTK_ABI_NAMESPACE_END
128 #endif
129 // VTK-HeaderTest-Exclude: vtkSmartPointerBase.h
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:80
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:72
vtkSmartPointerBase::NoReference
Definition: vtkSmartPointerBase.h:83
vtkSmartPointerBase
Non-templated superclass for vtkSmartPointer.
Definition: vtkSmartPointerBase.h:22
vtkSmartPointerBase::~vtkSmartPointerBase
~vtkSmartPointerBase()
Destroy smart pointer and remove the reference to its object.
vtkSmartPointerBase::Report
void Report(vtkGarbageCollector *collector, const char *desc)
Report the reference held by the smart pointer to a collector.
vtkSmartPointerBase::vtkSmartPointerBase
vtkSmartPointerBase(vtkObjectBase *r, const NoReference &)
vtkSmartPointerBase::vtkSmartPointerBase
vtkSmartPointerBase() noexcept
Initialize smart pointer to nullptr.
vtkSmartPointerBase::operator=
vtkSmartPointerBase & operator=(vtkObjectBase *r)
Assign object to reference.
vtkSmartPointerBase::operator=
vtkSmartPointerBase & operator=(const vtkSmartPointerBase &r)
Assign object to reference.
vtkSmartPointerBase::Object
vtkObjectBase * Object
Definition: vtkSmartPointerBase.h:88
vtkSmartPointerBase::GetPointer
vtkObjectBase * GetPointer() const noexcept
Get the contained pointer.
Definition: vtkSmartPointerBase.h:66
vtkObjectBase.h
VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op)
Definition: vtkSmartPointerBase.h:97
operator<<
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkSmartPointerBase &p)
Compare smart pointer values.