0024157: Parallelization of assembly part of BO
[occt.git] / src / PCollection / PCollection_ATPostOrderIterator.gxx
CommitLineData
b311480e 1// Created on: 1992-08-13
2// Created by: Mireille MERCIEN
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21#include <Standard_OutOfRange.hxx>
22#include <Standard_NoSuchObject.hxx>
23#include <Standard_NoMoreObject.hxx>
24
25// ----------------------------------------------------------------------
7fd59977 26// ----------------------------------------------------------------------
27
28// Purpose: Permits to iterate through an ArbitraryTree beginning by
29// the most left leave and its rightSibling, then upward to
30// its parent, ..
31// IF theTree is ( A (B (C D E)) F G (H (I J K)))
32// THEN it will read ( C D E B F I J K H G A)
33
34
35// --------
36// Create
37// --------
38PCollection_ATPostOrderIterator::
39 PCollection_ATPostOrderIterator
40 (const Handle(PCollection_HArbitraryTree)& ATree)
41{
42 CurrentStack = new PCollection_StackArbitraryTree;
43 if (ATree.IsNull()) {
44 HasMore = Standard_False;
45 }
46 else {
47 HasMore = Standard_True;
48 RecursiveAppend(ATree);
49 CurrentTree = CurrentStack->Top();
50 }
51}
52
53// --------
54// More
55// --------
56Standard_Boolean PCollection_ATPostOrderIterator::More () const
57{
58 return HasMore;
59}
60
61// --------
62// Value
63// --------
64Handle(PCollection_HArbitraryTree)
65 PCollection_ATPostOrderIterator::Value () const
66{
67 if (!HasMore) Standard_NoSuchObject::Raise();
68 return CurrentTree;
69}
70
71// --------
72// Clear
73// --------
74void PCollection_ATPostOrderIterator::Clear ()
75{
76 CurrentTree.Nullify();
77 CurrentStack.Nullify();
78 HasMore = Standard_False;
79}
80
81// --------
82// Next
83// --------
84void PCollection_ATPostOrderIterator::Next ()
85{
86 if (!HasMore) Standard_NoMoreObject::Raise();
87// ... removes the last tree
88 CurrentStack->Pop();
89 if (CurrentStack->IsEmpty()) {
90 HasMore = Standard_False;
91 }
92 else {
93// ... is there still someone on the right ?
94// ... if yes, go on to the right
95 Handle(PCollection_HArbitraryTree) Temp = CurrentTree->RightSibling();
96 if (!Temp.IsNull()) {
97 RecursiveAppend(Temp);
98 }
99 CurrentTree = CurrentStack->Top();
100 }
101}
102
103// PRIVATE TOOLS TO MANAGE CURRENTSTACK
104
105// --------
106// --------
107void PCollection_ATPostOrderIterator::RecursiveAppend (
108 const Handle(PCollection_HArbitraryTree)& ATree)
109{
110 CurrentStack->Push(ATree);
111// ... is there still some child ?
112 if ( !ATree->IsLeaf()) {
113 RecursiveAppend( ATree->Child(1));
114 }
115}
116
117
118
119
120
121