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 __itkTreeIteratorClone_h
00018 #define __itkTreeIteratorClone_h
00019
00020 #include "itkMacro.h"
00021 #include <iostream>
00022
00023 namespace itk
00024 {
00025
00026 template <class TObjectType>
00027 class ITK_EXPORT TreeIteratorClone
00028 {
00029 public:
00030
00032 typedef TreeIteratorClone<TObjectType> Self;
00033 typedef TObjectType ObjectType;
00034
00036 TreeIteratorClone ()
00037 {
00038 m_Pointer = 0;
00039 }
00040
00042 TreeIteratorClone (const TreeIteratorClone<ObjectType> &p)
00043 {
00044 m_Pointer = 0;
00045 if(p.m_Pointer != NULL)
00046 {
00047 m_Pointer = p.m_Pointer->Clone();
00048 }
00049 }
00051
00053 TreeIteratorClone (ObjectType *p)
00054 {
00055 m_Pointer = 0;
00056 if(p!=NULL)
00057 {
00058 m_Pointer=p->Clone();
00059 }
00060 }
00062
00064 TreeIteratorClone (const ObjectType &p)
00065 {
00066 m_Pointer = 0;
00067 m_Pointer=const_cast<ObjectType*>(&p)->Clone();
00068 }
00070
00072 ~TreeIteratorClone ()
00073 {
00074 delete m_Pointer;
00075 m_Pointer = 0;
00076 }
00077
00079 ObjectType *operator -> () const
00080 { return m_Pointer; }
00081
00083 bool IsNotNull() const
00084 { return m_Pointer != 0; }
00085 bool IsNull() const
00086 { return m_Pointer == 0; }
00088
00090 template <typename TR>
00091 bool operator == ( TR r ) const
00092 { return (m_Pointer == (ObjectType*)(r) ); }
00093
00094 template <typename TR>
00095 bool operator != ( TR r ) const
00096 { return (m_Pointer != (ObjectType*)(r) ); }
00097
00099 ObjectType *GetPointer () const
00100 { return m_Pointer; }
00101
00103 bool operator < (const TreeIteratorClone &r) const
00104 { return (void*)m_Pointer < (void*) r.m_Pointer; }
00105
00107 bool operator > (const TreeIteratorClone &r) const
00108 { return (void*)m_Pointer > (void*) r.m_Pointer; }
00109
00111 bool operator <= (const TreeIteratorClone &r) const
00112 { return (void*)m_Pointer <= (void*) r.m_Pointer; }
00113
00115 bool operator >= (const TreeIteratorClone &r) const
00116 { return (void*)m_Pointer >= (void*) r.m_Pointer; }
00117
00119 TreeIteratorClone &operator = (const TreeIteratorClone &r)
00120 { return this->operator = (r.GetPointer()); }
00121
00123 TreeIteratorClone &operator = (const ObjectType *r)
00124 {
00125 if (m_Pointer != r)
00126 {
00127 delete m_Pointer;
00128 m_Pointer = 0;
00129 if(r!=NULL)
00130 m_Pointer=const_cast<ObjectType*>(r)->Clone();
00131 }
00132 return *this;
00133 }
00135
00136 Self &
00137 operator++()
00138 {
00139 if(m_Pointer)
00140 {
00141 ++(*m_Pointer);
00142 }
00143 return *this;
00144 }
00145
00146 const Self
00147 operator++(int)
00148 {
00149 if(m_Pointer)
00150 {
00151 const Self oldValue( m_Pointer );
00152 ++(*m_Pointer);
00153 return oldValue;
00154 }
00155 }
00156
00158 ObjectType *Print (std::ostream& os) const
00159 {
00160
00161 (*m_Pointer).Print(os);
00162 return m_Pointer;
00163 }
00165
00166 private:
00168 ObjectType* m_Pointer;
00169 };
00170
00171
00172 template <typename T>
00173 std::ostream& operator<< (std::ostream& os, TreeIteratorClone<T> p)
00174 {
00175 p.Print(os);
00176 return os;
00177 }
00178
00179 }
00180
00181 #endif
00182