18 #ifndef itkPreOrderTreeIterator_h
19 #define itkPreOrderTreeIterator_h
26 template<
typename TTreeType >
29 template<
typename TTreeType >
68 template<
typename TTreeType >
74 template<
typename TTreeType >
82 template<
typename TTreeType >
86 if ( const_cast< TreeNodeType * >( FindNextNode() ) !=
nullptr )
95 template<
typename TTreeType >
99 this->m_Position =
const_cast< TreeNodeType *
>( FindNextNode() );
100 if ( this->m_Position ==
nullptr )
102 return this->m_Root->Get();
104 return this->m_Position->Get();
109 template<
typename TTreeType >
113 if ( this->m_Position ==
nullptr )
117 if ( this->m_Position->HasChildren() )
119 return dynamic_cast< const TreeNodeType *
>( this->m_Position->GetChild(0) );
123 if ( !this->m_Position->HasParent() )
131 while ( parent->HasParent() )
134 parent =
dynamic_cast< TreeNodeType *
>( parent->GetParent() );
137 if ( parent->ChildPosition(this->m_Root) >= 0 )
142 int childPosition = parent->ChildPosition(child);
143 int lastChildPosition = parent->CountChildren() - 1;
145 while ( childPosition < lastChildPosition )
147 auto * help =
dynamic_cast< TreeNodeType *
>( parent->GetChild(childPosition + 1) );
149 if ( help !=
nullptr )
160 template<
typename TTreeType >
typename TTreeType::ValueType ValueType
NodeType GetType() const override
const ValueType & Next() override
typename Superclass::TreeNodeType TreeNodeType
PreOrderTreeIterator(const TTreeType *tree, const TreeNodeType *start=nullptr)
const TreeNodeType * FindNextNode() const
typename Superclass::NodeType NodeType
This class provides the base implementation for tree iterators.
typename TTreeType::TreeNodeType TreeNodeType
TreeIteratorBase< TTreeType > * Clone() override
bool HasNext() const override