Salome HOME
PR: last merge from BR_V5_DEV
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_ChildNodeIterator.cxx
1 //  Copyright (C) 2007-2008  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.
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 // File:        SALOMEDSImpl_ChildNodeIterator.cxx
23 // Created:     Wed Jan 26 16:43:08 2000
24 // Author:      Denis PASCAL
25 //              <dp@dingox.paris1.matra-dtv.fr>
26 //
27 #include "SALOMEDSImpl_ChildNodeIterator.hxx"
28
29 #define ChildNodeIterator_UpToBrother \
30 { \
31     while (myNode && (myNode->Depth() > myFirstLevel) && myNode->myNext == NULL) \
32       myNode = myNode->myFather; \
33         if (myNode && (myNode->Depth() > myFirstLevel) && myNode->myFather != NULL) \
34           myNode = myNode->myNext; \
35         else \
36           myNode = NULL; \
37 }
38
39 //=======================================================================
40 //function : SALOMEDSImpl_ChildNodeIterator
41 //purpose  : 
42 //=======================================================================
43 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator()
44      : myFirstLevel(0)
45 {}
46
47 //=======================================================================
48 //function : SALOMEDSImpl_ChildNodeIterator
49 //purpose  : 
50 //=======================================================================
51
52 SALOMEDSImpl_ChildNodeIterator::SALOMEDSImpl_ChildNodeIterator (const SALOMEDSImpl_AttributeTreeNode* aNode,
53                                                                 const bool allLevels)
54 : myNode(aNode->myFirst),
55   myFirstLevel(allLevels ? aNode->Depth() : -1)
56 {}
57
58 //=======================================================================
59 //function : Initialize
60 //purpose  : 
61 //=======================================================================
62
63 void SALOMEDSImpl_ChildNodeIterator::Initialize(const SALOMEDSImpl_AttributeTreeNode* aNode,
64                                                 const bool allLevels)
65 {
66   myNode = aNode->myFirst;
67   myFirstLevel = allLevels ? aNode->Depth() : -1;
68 }
69
70 //=======================================================================
71 //function : Next
72 //purpose  : 
73 //=======================================================================
74
75 void SALOMEDSImpl_ChildNodeIterator::Next() 
76 {
77   if (myFirstLevel == -1) {
78     myNode = myNode->myNext;
79   }
80   else {
81     if (myNode->myFirst != NULL) myNode = myNode->myFirst;
82     else ChildNodeIterator_UpToBrother;
83   }
84 }
85
86 //=======================================================================
87 //function : NextBrother
88 //purpose  : 
89 //=======================================================================
90
91 void SALOMEDSImpl_ChildNodeIterator::NextBrother() 
92 {
93   if (myNode->myNext != NULL) myNode = myNode->myNext;
94   else ChildNodeIterator_UpToBrother;
95 }