Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkTreeIteratorClone.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkTreeIteratorClone.h,v $
00005   Language:  C++
00006   Date:      $Date: 2008-06-20 20:28:54 $
00007   Version:   $Revision: 1.2 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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 ); // create a copy of the iterator behind the pointer (Clone())
00150       ++(*m_Pointer);
00151       return oldValue;
00152       }
00153     }
00154    
00156   ObjectType *Print (std::ostream& os) const 
00157     { 
00158     // This prints the object pointed to by the pointer  
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 } // end namespace itk
00178   
00179 #endif
00180 

Generated at Tue Jul 29 22:59:50 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000