0024645: Pointer to the last is wrong for a tree node
[occt.git] / src / PCollection / PCollection_HStack.gxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Standard_NoSuchObject.hxx>
16 #include <Standard_NotImplemented.hxx>
17 #include <Standard_NoMoreObject.hxx>
18
19 // ------------
20 // constructor
21 // -----------
22
23 PCollection_HStack::PCollection_HStack() 
24 {
25     TheDepth = 0;
26     TheTop = new PCollection_StackNode;
27 }
28
29 // ------------------------------------
30 // Push : insert an item on the top
31 // ------------------------------------
32 void PCollection_HStack::Push(const Item& T)
33 {   
34     TheTop = TheTop->Construct(T);
35     TheDepth = TheDepth + 1;
36           
37   }
38
39 // ------------------------------------
40 // Pop : remove an item from the top
41 // ------------------------------------
42 void PCollection_HStack::Pop()
43 {   
44     if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
45     Handle(PCollection_StackNode) temp = TheTop;
46     TheTop = TheTop->Tail();
47     temp.Delete();
48     TheDepth = TheDepth - 1;
49 }
50
51
52 // -----------------------------
53 // IsEmpty : is the stack empty ? 
54 // -----------------------------
55 Standard_Boolean PCollection_HStack::IsEmpty() const 
56 {
57     return TheTop->IsEmpty();
58
59
60 // ------------------------------------
61 // Clear : remove all items
62 // ------------------------------------
63 void PCollection_HStack::Clear() 
64 {   
65    Handle(PCollection_StackNode) temp; 
66    while (TheDepth != 0) {    
67       temp = TheTop;
68       TheTop = TheTop->Tail();
69       temp.Delete();
70       --TheDepth;
71    }  
72 }
73
74 // ------------------------------------
75 // ChangeTop : replace the top by T
76 // ------------------------------------
77 void PCollection_HStack::ChangeTop(const Item& T)
78 {   
79     if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
80     TheTop->SetValue(T);       
81 }
82
83 // -----------------------------
84 // Top : item on the Top 
85 // -----------------------------
86 Item PCollection_HStack::Top() const 
87 {
88     if (TheTop->IsEmpty()) Standard_NoSuchObject::Raise();
89     return TheTop->Value();
90
91
92
93 // ------------------------------------
94 // ShallowCopy redefinition
95 // ------------------------------------
96 Handle(Standard_Persistent) PCollection_HStack::ShallowCopy() const
97 {
98   PCollection_HStack* TheCopy = new PCollection_HStack (*this);
99   TheCopy->TheTop = 
100     Handle(PCollection_StackNode)::DownCast(::ShallowCopy(TheTop));
101   return TheCopy;
102 }
103
104 // ------------------------------------
105 // ShallowDump redefinition
106 // ------------------------------------
107 void PCollection_HStack::ShallowDump(Standard_OStream& S) const
108 {
109   S << "begin class Stack "<< endl;
110   S << "Length of Stack : "<< TheDepth << endl;
111   TheTop->ShallowDump(S);
112   S << "end of class Stack." << endl;
113 }
114
115
116
117 // -----------------------------
118 // Depth : numbers of items 
119 // -----------------------------
120 Standard_Integer PCollection_HStack::Depth() const {
121     return TheDepth;
122
123
124 // -----------------------------
125 // FTop : Top of the Stack  
126 // -----------------------------
127 Handle(PCollection_StackNode) PCollection_HStack::FTop() const {
128     return TheTop;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178