Orfeo Toolbox  4.0
itkTreeIteratorBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkTreeIteratorBase_h
19 #define __itkTreeIteratorBase_h
20 
21 #include "itkTreeNode.h"
22 
23 namespace itk
24 {
41 template< typename TTreeType >
43 {
44 public:
45 
48  typedef typename TTreeType::ValueType ValueType;
49  typedef typename TTreeType::TreeNodeType TreeNodeType;
50  typedef typename TreeNodeType::ChildIdentifier ChildIdentifier;
51 
53  typedef enum
54  {
55  UNDEFIND = 0,
56  PREORDER = 1,
57  INORDER = 2,
58  POSTORDER = 3,
60  CHILD = 5,
61  ROOT = 6,
62  LEAF = 7
63  }
64  NodeType;
65 
67  virtual bool Add(ValueType element);
68 
70  virtual bool Add(int position, ValueType element);
71 
73  virtual bool Add(TTreeType & subTree);
74 
76  virtual const ValueType & Get() const;
77 
79  virtual TTreeType * GetSubTree() const;
80 
82  virtual bool IsLeaf() const;
83 
85  virtual bool IsRoot() const;
86 
88  virtual NodeType GetType() const = 0;
89 
91  virtual bool GoToChild(ChildIdentifier number = 0);
92 
94  virtual bool GoToParent();
95 
97  void Set(ValueType element);
98 
100  virtual bool HasChild(int number = 0) const;
101 
103  virtual int ChildPosition(ValueType element) const;
104 
106  virtual bool RemoveChild(int number);
107 
109  virtual int CountChildren() const;
110 
112  virtual bool HasParent() const;
113 
115  virtual bool Disconnect();
116 
119 
122 
124  virtual TreeIteratorBase< TTreeType > * GetChild(int number) const;
125 
127  virtual int Count();
128 
130  bool Remove();
131 
133  virtual TreeNodeType * GetNode();
134 
135  virtual const TreeNodeType * GetNode() const;
136 
138  TreeNodeType * GetRoot();
139 
140  const TreeNodeType * GetRoot() const;
141 
143  TTreeType * GetTree() const;
144 
146  const TreeNodeType * GetParent() const;
147 
150 
152  void GoToEnd() { m_Position = m_End; }
153 
155  bool IsAtBegin(void) const { return ( m_Position == m_Begin ); }
156 
159  bool IsAtEnd(void) const { return ( m_Position == m_End ); }
160 
162  virtual TreeIteratorBase< TTreeType > * Clone() = 0;
163 
165  Self &
167  {
168  this->Next();
169  return *this;
170  }
171 
173  void
175  {
176  // itkAssertInDebugAndIgnoreInReleaseMacro( !IsAtEnd() );
177  this->Next();
178  }
179 
181  Self & operator=(const Self & iterator)
182  {
183  if(this != &iterator)
184  {
185  m_Position = iterator.m_Position;
186  m_Begin = iterator.m_Begin;
187  m_End = iterator.m_End;
188  m_Root = iterator.m_Root;
189  m_Tree = iterator.m_Tree;
190  }
191  return *this;
192  }
193 
194  virtual ~TreeIteratorBase() {}
195 
196 protected:
197 
199  TreeIteratorBase(TTreeType *tree, const TreeNodeType *start);
200  TreeIteratorBase(const TTreeType *tree, const TreeNodeType *start);
201 
202  mutable TreeNodeType *m_Position; // Current position of the iterator
204  mutable TreeNodeType *m_End;
206  TTreeType * m_Tree;
207 
208  virtual bool HasNext() const = 0;
209 
210  virtual const ValueType & Next() = 0;
211 };
212 } //end namespace itk
213 
214 #ifndef ITK_MANUAL_INSTANTIATION
215 #include "itkTreeIteratorBase.hxx"
216 #endif
217 
218 #endif

Generated at Sat Mar 8 2014 15:39:11 for Orfeo Toolbox with doxygen 1.8.3.1