Orfeo Toolbox  3.16
itkTreeIteratorBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkTreeIteratorBase.h,v $
5  Language: C++
6  Date: $Date: 2009-06-14 11:55:05 $
7  Version: $Revision: 1.13 $
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 
41 template <class TTreeType>
43 {
44 public:
45 
48  typedef typename TTreeType::ValueType ValueType;
49  typedef typename TTreeType::TreeNodeType TreeNodeType;
50 
52  virtual bool Add(ValueType element);
53 
55  virtual bool Add(int position, ValueType element);
56 
58  virtual bool Add(TTreeType& subTree);
59 
61  virtual const ValueType& Get() const;
62 
64  virtual TTreeType* GetSubTree() const;
65 
67  virtual bool IsLeaf() const;
68 
70  virtual bool IsRoot() const;
71 
73  virtual int GetType() const = 0;
74 
76  virtual bool GoToChild(int number = 0);
77 
79  virtual bool GoToParent( );
80 
82  void Set(ValueType element);
83 
85  virtual bool HasChild(int number = 0) const;
86 
88  virtual int ChildPosition(ValueType element) const;
89 
91  virtual bool RemoveChild(int number);
92 
94  virtual int CountChildren() const;
95 
97  virtual bool HasParent() const;
98 
100  virtual bool Disconnect();
101 
104 
107 
109  virtual TreeIteratorBase<TTreeType>* GetChild(int number) const;
110 
112  virtual int Count();
113 
115  bool Remove();
116 
118  virtual TreeNodeType* GetNode();
119  virtual const TreeNodeType* GetNode() const;
120 
123  const TreeNodeType* GetRoot() const;
124 
126  TTreeType* GetTree() const;
127 
129  const TreeNodeType* GetParent() const;
130 
132  void GoToBegin()
133  {
135  }
136 
138  void GoToEnd()
139  {
140  m_Position = m_End;
141  }
142 
144  bool IsAtBegin(void) const
145  {
146  return (m_Position == m_Begin);
147  }
148 
151  bool IsAtEnd(void) const
152  {
153  return (m_Position == m_End);
154  }
155 
157  virtual TreeIteratorBase<TTreeType>* Clone() = 0;
158 
160  enum{
161  UNDEFIND = 0,
162  PREORDER = 1,
163  INORDER = 2,
166  CHILD = 5,
167  ROOT = 6,
168  LEAF = 7
169  };
170 
172  Self &
174  {
175  this->Next();
176  return *this;
177  }
179  void
181  {
182  // assert( !IsAtEnd() );
183  this->Next();
184  }
186  const Self & operator=(const Self& iterator)
187  {
188  m_Position = iterator.m_Position;
189  m_Begin = iterator.m_Begin;
190  m_End = iterator.m_End;
191  m_Root = iterator.m_Root;
192  m_Tree = iterator.m_Tree;
193  return *this;
194  }
195 
196  virtual ~TreeIteratorBase() {}
197 
198 protected:
199 
201  TreeIteratorBase( TTreeType* tree, const TreeNodeType* start);
202  TreeIteratorBase( const TTreeType* tree, const TreeNodeType* start);
203 
204  mutable TreeNodeType* m_Position; // Current position of the iterator
206  mutable TreeNodeType* m_End;
208  TTreeType* m_Tree;
209 
210  virtual bool HasNext() const = 0;
211  virtual const ValueType& Next() = 0;
212 };
213 
214 } //end namespace itk
215 
216 // Define instantiation macro for this template.
217 #define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, x, y) namespace itk { \
218  _(1(class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 x >)) \
219  namespace Templates { typedef TreeIteratorBase< ITK_TEMPLATE_1 x > \
220  TreeIteratorBase##y; } \
221  }
222 
223 #if ITK_TEMPLATE_EXPLICIT
224 # include "Templates/itkTreeIteratorBase+-.h"
225 #endif
226 
227 #if ITK_TEMPLATE_TXX
228 # include "itkTreeIteratorBase.txx"
229 #endif
230 
231 #endif

Generated at Sun Feb 3 2013 00:10:24 for Orfeo Toolbox with doxygen 1.8.1.1