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