VTK
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() : Object(0) {}
40 
45 
50 
55 
57 
61  vtkWeakPointerBase& operator=(vtkObjectBase* r);
62  vtkWeakPointerBase& operator=(const vtkWeakPointerBase& r);
64 
69  {
70  // Inline implementation so smart pointer comparisons can be fully
71  // inlined.
72  return this->Object;
73  }
74 
75 private:
76  friend class vtkObjectBaseToWeakPointerBaseFriendship;
77 
78 protected:
79 
80  // Initialize weak pointer to given object.
81  class NoReference {};
83 
84  // Pointer to the actual object.
86 };
87 
88 //----------------------------------------------------------------------------
89 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \
90  inline bool \
91  operator op (const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \
92  { \
93  return (static_cast<void*>(l.GetPointer()) op \
94  static_cast<void*>(r.GetPointer())); \
95  } \
96  inline bool \
97  operator op (vtkObjectBase* l, const vtkWeakPointerBase& r) \
98  { \
99  return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \
100  } \
101  inline bool \
102  operator op (const vtkWeakPointerBase& l, vtkObjectBase* r) \
103  { \
104  return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \
105  }
106 
115 
116 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR
117 
121 VTKCOMMONCORE_EXPORT ostream& operator << (ostream& os,
122  const vtkWeakPointerBase& p);
123 
124 #endif
125 // VTK-HeaderTest-Exclude: vtkWeakPointerBase.h
vtkObjectBase * Object
vtkObjectBase * GetPointer() const
Get the contained pointer.
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkWeakPointerBase &p)
Compare smart pointer values.
Non-templated superclass for vtkWeakPointer.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
vtkWeakPointerBase()
Initialize smart pointer to NULL.
#define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op)