b311480e |
1 | // Created on: 1993-01-18 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-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 | |
22 | #include <Standard_NoSuchObject.hxx> |
23 | |
24 | //======================================================================= |
25 | //function : TCollection_Stack |
26 | //purpose : |
27 | //======================================================================= |
28 | |
29 | TCollection_Stack::TCollection_Stack() : |
30 | myTop(NULL), |
31 | myDepth(0) |
32 | { |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : TCollection_Stack |
37 | //purpose : |
38 | //======================================================================= |
39 | |
40 | TCollection_Stack::TCollection_Stack(const TCollection_Stack& Other) |
41 | { |
42 | if (!Other.IsEmpty()) { |
43 | cout << "WARNING copy constructor of non empty stack !"<<endl; |
44 | } |
45 | TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop; |
46 | TCollection_StackNode* q; |
47 | TCollection_StackNode* r = NULL; |
48 | myTop = NULL; |
49 | while (p) { |
50 | q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L); |
51 | if (r) r->Next() = q; |
52 | else myTop = q; |
53 | r = q; |
54 | p = (TCollection_StackNode*)p->Next(); |
55 | } |
56 | myDepth = Other.myDepth; |
57 | } |
58 | |
59 | //======================================================================= |
60 | //function : Assign |
61 | //purpose : |
62 | //======================================================================= |
63 | |
64 | const TCollection_Stack& TCollection_Stack::Assign |
65 | (const TCollection_Stack& Other) |
66 | { |
67 | if (this == &Other) return *this; |
68 | Clear(); |
69 | TCollection_StackNode* p = (TCollection_StackNode*) Other.myTop; |
70 | TCollection_StackNode* q; |
71 | TCollection_StackNode* r = NULL; |
72 | while (p) { |
73 | q = new TCollection_StackNode(p->Value(),(TCollection_MapNode*)0L); |
74 | if (r) r->Next() = q; |
75 | else myTop = q; |
76 | r = q; |
77 | p = (TCollection_StackNode*)p->Next(); |
78 | } |
79 | myDepth = Other.myDepth; |
80 | return *this; |
81 | } |
82 | |
83 | |
84 | //======================================================================= |
85 | //function : Top |
86 | //purpose : |
87 | //======================================================================= |
88 | |
89 | const Item& TCollection_Stack::Top() const |
90 | { |
91 | Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack"); |
92 | return ((TCollection_StackNode*)myTop)->Value(); |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Push |
97 | //purpose : |
98 | //======================================================================= |
99 | |
100 | void TCollection_Stack::Push(const Item& I) |
101 | { |
102 | myTop = new TCollection_StackNode(I,(TCollection_StackNode*)myTop); |
103 | myDepth++; |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : Pop |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | void TCollection_Stack::Pop() |
112 | { |
113 | Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack"); |
114 | TCollection_StackNode* p = (TCollection_StackNode*) myTop; |
115 | myTop = p->Next(); |
116 | delete p; |
117 | myDepth--; |
118 | } |
119 | |
120 | //======================================================================= |
121 | //function : Clear |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | void TCollection_Stack::Clear() |
126 | { |
127 | TCollection_StackNode* p = (TCollection_StackNode*) myTop; |
128 | TCollection_StackNode* q; |
129 | while(p) { |
130 | q = (TCollection_StackNode*)p->Next(); |
131 | delete p; |
132 | p = q; |
133 | } |
134 | myDepth = 0; |
135 | myTop = NULL; |
136 | } |
137 | |
138 | //======================================================================= |
139 | //function : ChangeTop |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | Item& TCollection_Stack::ChangeTop() |
144 | { |
145 | Standard_NoSuchObject_Raise_if(IsEmpty(),"TCollection_Stack"); |
146 | return ((TCollection_StackNode*)myTop)->Value(); |
147 | } |
148 | |
149 | //======================================================================= |
150 | //function : Next |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | void TCollection_StackIterator::Next() |
155 | { |
156 | current = ((TCollection_StackNode*)current)->Next(); |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : Value |
161 | //purpose : |
162 | //======================================================================= |
163 | |
164 | const Item& TCollection_StackIterator::Value() const |
165 | { |
166 | Standard_NoSuchObject_Raise_if(current == NULL, |
167 | "TCollection_StackIterator"); |
168 | return ((TCollection_StackNode*)current)->Value(); |
169 | } |