1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
28 ************************************************************************/
30 #ifndef SVX_TREE_VISITOR_HXX
31 #define SVX_TREE_VISITOR_HXX
35 template< class ELEMENT
, class NODEINFO
, class PROCESSOR
>
39 TreeVisitor( NODEINFO _nodeInfo
)
40 :m_visitedRoot( false )
43 ,m_nodeInfo( _nodeInfo
)
47 void process( const ELEMENT
& _root
, PROCESSOR
& _processor
)
50 m_visitedRoot
= false;
53 _processor
.process( m_current
);
63 const NODEINFO m_nodeInfo
;
65 ::std::stack
< size_t > m_pathToCurrent
;
66 ::std::stack
< ELEMENT
> m_currentAncestors
;
69 template< class ELEMENT
, class NODEINFO
, class PROCESSOR
>
70 bool TreeVisitor
< ELEMENT
, NODEINFO
, PROCESSOR
>::do_step()
79 // can we step down from the current node?
80 size_t childCount
= m_nodeInfo
.childCount( m_current
);
83 m_currentAncestors
.push( m_current
);
84 m_current
= m_nodeInfo
.getChild( m_current
, 0 );
85 m_pathToCurrent
.push( 0 );
89 // is there a right sibling of the current node?
90 while ( !m_pathToCurrent
.empty() )
92 const ELEMENT
& currentParent
= m_currentAncestors
.top();
93 childCount
= m_nodeInfo
.childCount( currentParent
);
95 size_t currentChildPos
= m_pathToCurrent
.top();
96 if ( ++currentChildPos
< childCount
)
99 m_pathToCurrent
.top() = currentChildPos
;
100 m_current
= m_nodeInfo
.getChild( currentParent
, currentChildPos
);
104 // no there isn't => step up
105 m_currentAncestors
.pop();
106 m_pathToCurrent
.pop();
112 #endif // SVX_TREE_VISITOR_HXX