VTK  9.1.0
vtkSmartPointerBase.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSmartPointerBase.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
26#ifndef vtkSmartPointerBase_h
27#define vtkSmartPointerBase_h
28
29#include "vtkCommonCoreModule.h" // For export macro
30#include "vtkObjectBase.h"
31
32class VTKCOMMONCORE_EXPORT vtkSmartPointerBase
33{
34public:
39
44
50
55 : Object(r.Object)
56 {
57 r.Object = nullptr;
58 }
59
64
66
73
77 vtkObjectBase* GetPointer() const noexcept
78 {
79 // Inline implementation so smart pointer comparisons can be fully
80 // inlined.
81 return this->Object;
82 }
83
87 void Report(vtkGarbageCollector* collector, const char* desc);
88
89protected:
90 // Initialize smart pointer to given object, but do not increment
91 // reference count. The destructor will still decrement the count.
92 // This effectively makes it an auto-ptr.
94 {
95 };
97
98 // Pointer to the actual object.
100
101private:
102 // Internal utility methods.
103 void Swap(vtkSmartPointerBase& r) noexcept;
104 void Register();
105};
106
107//----------------------------------------------------------------------------
108#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op) \
109 inline bool operator op(const vtkSmartPointerBase& l, const vtkSmartPointerBase& r) \
110 { \
111 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r.GetPointer())); \
112 } \
113 inline bool operator op(vtkObjectBase* l, const vtkSmartPointerBase& r) \
114 { \
115 return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
116 } \
117 inline bool operator op(const vtkSmartPointerBase& l, vtkObjectBase* r) \
118 { \
119 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
120 }
130
131#undef VTK_SMART_POINTER_BASE_DEFINE_OPERATOR
132
136VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkSmartPointerBase& p);
137
138#endif
139// VTK-HeaderTest-Exclude: vtkSmartPointerBase.h
Detect and break reference loops.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
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.
vtkObjectBase * Object
#define VTK_SMART_POINTER_BASE_DEFINE_OPERATOR(op)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkSmartPointerBase &p)
Compare smart pointer values.