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 "vtkObjectBase.h" 00028 00029 class vtkObjectBaseToWeakPointerBaseFriendship; 00030 00031 class VTK_COMMON_EXPORT vtkWeakPointerBase 00032 { 00033 public: 00035 vtkWeakPointerBase() : Object(0) {}; 00036 00038 vtkWeakPointerBase(vtkObjectBase* r); 00039 00041 vtkWeakPointerBase(const vtkWeakPointerBase& r); 00042 00044 ~vtkWeakPointerBase(); 00045 00047 00049 vtkWeakPointerBase& operator=(vtkObjectBase* r); 00050 vtkWeakPointerBase& operator=(const vtkWeakPointerBase& r); 00052 00054 00055 vtkObjectBase* GetPointer() const 00056 { 00057 // Inline implementation so smart pointer comparisons can be fully 00058 // inlined. 00059 return this->Object; 00060 } 00062 00063 private: 00064 friend class vtkObjectBaseToWeakPointerBaseFriendship; 00065 00066 protected: 00067 00068 // Initialize weak pointer to given object. 00069 class NoReference {}; 00070 vtkWeakPointerBase(vtkObjectBase* r, const NoReference&); 00071 00072 // Pointer to the actual object. 00073 vtkObjectBase* Object; 00074 }; 00075 00076 //---------------------------------------------------------------------------- 00077 #define VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(op) \ 00078 inline bool \ 00079 operator op (const vtkWeakPointerBase& l, const vtkWeakPointerBase& r) \ 00080 { \ 00081 return (static_cast<void*>(l.GetPointer()) op \ 00082 static_cast<void*>(r.GetPointer())); \ 00083 } \ 00084 inline bool \ 00085 operator op (vtkObjectBase* l, const vtkWeakPointerBase& r) \ 00086 { \ 00087 return (static_cast<void*>(l) op static_cast<void*>(r.GetPointer())); \ 00088 } \ 00089 inline bool \ 00090 operator op (const vtkWeakPointerBase& l, vtkObjectBase* r) \ 00091 { \ 00092 return (static_cast<void*>(l.GetPointer()) op static_cast<void*>(r)); \ 00093 } 00094 00095 00096 VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR(==) 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(>=) 00103 00104 #undef VTK_WEAK_POINTER_BASE_DEFINE_OPERATOR 00105 00107 00108 VTK_COMMON_EXPORT ostream& operator << (ostream& os, 00109 const vtkWeakPointerBase& p); 00111 00112 #endif