ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkTreeIteratorBase_h 00019 #define __itkTreeIteratorBase_h 00020 00021 #include "itkTreeNode.h" 00022 00023 namespace itk 00024 { 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 typedef typename TreeNodeType::ChildIdentifier ChildIdentifier; 00051 00053 typedef enum 00054 { 00055 UNDEFIND = 0, 00056 PREORDER = 1, 00057 INORDER = 2, 00058 POSTORDER = 3, 00059 LEVELORDER = 4, 00060 CHILD = 5, 00061 ROOT = 6, 00062 LEAF = 7 00063 } 00064 NodeType; 00065 00067 virtual bool Add(ValueType element); 00068 00070 virtual bool Add(int position, ValueType element); 00071 00073 virtual bool Add(TTreeType & subTree); 00074 00076 virtual const ValueType & Get() const; 00077 00079 virtual TTreeType * GetSubTree() const; 00080 00082 virtual bool IsLeaf() const; 00083 00085 virtual bool IsRoot() const; 00086 00088 virtual NodeType GetType() const = 0; 00089 00091 virtual bool GoToChild(ChildIdentifier number = 0); 00092 00094 virtual bool GoToParent(); 00095 00097 void Set(ValueType element); 00098 00100 virtual bool HasChild(int number = 0) const; 00101 00103 virtual int ChildPosition(ValueType element) const; 00104 00106 virtual bool RemoveChild(int number); 00107 00109 virtual int CountChildren() const; 00110 00112 virtual bool HasParent() const; 00113 00115 virtual bool Disconnect(); 00116 00118 virtual TreeIteratorBase< TTreeType > * Children(); 00119 00121 virtual TreeIteratorBase< TTreeType > * Parents(); 00122 00124 virtual TreeIteratorBase< TTreeType > * GetChild(int number) const; 00125 00127 virtual int Count(); 00128 00130 bool Remove(); 00131 00133 virtual TreeNodeType * GetNode(); 00134 00135 virtual const TreeNodeType * GetNode() const; 00136 00138 TreeNodeType * GetRoot(); 00139 00140 const TreeNodeType * GetRoot() const; 00141 00143 TTreeType * GetTree() const; 00144 00146 const TreeNodeType * GetParent() const; 00147 00149 void GoToBegin() { m_Position = m_Begin; } 00150 00152 void GoToEnd() { m_Position = m_End; } 00153 00155 bool IsAtBegin(void) const { return ( m_Position == m_Begin ); } 00156 00159 bool IsAtEnd(void) const { return ( m_Position == m_End ); } 00160 00162 virtual TreeIteratorBase< TTreeType > * Clone() = 0; 00163 00165 Self & 00166 operator++() 00167 { 00168 this->Next(); 00169 return *this; 00170 } 00172 00174 void 00175 operator++(int) 00176 { 00177 // itkAssertInDebugAndIgnoreInReleaseMacro( !IsAtEnd() ); 00178 this->Next(); 00179 } 00181 00183 const Self & operator=(const Self & iterator) 00184 { 00185 m_Position = iterator.m_Position; 00186 m_Begin = iterator.m_Begin; 00187 m_End = iterator.m_End; 00188 m_Root = iterator.m_Root; 00189 m_Tree = iterator.m_Tree; 00190 return *this; 00191 } 00192 00193 virtual ~TreeIteratorBase() {} 00194 protected: 00195 00197 TreeIteratorBase(TTreeType *tree, const TreeNodeType *start); 00198 TreeIteratorBase(const TTreeType *tree, const TreeNodeType *start); 00200 00201 mutable TreeNodeType *m_Position; // Current position of the iterator 00202 mutable TreeNodeType *m_Begin; 00203 mutable TreeNodeType *m_End; 00204 const TreeNodeType * m_Root; 00205 TTreeType * m_Tree; 00206 00207 virtual bool HasNext() const = 0; 00208 00209 virtual const ValueType & Next() = 0; 00210 }; 00211 } //end namespace itk 00212 00213 // Define instantiation macro for this template. 00214 #define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, TypeX, TypeY) \ 00215 namespace itk \ 00216 { \ 00217 _( 1 ( class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 TypeX > ) ) \ 00218 namespace Templates \ 00219 { \ 00220 typedef TreeIteratorBase< ITK_TEMPLATE_1 TypeX > \ 00221 TreeIteratorBase##TypeY; \ 00222 } \ 00223 } 00224 00225 #if ITK_TEMPLATE_EXPLICIT 00226 #include "Templates/itkTreeIteratorBase+-.h" 00227 #endif 00228 00229 #if ITK_TEMPLATE_TXX 00230 #include "itkTreeIteratorBase.hxx" 00231 #endif 00232 00233 #endif 00234