Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkWeakPointer_h
00018 #define __itkWeakPointer_h
00019
00020 #include "itkMacro.h"
00021 #include <iostream>
00022
00023 namespace itk
00024 {
00025
00042 template <class TObjectType>
00043 class ITK_EXPORT WeakPointer
00044 {
00045 public:
00047 typedef TObjectType ObjectType;
00048
00050 WeakPointer ()
00051 { m_Pointer = 0; }
00052
00054 WeakPointer (const WeakPointer<ObjectType> &p): m_Pointer(p.m_Pointer) {}
00055
00057 WeakPointer (ObjectType *p): m_Pointer(p) { }
00058
00060 ~WeakPointer ()
00061 { m_Pointer = 0; }
00062
00064 ObjectType *operator -> () const
00065 { return m_Pointer; }
00066
00068 operator ObjectType * () const
00069 { return m_Pointer; }
00070
00072 template <typename R>
00073 bool operator == (R r) const
00074 {
00075 return (m_Pointer == (ObjectType*)r);
00076 }
00077 template <typename R>
00078 bool operator != (R r) const
00079 {
00080 return (m_Pointer != (ObjectType*)r);
00081 }
00083
00085 ObjectType *GetPointer () const
00086 { return m_Pointer; }
00087
00089 bool operator < (const WeakPointer &r) const
00090 { return (void*)m_Pointer < (void*) r.m_Pointer; }
00091
00093 bool operator > (const WeakPointer &r) const
00094 { return (void*)m_Pointer > (void*) r.m_Pointer; }
00095
00097 bool operator <= (const WeakPointer &r) const
00098 { return (void*)m_Pointer <= (void*) r.m_Pointer; }
00099
00101 bool operator >= (const WeakPointer &r) const
00102 { return (void*)m_Pointer >= (void*) r.m_Pointer; }
00103
00105 WeakPointer &operator = (const WeakPointer &r)
00106 { return this->operator = (r.GetPointer()); }
00107
00109 WeakPointer &operator = (ObjectType *r)
00110 {
00111 m_Pointer = r;
00112 return *this;
00113 }
00114
00116 ObjectType *Print (std::ostream& os) const
00117 {
00118
00119 (*m_Pointer).Print(os);
00120 return m_Pointer;
00121 }
00123
00124 private:
00126 ObjectType* m_Pointer;
00127 };
00128
00129
00130 template <typename T>
00131 std::ostream& operator<< (std::ostream& os, WeakPointer<T> p)
00132 {
00133 p.Print(os);
00134 return os;
00135 }
00136
00137 }
00138
00139 #endif
00140