VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkWeakPointerBase.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00024 #ifndef __vtkWeakPointerBase_h 00025 #define __vtkWeakPointerBase_h 00026 00027 #include "vtkCommonCoreModule.h" // For export macro 00028 #include "vtkObjectBase.h" 00029 00030 class vtkObjectBaseToWeakPointerBaseFriendship; 00031 00032 class VTKCOMMONCORE_EXPORT vtkWeakPointerBase 00033 { 00034 public: 00036 vtkWeakPointerBase() : Object(0) {} 00037 00039 vtkWeakPointerBase(vtkObjectBase* r); 00040 00042 vtkWeakPointerBase(const vtkWeakPointerBase& r); 00043 00045 ~vtkWeakPointerBase(); 00046 00048 00050 vtkWeakPointerBase& operator=(vtkObjectBase* r); 00051 vtkWeakPointerBase& operator=(const vtkWeakPointerBase& r); 00053 00055 00056 vtkObjectBase* GetPointer() const 00057 { 00058 // Inline implementation so smart pointer comparisons can be fully 00059 // inlined. 00060 return this->Object; 00061 } 00063 00064 private: 00065 friend class vtkObjectBaseToWeakPointerBaseFriendship; 00066 00067 protected: 00068 00069 // Initialize weak pointer to given object. 00070 class NoReference {}; 00071 vtkWeakPointerBase(vtkObjectBase* r, const NoReference&); 00072 00073 // Pointer to the actual object. 00074 vtkObjectBase* Object; 00075 }; 00076 00077 //---------------------------------------------------------------------------- 00078 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \ 00079 inline bool \ 00080 operator op (const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \ 00081 { \ 00082 return (static_cast<void*>(l.GetPointer()) op \ 00083 static_cast<void*>(r.GetPointer())); \ 00084 } \ 00085 inline bool \ 00086 operator op (vtkObjectBase* l, const vtkWeakPointerBase& r) \ 00087 { \ 00088 return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \ 00089 } \ 00090 inline bool \ 00091 operator op (const vtkWeakPointerBase& l, vtkObjectBase* r) \ 00092 { \ 00093 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \ 00094 } 00095 00096 00097 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(==) 00098 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(!=) 00099 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(<) 00100 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(<=) 00101 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(>) 00102 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(>=) 00104 00105 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR 00106 00108 00109 VTKCOMMONCORE_EXPORT ostream& operator << (ostream& os, 00110 const vtkWeakPointerBase& p); 00112 00113 #endif 00114 // VTK-HeaderTest-Exclude: vtkWeakPointerBase.h