VTK  9.3.20240226
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 
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 
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.
83  {
84  };
86 
87  // Pointer to the actual 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  }
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
Detect and break reference loops.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:83
Non-templated superclass for vtkSmartPointer.
~vtkSmartPointerBase()
Destroy smart pointer and remove the reference to its object.
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=(vtkObjectBase *r)
Assign object to reference.
vtkSmartPointerBase & operator=(const vtkSmartPointerBase &r)
Assign object to reference.
vtkObjectBase * Object
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.