1 #include "SUIT_DataObjectIterator.h"
3 SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot )
8 if ( myRoot && fromTrueRoot )
9 myRoot = myRoot->root();
11 myCurrent = myExtremeChild = myRoot;
14 SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
16 SUIT_DataObject* result = 0;
17 if ( obj && obj != myRoot )
18 result = obj->parent();
22 void SUIT_DataObjectIterator::operator++()
24 SUIT_DataObject* aNext = 0;
25 SUIT_DataObject* aParent = 0;
31 if ( myDetourType == DepthLeft || myDetourType == DepthRight )
33 //Depth detour algorithm
34 if ( myCurrent->myChildren.count() > 0 )
36 myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft );
42 aParent = parent( myCurrent );
45 myCurrent = 0; //the tree is passed completely
50 aParent->myChildren.find( myCurrent );
51 if ( myDetourType == DepthLeft )
52 myCurrent = aParent->myChildren.next();
54 myCurrent = aParent->myChildren.prev();
66 else if ( myDetourType == BreadthLeft || myDetourType == BreadthRight )
68 //Breadth detour algorithm
69 aNext = globalSibling( myCurrent, myDetourType == BreadthLeft );
73 for ( SUIT_DataObject* cur = myExtremeChild; cur && !myCurrent; cur = globalSibling( cur, myDetourType == BreadthLeft ) )
75 if ( cur->myChildren.count() > 0 )
77 myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft );
78 myCurrent = myExtremeChild;
89 SUIT_DataObject* SUIT_DataObjectIterator::current() const
94 int SUIT_DataObjectIterator::depth() const
96 return myCurrentLevel;
99 int SUIT_DataObjectIterator::detour() const
104 SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, bool next ) const
106 SUIT_DataObject* par;
108 if ( obj && ( par = parent( obj ) ) )
110 par->myChildren.find( obj );
111 if ( par->myChildren.next() )
112 return par->myChildren.current();
115 for ( ; par; par = globalSibling( par, next ) )
117 if ( par->myChildren.count() > 0 )
118 return extreme( par->myChildren, next );
127 SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const
130 return aList.getFirst();
132 return aList.getLast();
136 SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* root,
137 int start, int end, bool LeftToRight )
138 : SUIT_DataObjectIterator( root, LeftToRight ? BreadthLeft : BreadthRight )
140 myStartLevel = start;
144 myEndLevel = myStartLevel;
146 while ( current() && depth() < myStartLevel )
147 SUIT_DataObjectIterator::operator++();
150 void SUIT_DataObjectLevelIterator::operator++()
154 SUIT_DataObjectIterator::operator++();
155 if ( depth() > myEndLevel )