Salome HOME
Removed includes and libraries of OCC
[modules/kernel.git] / src / DF / DF_ChildIterator.cxx
1 #include "DF_ChildIterator.hxx"
2
3 using namespace std;
4
5
6 //Constructor
7 DF_ChildIterator::DF_ChildIterator(const DF_Label& theLabel, bool allLevels)
8   :_root(NULL), _current(NULL)
9 {
10   Init(theLabel, allLevels);
11 }
12
13 DF_ChildIterator::DF_ChildIterator()
14   :_root(NULL), _current(NULL)
15 {
16 }
17
18 DF_ChildIterator::~DF_ChildIterator() 
19 {
20   _root = NULL;
21   _current = NULL;
22 }
23
24 //Initializes the iterator
25 void DF_ChildIterator::Init(const DF_Label& theLabel, bool allLevels)
26 {
27   _root = theLabel._node;
28   _allLevels = allLevels;
29   if(_root) _current = _root->_firstChild;
30 }
31
32 //Returns a current Label
33 DF_Label DF_ChildIterator::Value()
34 {
35   return DF_Label(_current);
36 }
37
38 //Returns true if there is a current Label
39 bool DF_ChildIterator::More()
40 {
41   return bool(_current);
42 }
43
44 //Moves to the next Label
45 void DF_ChildIterator::Next()
46 {
47   if(!_allLevels) {
48     _current = _current->_next; //Move to the next brother
49     return;
50   }
51   else {
52     if(_current->_firstChild) { //Go down to the first child
53       _current = _current->_firstChild;
54     }
55     else {
56       if(_current->_next) { //Next Brother
57         _current = _current->_next;
58       }
59       else {
60         if(_current->_father && _current->_father != _root) {
61           DF_LabelNode *father = _current->_father;
62           _current = father->_next;
63           if(!_current) {
64             while(father && father != _root) {
65               father = father->_father;
66               if(father->_next) break;
67             } 
68             if(father == _root) father = NULL;
69             if(father) _current = father->_next;
70             else _current = NULL;
71           }
72         }
73         else {
74           _current = NULL; //We iterate the whole sub tree
75         }
76       }
77     }
78   }
79 }
80