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

itkTreeIteratorBase.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkTreeIteratorBase.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/07/29 21:45:16 $
00007   Version:   $Revision: 1.3 $
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 __itkTreeIteratorBase_h
00018 #define __itkTreeIteratorBase_h
00019 
00020 #include <itkTreeNode.h>
00021 
00022 namespace itk {
00023 
00029 template <class TTreeType>
00030 class TreeIteratorBase
00031 {
00032 public: 
00033   
00035   typedef TreeIteratorBase<TTreeType> Self;
00036   typedef typename TTreeType::ValueType ValueType;
00037   typedef typename TTreeType::TreeNodeType TreeNodeType;
00038 
00040   virtual bool Add(ValueType element);
00041 
00043   virtual bool Add(int position, ValueType element);
00044 
00046   virtual bool Add(TTreeType& subTree);
00047 
00049   virtual const ValueType& Get() const ;
00050 
00052   virtual TTreeType* GetSubTree() const ;
00053 
00055   virtual bool IsLeaf() const;
00056   
00058   virtual bool IsRoot() const;
00059 
00061   virtual int GetType() const = 0;
00062 
00064   virtual bool GoToChild(int number = 0);
00065   
00067   virtual bool GoToParent( );
00068 
00070   ValueType& Set( ValueType element);
00071 
00073   virtual bool HasChild(int number = 0) const;
00074 
00076   virtual int ChildPosition(ValueType element) const;
00077 
00079   virtual bool RemoveChild(int number);
00080 
00082   virtual int CountChildren() const;
00083 
00085   virtual bool HasParent() const;
00086 
00088   virtual bool Disconnect();
00089 
00091   virtual TreeIteratorBase<TTreeType>* Children();
00092 
00094   virtual TreeIteratorBase<TTreeType>* Parents();
00095 
00097   virtual TreeIteratorBase<TTreeType>* GetChild(int number) const;
00098 
00100   virtual int Count();
00101 
00103   bool Remove();
00104 
00106   virtual TreeNodeType* GetNode();
00107   virtual const TreeNodeType* GetNode() const;
00108 
00110   TreeNodeType* &GetRoot();
00111   const TreeNodeType* &GetRoot() const;
00112   
00114   TTreeType* GetTree() const;
00115 
00117   const TreeNodeType* GetParent() const;
00118 
00120   void GoToBegin()
00121     {
00122     m_Position = m_Begin;
00123     };
00124 
00126   void GoToEnd()
00127     {
00128     m_Position = m_End;
00129     };
00130 
00132   bool IsAtBegin(void) const
00133     {
00134     return (m_Position == m_Begin);
00135     }
00136 
00138   bool IsAtEnd(void) const
00139     {
00140     return (m_Position == m_End);
00141     }
00142 
00144   virtual TreeIteratorBase<TTreeType>* Clone() = 0;
00145 
00147   enum{
00148     UNDEFIND   = 0,
00149     PREORDER   = 1,
00150     INORDER    = 2,
00151     POSTORDER  = 3,
00152     LEVELORDER = 4,
00153     CHILD   = 5,
00154     ROOT     = 6,
00155     LEAF     = 7
00156   };
00157 
00159   Self &
00160   operator++()
00161   {
00162     this->Next();
00163     return *this;
00164   }
00165 
00167   virtual Self& operator=(Self& iterator) 
00168     {
00169     m_Position = iterator.m_Position; 
00170     m_Begin  = iterator.m_Begin;
00171     m_End = iterator.m_End;
00172     m_Root = iterator.m_Root;
00173     m_Tree = iterator.m_Tree;
00174     return *this;
00175     }
00176 
00177 protected:
00178 
00180   TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
00181   TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
00182 
00183   mutable TreeNodeType* m_Position; // Current position of the iterator
00184   mutable TreeNodeType* m_Begin;
00185   mutable TreeNodeType* m_End;
00186   const TreeNodeType* m_Root;
00187   TTreeType* m_Tree;
00188   int Count(TreeNodeType* node);
00189 
00190   virtual bool HasNext() const = 0;
00191   virtual const ValueType& Next() = 0;
00192 };
00193 
00194 } //end namespace itk
00195 
00196 
00197 #ifndef ITK_MANUAL_INSTANTIATION
00198 #include "itkTreeIteratorBase.txx"
00199 #endif
00200 
00201 
00202 #endif

Generated at Thu May 25 00:09:37 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000