KWStyle - itkTreeIteratorBase.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkTreeIteratorBase.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:48 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkTreeIteratorBase_h
18 #define __itkTreeIteratorBase_h
19
20 #include <itkTreeNode.h>
21
22 namespace itk {
23
24 /** \class TreeIteratorBase
25  *  \brief TreeIteratorBase class
26  * 
27  * This class provides the base implementation for tree iterators
28  */
29 template <class TTreeType>
30 class TreeIteratorBase
31 {
32 public: 
33   
34   /** Typedefs */
35   typedef TreeIteratorBase<TTreeType> Self;
36 TDA   typedef typename TTreeType::ValueType ValueType;
37 TDA   typedef typename TTreeType::TreeNodeType TreeNodeType;
38
39   /** Add an element to the tree */
40   virtual bool Add(ValueType element);
41
42   /** Add an element at a given position */
43   virtual bool Add(int position, ValueType element);
44
45   /** Add a subtree */
46   virtual bool Add(TTreeType& subTree);
47
48   /** Get a value */
49 SEM   virtual const ValueType& Get() const ;
50
51   /** Get the subtree */
52 SEM   virtual TTreeType* GetSubTree() const ;
53
54   /** Return true if the current node is a leaf */
55   virtual bool IsLeaf() const;
56   
57   /** Return true if the current node is a root */
58   virtual bool IsRoot() const;
59
60   /** Get the type of iterator */
61   virtual int GetType() const = 0;
62
63   /** Go to the specified child */
64   virtual bool GoToChild(int number = 0);
65   
66   /** Go to the parent */
67   virtual bool GoToParent( );
68
69   /** Set the current value of the node */
70   ValueType& Set( ValueType element);
71
72   /** Return true if the current node has a child */
73   virtual bool HasChild(int number = 0) const;
74
75   /** Return the current ChildPosition of an element */
76   virtual int ChildPosition(ValueType element) const;
77
78   /** Remove a child */
79   virtual bool RemoveChild(int number);
80
81   /** Count the number of children */
82   virtual int CountChildren() const;
83
84   /** Return true if the current node has a parent */
85   virtual bool HasParent() const;
86
87   /** Disconnect the tree */
88   virtual bool Disconnect();
89
90   /** Return a list of children */
91   virtual TreeIteratorBase<TTreeType>* Children();
92
93   /** Return a list of parents */
94   virtual TreeIteratorBase<TTreeType>* Parents();
95
96   /** Return a list of child */
97   virtual TreeIteratorBase<TTreeType>* GetChild(int number) const;
98
99   /** Count the number of nodes */
100   virtual int Count();
101
102   /** Remove the current node from the tree */
103   bool Remove();
104
105   /** Get the current node */
106   virtual TreeNodeType* GetNode();
107   virtual const TreeNodeType* GetNode() const;
108
109   /** Get the root */
110   TreeNodeType* &GetRoot();
111   const TreeNodeType* &GetRoot() const;
112   
113   /** Get the tree */
114   TTreeType* GetTree() const;
115
116   /** Return the first parent found */
117   const TreeNodeType* GetParent() const;
118
119   /** Move an iterator to the beginning of the tree */
120   void GoToBegin()
121     {
122     m_Position = m_Begin;
123     };
124
125   /** Move an iterator to the end of the tree. */
126   void GoToEnd()
127     {
128     m_Position = m_End;
129     };
130
131   /** Is the iterator at the beginning of the tree? */
132   bool IsAtBegin(void) const
133     {
134     return (m_Position == m_Begin);
135     }
136
137 LEN   /** Is the iterator at the end of the tree?. The iterator is at the end if it points to NULL*/
138   bool IsAtEnd(void) const
139     {
140     return (m_Position == m_End);
141     }
142
143   /** Clone the iterator */
144   virtual TreeIteratorBase<TTreeType>* Clone() = 0;
145
146   /** Enumerations */
147   enum{
148     UNDEFIND   = 0,
149     PREORDER   = 1,
150     INORDER    = 2,
151     POSTORDER  = 3,
152     LEVELORDER = 4,
153     CHILD   = 5,
154     ROOT     = 6,
155     LEAF     = 7
156 IND **};
157
158   /** operator++ */
159   Self &
160   operator++()
161 IND **{
162     this->Next();
163     return *this;
164 IND **}
165
166   /** operator = */
167   virtual Self& operator=(Self& iterator) 
168     {
169     m_Position = iterator.m_Position; 
170     m_Begin  = iterator.m_Begin;
171     m_End = iterator.m_End;
172     m_Root = iterator.m_Root;
173     m_Tree = iterator.m_Tree;
174     return *this;
175     }
176
177 protected:
178
179   /** Constructors */
180   TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
181   TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
182
183   mutable TreeNodeType* m_Position; // Current position of the iterator
184   mutable TreeNodeType* m_Begin;
185   mutable TreeNodeType* m_End;
186   const TreeNodeType* m_Root;
187   TTreeType* m_Tree;
188   int Count(TreeNodeType* node);
189
190   virtual bool HasNext() const = 0;
191   virtual const ValueType& Next() = 0;
192 };
193
194 //end namespace itk
195
196
197 #ifndef ITK_MANUAL_INSTANTIATION
198 #include "itkTreeIteratorBase.txx"
199 #endif
200
201
202 #endif
203

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:50PM
© Kitware Inc.