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-06-20 20:28:54 $
00007   Version:   $Revision: 1.11 $
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 
00041 template <class TTreeType>
00042 class TreeIteratorBase
00043 {
00044 public: 
00045   
00047   typedef TreeIteratorBase                    Self;
00048   typedef typename TTreeType::ValueType       ValueType;
00049   typedef typename TTreeType::TreeNodeType    TreeNodeType;
00050 
00052   virtual bool Add(ValueType element);
00053 
00055   virtual bool Add(int position, ValueType element);
00056 
00058   virtual bool Add(TTreeType& subTree);
00059 
00061   virtual const ValueType& Get() const ;
00062 
00064   virtual TTreeType* GetSubTree() const;
00065 
00067   virtual bool IsLeaf() const;
00068 
00070   virtual bool IsRoot() const;
00071 
00073   virtual int GetType() const = 0;
00074 
00076   virtual bool GoToChild(int number = 0);
00077 
00079   virtual bool GoToParent( );
00080 
00082   void Set(ValueType element);
00083 
00085   virtual bool HasChild(int number = 0) const;
00086 
00088   virtual int ChildPosition(ValueType element) const;
00089 
00091   virtual bool RemoveChild(int number);
00092 
00094   virtual int CountChildren() const;
00095 
00097   virtual bool HasParent() const;
00098 
00100   virtual bool Disconnect();
00101 
00103   virtual TreeIteratorBase<TTreeType>* Children();
00104 
00106   virtual TreeIteratorBase<TTreeType>* Parents();
00107 
00109   virtual TreeIteratorBase<TTreeType>* GetChild(int number) const;
00110 
00112   virtual int Count();
00113 
00115   bool Remove();
00116 
00118   virtual TreeNodeType* GetNode();
00119   virtual const TreeNodeType* GetNode() const;
00121 
00123   TreeNodeType* GetRoot();
00124   const TreeNodeType* GetRoot() const;
00126 
00128   TTreeType* GetTree() const;
00129 
00131   const TreeNodeType* GetParent() const;
00132 
00134   void GoToBegin()
00135     {
00136     m_Position = m_Begin;
00137     };
00138 
00140   void GoToEnd()
00141     {
00142     m_Position = m_End;
00143     };
00144 
00146   bool IsAtBegin(void) const
00147     {
00148     return (m_Position == m_Begin);
00149     }
00150 
00152   bool IsAtEnd(void) const
00153     {
00154     return (m_Position == m_End);
00155     }
00156 
00158   virtual TreeIteratorBase<TTreeType>* Clone() = 0;
00159 
00161   enum{
00162     UNDEFIND   = 0,
00163     PREORDER   = 1,
00164     INORDER    = 2,
00165     POSTORDER  = 3,
00166     LEVELORDER = 4,
00167     CHILD   = 5,
00168     ROOT     = 6,
00169     LEAF     = 7
00170   };
00171 
00173   Self &
00174   operator++()
00175     {
00176     this->Next();
00177     return *this;
00178     }
00179 
00181   void
00182   operator++(int)
00183     {
00184     assert( !IsAtEnd() );
00185     this->Next();
00186     }
00187 
00189   const Self & operator=(const Self& iterator) 
00190     {
00191     m_Position = iterator.m_Position; 
00192     m_Begin  = iterator.m_Begin;
00193     m_End = iterator.m_End;
00194     m_Root = iterator.m_Root;
00195     m_Tree = iterator.m_Tree;
00196     return *this;
00197     }
00198 
00199   virtual ~TreeIteratorBase() {}
00200   
00201 protected:
00202 
00204   TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
00205   TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
00207 
00208   mutable TreeNodeType* m_Position; // Current position of the iterator
00209   mutable TreeNodeType* m_Begin;
00210   mutable TreeNodeType* m_End;
00211   const TreeNodeType* m_Root;
00212   TTreeType* m_Tree;
00213 
00214   virtual bool HasNext() const = 0;
00215   virtual const ValueType& Next() = 0;
00216 };
00217 
00218 } //end namespace itk
00219 
00220 // Define instantiation macro for this template.
00221 #define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, x, y) namespace itk { \
00222   _(1(class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 x >)) \
00223   namespace Templates { typedef TreeIteratorBase< ITK_TEMPLATE_1 x > \
00224                                                   TreeIteratorBase##y; } \
00225   }
00226 
00227 #if ITK_TEMPLATE_EXPLICIT
00228 # include "Templates/itkTreeIteratorBase+-.h"
00229 #endif
00230 
00231 #if ITK_TEMPLATE_TXX
00232 # include "itkTreeIteratorBase.txx"
00233 #endif
00234 
00235 #endif
00236 

Generated at Sat Feb 28 13:41:08 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000