b311480e |
1 | // Created on: 1991-05-29 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1991-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 | // <dp> |
22 | // Revised by: Mireille MERCIEN |
23 | // Sep,7 1992 |
24 | |
25 | #include <Standard_NoMoreObject.hxx> |
26 | #include <Standard_NoSuchObject.hxx> |
27 | |
28 | |
29 | //--------------------------------------------------------------------------- |
30 | // Constructor |
31 | //--------------------------------------------------------------------------- |
32 | PCollection_DepthFirstIterator:: |
33 | PCollection_DepthFirstIterator(const Handle(PCollection_Vertex)& V) |
34 | { |
35 | Visited = new PCollection_SetOfVertex; |
36 | Ready = new PCollection_StackOfVertex; |
37 | Visited->Add(V); |
38 | Ready->Push(V); |
39 | HasMore = ! (Ready->IsEmpty()); |
40 | } |
41 | |
42 | //--------------------------------------------------------------------------- |
43 | // More |
44 | //--------------------------------------------------------------------------- |
45 | Boolean PCollection_DepthFirstIterator::More () const |
46 | { |
47 | return HasMore; |
48 | } |
49 | |
50 | //--------------------------------------------------------------------------- |
51 | // Next |
52 | //--------------------------------------------------------------------------- |
53 | void PCollection_DepthFirstIterator::Next () |
54 | { |
55 | if (!HasMore) Standard_NoMoreObject::Raise(); |
56 | Handle(PCollection_Vertex) w1 = Ready->Top(); |
57 | Ready->Pop(); |
58 | PCollection_FrontEdgesIterator It(w1); |
59 | while (It.More()) { |
60 | Handle(PCollection_Vertex) w2 = It.Value()->Destination(); |
61 | if (! (Visited->Contains(w2))) { |
62 | Ready->Push(w2); |
63 | Visited->Add(w2); |
64 | } |
65 | It.Next(); |
66 | } |
67 | HasMore = !(Ready->IsEmpty()); |
68 | } |
69 | |
70 | //--------------------------------------------------------------------------- |
71 | // Value |
72 | //--------------------------------------------------------------------------- |
73 | Handle(PCollection_Vertex) PCollection_DepthFirstIterator::Value () const |
74 | { |
75 | if (HasMore) |
76 | return Ready->Top(); |
77 | else |
78 | Standard_NoSuchObject::Raise(); |
79 | } |
80 | |
81 | //--------------------------------------------------------------------------- |
82 | // Clear |
83 | //--------------------------------------------------------------------------- |
84 | void PCollection_DepthFirstIterator::Clear () |
85 | { |
86 | HasMore = False; |
87 | Ready->Nullify(); |
88 | Visited->Nullify(); |
89 | } |