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: 2009-06-14 11:55:05 $
00007   Version:   $Revision: 1.13 $
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 
00153   bool IsAtEnd(void) const
00154     {
00155     return (m_Position == m_End);
00156     }
00157 
00159   virtual TreeIteratorBase<TTreeType>* Clone() = 0;
00160 
00162   enum{
00163     UNDEFIND   = 0,
00164     PREORDER   = 1,
00165     INORDER    = 2,
00166     POSTORDER  = 3,
00167     LEVELORDER = 4,
00168     CHILD   = 5,
00169     ROOT     = 6,
00170     LEAF     = 7
00171   };
00172 
00174   Self &
00175   operator++()
00176     {
00177     this->Next();
00178     return *this;
00179     }
00180 
00182   void
00183   operator++(int)
00184     {
00185     // assert( !IsAtEnd() );
00186     this->Next();
00187     }
00188 
00190   const Self & operator=(const Self& iterator) 
00191     {
00192     m_Position = iterator.m_Position; 
00193     m_Begin  = iterator.m_Begin;
00194     m_End = iterator.m_End;
00195     m_Root = iterator.m_Root;
00196     m_Tree = iterator.m_Tree;
00197     return *this;
00198     }
00199 
00200   virtual ~TreeIteratorBase() {}
00201   
00202 protected:
00203 
00205   TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
00206   TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
00208 
00209   mutable TreeNodeType* m_Position; // Current position of the iterator
00210   mutable TreeNodeType* m_Begin;
00211   mutable TreeNodeType* m_End;
00212   const TreeNodeType*   m_Root;
00213   TTreeType*            m_Tree;
00214 
00215   virtual bool HasNext() const = 0;
00216   virtual const ValueType& Next() = 0;
00217 };
00218 
00219 } //end namespace itk
00220 
00221 // Define instantiation macro for this template.
00222 #define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, x, y) namespace itk { \
00223   _(1(class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 x >)) \
00224   namespace Templates { typedef TreeIteratorBase< ITK_TEMPLATE_1 x > \
00225                                                   TreeIteratorBase##y; } \
00226   }
00227 
00228 #if ITK_TEMPLATE_EXPLICIT
00229 # include "Templates/itkTreeIteratorBase+-.h"
00230 #endif
00231 
00232 #if ITK_TEMPLATE_TXX
00233 # include "itkTreeIteratorBase.txx"
00234 #endif
00235 
00236 #endif
00237 

Generated at Tue Sep 15 05:10:36 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000