while ( do_step() )
_processor.process( m_current );
}
private: bool do_step();
private: bool m_visitedRoot;
ELEMENT m_root;
ELEMENT m_current; const NODEINFO m_nodeInfo;
::std::stack< size_t > m_pathToCurrent;
::std::stack< ELEMENT > m_currentAncestors;
};
template< class ELEMENT, class NODEINFO, class PROCESSOR > bool TreeVisitor< ELEMENT, NODEINFO, PROCESSOR >::do_step()
{ if ( !m_visitedRoot )
{
m_current = m_root;
m_visitedRoot = true; returntrue;
}
// can we step down from the current node?
size_t childCount = m_nodeInfo.childCount( m_current ); if ( childCount )
{
m_currentAncestors.push( m_current );
m_current = m_nodeInfo.getChild( m_current, 0 );
m_pathToCurrent.push( 0 ); returntrue;
}
// is there a right sibling of the current node? while ( !m_pathToCurrent.empty() )
{ const ELEMENT& currentParent = m_currentAncestors.top();
childCount = m_nodeInfo.childCount( currentParent );
size_t currentChildPos = m_pathToCurrent.top(); if ( ++currentChildPos < childCount )
{ // yes there is
m_pathToCurrent.top() = currentChildPos;
m_current = m_nodeInfo.getChild( currentParent, currentChildPos ); returntrue;
}
// no there isn't => step up
m_currentAncestors.pop();
m_pathToCurrent.pop();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.