Salome HOME
Copyrights update
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_ChildNodeIterator.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 // File:        SALOMEDSImpl_ChildNodeIterator.cxx
21 // Created:     Wed Jan 26 16:43:08 2000
22 // Author:      Denis PASCAL
23 //              <dp@dingox.paris1.matra-dtv.fr>
24
25
26 #include <SALOMEDSImpl_ChildNodeIterator.hxx>
27
28 #define ChildNodeIterator_UpToBrother \
29 { \
30     while (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myNext == NULL) \
31       myNode = myNode->myFather; \
32         if (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myFather != NULL) \
33           myNode = myNode->myNext; \
34         else \
35           myNode = NULL; \
36 }
37
38 //=======================================================================
39 //function : SALOMEDSImpl_ChildNodeIterator
40 //purpose  : 
41 //=======================================================================
42 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator()
43      : myFirstLevel(0)
44 {}
45
46 //=======================================================================
47 //function : SALOMEDSImpl_ChildNodeIterator
48 //purpose  : 
49 //=======================================================================
50
51 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator (const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode,
52                                                                 const Standard_Boolean allLevels)
53 : myNode(aNode->myFirst),
54   myFirstLevel(allLevels ? aNode->Depth() : -1)
55 {}
56
57 //=======================================================================
58 //function : Initialize
59 //purpose  : 
60 //=======================================================================
61
62 void SALOMEDSImpl_ChildNodeIterator::Initialize(const Handle(SALOMEDSImpl_AttributeTreeNode)& aNode,
63                                                 const Standard_Boolean allLevels)
64 {
65   myNode = aNode->myFirst;
66   myFirstLevel = allLevels ? aNode->Depth() : -1;
67 }
68
69 //=======================================================================
70 //function : Next
71 //purpose  : 
72 //=======================================================================
73
74 void SALOMEDSImpl_ChildNodeIterator::Next() 
75 {
76   if (myFirstLevel == -1) {
77     myNode = myNode->myNext;
78   }
79   else {
80     if (myNode->myFirst != NULL) myNode = myNode->myFirst;
81     else ChildNodeIterator_UpToBrother;
82   }
83 }
84
85 //=======================================================================
86 //function : NextBrother
87 //purpose  : 
88 //=======================================================================
89
90 void SALOMEDSImpl_ChildNodeIterator::NextBrother() 
91 {
92   if (myNode->myNext != NULL) myNode = myNode->myNext;
93   else ChildNodeIterator_UpToBrother;
94 }