VTK  9.3.20240615
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
20VTK_ABI_NAMESPACE_BEGIN
21class VTKCOMMONCORE_EXPORT vtkSmartPointerBase
22{
23public:
28
33
39
44 : Object(r.Object)
45 {
46 r.Object = nullptr;
47 }
48
53
55
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
78protected:
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.
83 {
84 };
86
87 // Pointer to the actual object.
89
90private:
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 }
119
120#undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
121
125VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkSmartPointerBase& p);
126
127VTK_ABI_NAMESPACE_END
128#endif
129// VTK-HeaderTest-Exclude: vtkSmartPointerBase.h
Detect and break reference loops.
abstract base class for most VTK objects
Non-templated superclass for vtkSmartPointer.
~vtkSmartPointerBase()
Destroy smart pointer and remove the reference to its object.
vtkSmartPointerBase & operator=(vtkObjectBase *r)
Assign object to reference.
void Report(vtkGarbageCollector *collector, const char *desc)
Report the reference held by the smart pointer to a collector.
vtkSmartPointerBase(vtkObjectBase *r, const NoReference &)
vtkSmartPointerBase() noexcept
Initialize smart pointer to nullptr.
vtkSmartPointerBase & operator=(const vtkSmartPointerBase &r)
Assign object to reference.
vtkObjectBase * GetPointer() const noexcept
Get the contained pointer.
#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkSmartPointerBase &p)
Compare smart pointer values.