VTK  9.0.1
vtkWeakPointerBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkWeakPointerBase.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 =========================================================================*/
25 #ifndef vtkWeakPointerBase_h
26 #define vtkWeakPointerBase_h
27 
28 #include "vtkCommonCoreModule.h" // For export macro
29 #include "vtkObjectBase.h"
30 
31 class vtkObjectBaseToWeakPointerBaseFriendship;
32 
33 class VTKCOMMONCORE_EXPORT vtkWeakPointerBase
34 {
35 public:
39  vtkWeakPointerBase() noexcept : Object(nullptr) {}
40 
45 
50 
55 
60 
62 
66  vtkWeakPointerBase& operator=(vtkObjectBase* r);
67  vtkWeakPointerBase& operator=(const vtkWeakPointerBase& r);
68  vtkWeakPointerBase& operator=(vtkWeakPointerBase&& r) noexcept;
70 
75  {
76  // Inline implementation so smart pointer comparisons can be fully
77  // inlined.
78  return this->Object;
79  }
80 
81 private:
82  friend class vtkObjectBaseToWeakPointerBaseFriendship;
83 
84 protected:
85  // Initialize weak pointer to given object.
87  {
88  };
90 
91  // Pointer to the actual object.
93 };
94 
95 //----------------------------------------------------------------------------
96 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \
97  inline bool operator op(const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \
98  { \
99  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r.GetPointer())); \
100  } \
101  inline bool operator op(vtkObjectBase* l, const vtkWeakPointerBase& r) \
102  { \
103  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
104  } \
105  inline bool operator op(const vtkWeakPointerBase& l, vtkObjectBase* r) \
106  { \
107  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
108  }
109 
118 
119 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
120 
124 VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkWeakPointerBase& p);
125 
126 #endif
127 // VTK-HeaderTest-Exclude: vtkWeakPointerBase.h
vtkWeakPointerBase::Object
vtkObjectBase * Object
Definition: vtkWeakPointerBase.h:92
operator<<
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkWeakPointerBase &p)
Compare smart pointer values.
vtkObjectBase.h
VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
#define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op)
Definition: vtkWeakPointerBase.h:96
vtkWeakPointerBase::GetPointer
vtkObjectBase * GetPointer() const
Get the contained pointer.
Definition: vtkWeakPointerBase.h:74
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
vtkWeakPointerBase
Non-templated superclass for vtkWeakPointer.
Definition: vtkWeakPointerBase.h:33
vtkWeakPointerBase::NoReference
Definition: vtkWeakPointerBase.h:86
vtkWeakPointerBase::vtkWeakPointerBase
vtkWeakPointerBase() noexcept
Initialize smart pointer to nullptr.
Definition: vtkWeakPointerBase.h:39