Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_ChildNodeIterator.cxx
1 // File:        SALOMEDSImpl_ChildNodeIterator.cxx
2 // Created:     Wed Jan 26 16:43:08 2000
3 // Author:      Denis PASCAL
4 //              <dp@dingox.paris1.matra-dtv.fr>
5
6
7 #include <SALOMEDSImpl_ChildNodeIterator.hxx>
8
9 #define ChildNodeIterator_UpToBrother \
10 { \
11     while (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myNext == NULL) \
12       myNode = myNode->myFather; \
13         if (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myFather != NULL) \
14           myNode = myNode->myNext; \
15         else \
16           myNode = NULL; \
17 }
18
19 //=======================================================================
20 //function : SALOMEDSImpl_ChildNodeIterator
21 //purpose  : 
22 //=======================================================================
23 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator()
24      : myFirstLevel(0)
25 {}
26
27 //=======================================================================
28 //function : SALOMEDSImpl_ChildNodeIterator
29 //purpose  : 
30 //=======================================================================
31
32 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator (const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode,
33                                                                 const Standard_Boolean allLevels)
34 : myNode(aNode->myFirst),
35   myFirstLevel(allLevels ? aNode->Depth() : -1)
36 {}
37
38 //=======================================================================
39 //function : Initialize
40 //purpose  : 
41 //=======================================================================
42
43 void SALOMEDSImpl_ChildNodeIterator::Initialize(const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode,
44                                                 const Standard_Boolean allLevels)
45 {
46   myNode = aNode->myFirst;
47   myFirstLevel = allLevels ? aNode->Depth() : -1;
48 }
49
50 //=======================================================================
51 //function : Next
52 //purpose  : 
53 //=======================================================================
54
55 void SALOMEDSImpl_ChildNodeIterator::Next() 
56 {
57   if (myFirstLevel == -1) {
58     myNode = myNode->myNext;
59   }
60   else {
61     if (myNode->myFirst != NULL) myNode = myNode->myFirst;
62     else ChildNodeIterator_UpToBrother;
63   }
64 }
65
66 //=======================================================================
67 //function : NextBrother
68 //purpose  : 
69 //=======================================================================
70
71 void SALOMEDSImpl_ChildNodeIterator::NextBrother() 
72 {
73   if (myNode->myNext != NULL) myNode = myNode->myNext;
74   else ChildNodeIterator_UpToBrother;
75 }