itkTreeIteratorClone.h
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 R>
00091 bool operator == ( R r ) const
00092 { return (m_Pointer == (ObjectType*)(r) ); }
00093
00094 template <typename R>
00095 bool operator != ( R 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 ++(*m_Pointer);
00141 return *this;
00142 }
00143
00144 const Self
00145 operator++(int)
00146 {
00147 if(m_Pointer)
00148 {
00149 const Self oldValue( m_Pointer );
00150 ++(*m_Pointer);
00151 return oldValue;
00152 }
00153 }
00154
00156 ObjectType *Print (std::ostream& os) const
00157 {
00158
00159 (*m_Pointer).Print(os);
00160 return m_Pointer;
00161 }
00163
00164 private:
00166 ObjectType* m_Pointer;
00167 };
00168
00169
00170 template <typename T>
00171 std::ostream& operator<< (std::ostream& os, TreeIteratorClone<T> p)
00172 {
00173 p.Print(os);
00174 return os;
00175 }
00176
00177 }
00178
00179 #endif
00180