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
00045 if(p.m_Pointer != NULL)
00046 {
00047 m_Pointer = p.m_Pointer->Clone();
00048 }
00049 }
00050
00052 TreeIteratorClone (ObjectType *p)
00053 {
00054 m_Pointer = 0;
00055 if(p!=NULL)
00056 {
00057 m_Pointer=p->Clone();
00058 }
00059 }
00061
00063 TreeIteratorClone (const ObjectType &p)
00064 {
00065 m_Pointer = 0;
00066 m_Pointer=const_cast<ObjectType*>(&p)->Clone();
00067 }
00069
00071 ~TreeIteratorClone ()
00072 {
00073 delete m_Pointer;
00074 m_Pointer = 0;
00075 }
00076
00078 ObjectType *operator -> () const
00079 { return m_Pointer; }
00080
00082 bool IsNotNull() const
00083 { return m_Pointer != 0; }
00084 bool IsNull() const
00085 { return m_Pointer == 0; }
00087
00089 template <typename R>
00090 bool operator == ( R r ) const
00091 { return (m_Pointer == (ObjectType*)(r) ); }
00092
00093 template <typename R>
00094 bool operator != ( R r ) const
00095 { return (m_Pointer != (ObjectType*)(r) ); }
00096
00098 ObjectType *GetPointer () const
00099 { return m_Pointer; }
00100
00102 bool operator < (const TreeIteratorClone &r) const
00103 { return (void*)m_Pointer < (void*) r.m_Pointer; }
00104
00106 bool operator > (const TreeIteratorClone &r) const
00107 { return (void*)m_Pointer > (void*) r.m_Pointer; }
00108
00110 bool operator <= (const TreeIteratorClone &r) const
00111 { return (void*)m_Pointer <= (void*) r.m_Pointer; }
00112
00114 bool operator >= (const TreeIteratorClone &r) const
00115 { return (void*)m_Pointer >= (void*) r.m_Pointer; }
00116
00118 TreeIteratorClone &operator = (const TreeIteratorClone &r)
00119 { return this->operator = (r.GetPointer()); }
00120
00122 TreeIteratorClone &operator = (const ObjectType *r)
00123 {
00124 if (m_Pointer != r)
00125 {
00126 delete m_Pointer;
00127 m_Pointer = 0;
00128 if(r!=NULL)
00129 m_Pointer=const_cast<ObjectType*>(r)->Clone();
00130 }
00131 return *this;
00132 }
00134
00135 Self &
00136 operator++()
00137 {
00138 if(m_Pointer)
00139 ++(*m_Pointer);
00140 return *this;
00141 }
00142
00144 ObjectType *Print (std::ostream& os) const
00145 {
00146
00147 (*m_Pointer).Print(os);
00148 return m_Pointer;
00149 }
00151
00152 private:
00154 ObjectType* m_Pointer;
00155 };
00156
00157
00158 template <typename T>
00159 std::ostream& operator<< (std::ostream& os, TreeIteratorClone<T> p)
00160 {
00161 p.Print(os);
00162 return os;
00163 }
00164
00165 }
00166
00167 #endif
00168