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: 2008-01-29 15:27:42 $
00007   Version:   $Revision: 1.10 $
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                    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;
00109 
00111   TreeNodeType* GetRoot();
00112   const TreeNodeType* GetRoot() const;
00114 
00116   TTreeType* GetTree() const;
00117 
00119   const TreeNodeType* GetParent() const;
00120 
00122   void GoToBegin()
00123     {
00124     m_Position = m_Begin;
00125     };
00126 
00128   void GoToEnd()
00129     {
00130     m_Position = m_End;
00131     };
00132 
00134   bool IsAtBegin(void) const
00135     {
00136     return (m_Position == m_Begin);
00137     }
00138 
00140   bool IsAtEnd(void) const
00141     {
00142     return (m_Position == m_End);
00143     }
00144 
00146   virtual TreeIteratorBase<TTreeType>* Clone() = 0;
00147 
00149   enum{
00150     UNDEFIND   = 0,
00151     PREORDER   = 1,
00152     INORDER    = 2,
00153     POSTORDER  = 3,
00154     LEVELORDER = 4,
00155     CHILD   = 5,
00156     ROOT     = 6,
00157     LEAF     = 7
00158   };
00159 
00161   Self &
00162   operator++()
00163   {
00164     this->Next();
00165     return *this;
00166   }
00168 
00170   const Self & operator=(const Self& iterator) 
00171     {
00172     m_Position = iterator.m_Position; 
00173     m_Begin  = iterator.m_Begin;
00174     m_End = iterator.m_End;
00175     m_Root = iterator.m_Root;
00176     m_Tree = iterator.m_Tree;
00177     return *this;
00178     }
00179 
00180   virtual ~TreeIteratorBase() {}
00181 protected:
00182 
00184   TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
00185   TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
00187 
00188   mutable TreeNodeType* m_Position; // Current position of the iterator
00189   mutable TreeNodeType* m_Begin;
00190   mutable TreeNodeType* m_End;
00191   const TreeNodeType* m_Root;
00192   TTreeType* m_Tree;
00193 
00194   virtual bool HasNext() const = 0;
00195   virtual const ValueType& Next() = 0;
00196 };
00197 
00198 } //end namespace itk
00199 
00200 // Define instantiation macro for this template.
00201 #define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, x, y) namespace itk { \
00202   _(1(class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 x >)) \
00203   namespace Templates { typedef TreeIteratorBase< ITK_TEMPLATE_1 x > \
00204                                                   TreeIteratorBase##y; } \
00205   }
00206 
00207 #if ITK_TEMPLATE_EXPLICIT
00208 # include "Templates/itkTreeIteratorBase+-.h"
00209 #endif
00210 
00211 #if ITK_TEMPLATE_TXX
00212 # include "itkTreeIteratorBase.txx"
00213 #endif
00214 
00215 #endif
00216 

Generated at Mon Apr 14 14:39:09 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000