0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / TDataStd / TDataStd_ChildNodeIterator.cxx
1 // Created on: 2000-01-26
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <TDataStd_ChildNodeIterator.ixx>
17
18 #define ChildNodeIterator_UpToBrother \
19 { \
20     while (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myNext == NULL) \
21       myNode = myNode->myFather; \
22         if (!myNode.IsNull() && (myNode->Depth() > myFirstLevel) && myNode->myFather != NULL) \
23           myNode = myNode->myNext; \
24         else \
25           myNode = NULL; \
26 }
27
28 //=======================================================================
29 //function : TDataStd_ChildNodeIterator
30 //purpose  : 
31 //=======================================================================
32
33 TDataStd_ChildNodeIterator::TDataStd_ChildNodeIterator()
34      : myFirstLevel(0)
35 {}
36
37 //=======================================================================
38 //function : TDataStd_ChildNodeIterator
39 //purpose  : 
40 //=======================================================================
41
42 TDataStd_ChildNodeIterator::TDataStd_ChildNodeIterator (const Handle(TDataStd_TreeNode)& aTreeNode,
43                                                         const Standard_Boolean allLevels)
44 : myNode(aTreeNode->myFirst),
45   myFirstLevel(allLevels ? aTreeNode->Depth() : -1)
46 {}
47
48 //=======================================================================
49 //function : Initialize
50 //purpose  : 
51 //=======================================================================
52
53 void TDataStd_ChildNodeIterator::Initialize(const Handle(TDataStd_TreeNode)& aTreeNode,
54                                             const Standard_Boolean allLevels)
55 {
56   myNode = aTreeNode->myFirst;
57   myFirstLevel = allLevels ? aTreeNode->Depth() : -1;
58 }
59
60 //=======================================================================
61 //function : Next
62 //purpose  : 
63 //=======================================================================
64
65 void TDataStd_ChildNodeIterator::Next() 
66 {
67   if (myFirstLevel == -1) {
68     myNode = myNode->myNext;
69   }
70   else {
71     if (myNode->myFirst != NULL) myNode = myNode->myFirst;
72     else ChildNodeIterator_UpToBrother;
73   }
74 }
75
76 //=======================================================================
77 //function : NextBrother
78 //purpose  : 
79 //=======================================================================
80
81 void TDataStd_ChildNodeIterator::NextBrother() 
82 {
83   if (myNode->myNext != NULL) myNode = myNode->myNext;
84   else ChildNodeIterator_UpToBrother;
85 }