VTK  9.3.20240416
vtkWeakPointerBase.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
13 #ifndef vtkWeakPointerBase_h
14 #define vtkWeakPointerBase_h
15 
16 #include "vtkCommonCoreModule.h" // For export macro
17 #include "vtkObjectBase.h"
18 
19 VTK_ABI_NAMESPACE_BEGIN
20 class vtkObjectBaseToWeakPointerBaseFriendship;
21 
22 class VTKCOMMONCORE_EXPORT vtkWeakPointerBase
23 {
24 public:
28  vtkWeakPointerBase() noexcept
29  : Object(nullptr)
30  {
31  }
32 
37 
42 
47 
52 
54 
62 
67  {
68  // Inline implementation so smart pointer comparisons can be fully
69  // inlined.
70  return this->Object;
71  }
72 
73 private:
74  friend class vtkObjectBaseToWeakPointerBaseFriendship;
75 
76 protected:
77  // Initialize weak pointer to given object.
79  {
80  };
82 
83  // Pointer to the actual object.
85 };
86 
87 //----------------------------------------------------------------------------
88 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \
89  inline bool operator op(const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \
90  { \
91  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r.GetPointer())); \
92  } \
93  inline bool operator op(vtkObjectBase* l, const vtkWeakPointerBase& r) \
94  { \
95  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
96  } \
97  inline bool operator op(const vtkWeakPointerBase& l, vtkObjectBase* r) \
98  { \
99  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
100  }
110 
111 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
112 
116 VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkWeakPointerBase& p);
117 
118 VTK_ABI_NAMESPACE_END
119 #endif
120 // VTK-HeaderTest-Exclude: vtkWeakPointerBase.h
abstract base class for most VTK objects
Definition: vtkObjectBase.h:84
Non-templated superclass for vtkWeakPointer.
vtkWeakPointerBase(const vtkWeakPointerBase &r)
Copy r's data object into the new weak pointer.
vtkWeakPointerBase(vtkObjectBase *r)
Initialize smart pointer to given object.
vtkWeakPointerBase & operator=(vtkObjectBase *r)
Assign object to reference.
vtkWeakPointerBase & operator=(vtkWeakPointerBase &&r) noexcept
Assign object to reference.
~vtkWeakPointerBase()
Destroy smart pointer.
vtkWeakPointerBase & operator=(const vtkWeakPointerBase &r)
Assign object to reference.
vtkObjectBase * Object
vtkWeakPointerBase(vtkWeakPointerBase &&r) noexcept
Move r's object into the new weak pointer, setting r to nullptr.
vtkWeakPointerBase(vtkObjectBase *r, const NoReference &)
vtkWeakPointerBase() noexcept
Initialize smart pointer to nullptr.
vtkObjectBase * GetPointer() const
Get the contained pointer.
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkWeakPointerBase &p)
Compare smart pointer values.
#define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op)