0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / TCollection / TCollection_List.gxx
CommitLineData
b311480e 1// Created on: 1992-12-17
2// Created by: Remi LEQUETTE
3// Copyright (c) 1992-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
7fd59977 17// Revised: Thu Jan 17 11:40:17 1995
18// By: Mireille MERCIEN
19
20
21#include <Standard_NoMoreObject.hxx>
22#include <Standard_NoSuchObject.hxx>
23
24//=======================================================================
25//function : TCollection_List
26//purpose :
27//=======================================================================
28
29TCollection_List::TCollection_List() :
30 myFirst(NULL),
31 myLast(NULL)
32{}
33
34//=======================================================================
35//function : TCollection_List
36//purpose :
37//=======================================================================
38
39TCollection_List::TCollection_List(const TCollection_List& Other) :
40 myFirst(NULL),
41 myLast(NULL)
42{
43 if (!Other.IsEmpty()) {
44// cout << "List copied : magic constructor"<<endl;
45 TCollection_ListIterator It(Other);
46 while (It.More()) {
47 Append(It.Value());
48 It.Next();
49 }
50 }
51}
52
53//=======================================================================
54//function : Assign
55//purpose :
56//=======================================================================
57
58void TCollection_List::Assign(const TCollection_List& Other)
59{
60 if (this != &Other) {
61 Clear();
62 TCollection_ListIterator It(Other);
63 while (It.More()) {
64 Append(It.Value());
65 It.Next();
66 }
67 }
68}
69
70//=======================================================================
71//function : Clear
72//purpose :
73//=======================================================================
74
75void TCollection_List::Clear()
76{
77 TCollection_ListNode* p = (TCollection_ListNode*) myFirst;
78 TCollection_ListNode* q;
79 while (p != NULL) {
80 q = p;
81 p = (TCollection_ListNode*)q->Next();
82 delete q;
83 }
84 myFirst = myLast = NULL;
85}
86
87//=======================================================================
88//function : Extent
89//purpose :
90//=======================================================================
91
92Standard_Integer TCollection_List::Extent() const
93{
94 Standard_Integer Size = 0;
95 TCollection_ListNode* p = (TCollection_ListNode*) myFirst;
96 while (p != NULL) {
97 Size++;
98 p = (TCollection_ListNode*)p->Next();
99 }
100 return Size;
101}
102
103
104//=======================================================================
105//function : Prepend
106//purpose :
107//=======================================================================
108
109void TCollection_List::Prepend(const Item& I)
110{
111 myFirst = new TCollection_ListNode(I,(TCollection_ListNode*)myFirst);
112 if (myLast == NULL) myLast = myFirst;
113}
114
115//=======================================================================
116//function : Prepend
117//purpose :
118//=======================================================================
119
120void TCollection_List::Prepend(const Item& I, TCollection_ListIterator& theIt)
121{
122 myFirst = new TCollection_ListNode(I,(TCollection_ListNode*)myFirst);
123
124 theIt.current = myFirst;
125 theIt.previous = NULL;
126
127 if (myLast == NULL) myLast = myFirst;
128
129}
130
131//=======================================================================
132//function : Prepend
133//purpose :
134//=======================================================================
135
136void TCollection_List::Prepend(TCollection_List& Other)
137{
138 if (!Other.IsEmpty()) {
139 ((TCollection_ListNode*)Other.myLast)->Next() = (TCollection_ListNode*)myFirst;
140 myFirst = Other.myFirst;
141 Other.myFirst = Other.myLast = NULL;
142 }
143}
144
145//=======================================================================
146//function : Append
147//purpose :
148//=======================================================================
149
150void TCollection_List::Append(const Item& I)
151{
152 TCollection_ListNode* p = new TCollection_ListNode(I,(TCollection_MapNode*)0L);
153
154 if (myFirst == NULL) {
155 myFirst = myLast = p;
156 }
157 else {
158 ((TCollection_ListNode*)myLast)->Next() = (TCollection_ListNode*)p;
159 myLast = p;
160 }
161}
162
163
164//=======================================================================
165//function : Append
166//purpose :
167//=======================================================================
168
169void TCollection_List::Append(const Item& I, TCollection_ListIterator& theIt)
170{
171 TCollection_ListNode* p = new TCollection_ListNode(I,(TCollection_MapNode*)0L);
172
173 theIt.current = p;
174 theIt.previous = myLast;
175
176 if (myFirst == NULL) {
177 myFirst = myLast = p;
178 }
179 else {
180 ((TCollection_ListNode*)myLast)->Next() = (TCollection_ListNode*)p;
181 myLast = p;
182 }
183}
184
185//=======================================================================
186//function : Append
187//purpose :
188//=======================================================================
189
190void TCollection_List::Append(TCollection_List& Other)
191{
192 if (!Other.IsEmpty()) {
193 if (IsEmpty()) {
194 myFirst = Other.myFirst;
195 myLast = Other.myLast;
196 }
197 else {
198 ((TCollection_ListNode*)myLast)->Next() = (TCollection_ListNode*)Other.myFirst;
199 myLast = Other.myLast;
200 }
201 Other.myLast = Other.myFirst = NULL;
202 }
203}
204
205//=======================================================================
206//function : First
207//purpose :
208//=======================================================================
209
210Item& TCollection_List::First() const
211{
212 Standard_NoSuchObject_Raise_if(myFirst == NULL,"List:First");
213 return ((TCollection_ListNode*) myFirst)->Value();
214}
215
216//=======================================================================
217//function : Last
218//purpose :
219//=======================================================================
220
221Item& TCollection_List::Last() const
222{
223 Standard_NoSuchObject_Raise_if(myLast == NULL,"List:Last");
224 return ((TCollection_ListNode*) myLast)->Value();
225}
226
227//=======================================================================
228//function : RemoveFirst
229//purpose :
230//=======================================================================
231
232void TCollection_List::RemoveFirst()
233{
234 if (myFirst == NULL) return;
235 TCollection_ListNode* p = (TCollection_ListNode*) myFirst;
236 myFirst = p->Next();
237 delete p;
238 if (myFirst == NULL) myLast = NULL;
239}
240
241//=======================================================================
242//function : Remove
243//purpose :
244//=======================================================================
245
246void TCollection_List::Remove(TCollection_ListIterator& It)
247{
248 Standard_NoSuchObject_Raise_if(!It.More(),
249 "TCollection_List::Remove");
250 if (It.previous == NULL) {
251 RemoveFirst();
252 It.current = myFirst;
253 }
254 else {
255 TCollection_ListNode* p = (TCollection_ListNode*)((TCollection_ListNode*) It.current)->Next();
256 ((TCollection_ListNode*)It.previous)->Next() = (TCollection_ListNode*)p;
257 delete ((TCollection_ListNode*) It.current);
258 It.current = p;
259 if (p == NULL) myLast = It.previous;
260 }
261}
262
263//=======================================================================
264//function : InsertBefore
265//purpose :
266//=======================================================================
267
268void TCollection_List::InsertBefore(const Item& I,
269 TCollection_ListIterator& It)
270{
271 Standard_NoSuchObject_Raise_if(!It.More(), "TCollection_List::InsertBefore");
272 if (It.previous == NULL) {
273 Prepend(I);
274 It.previous = myFirst;
275 }
276 else {
277 TCollection_ListNode* p = new TCollection_ListNode(I,(TCollection_ListNode*)It.current);
278 ((TCollection_ListNode*)It.previous)->Next() = (TCollection_ListNode*)p;
279 It.previous = p;
280 }
281}
282
283//=======================================================================
284//function : InsertBefore
285//purpose :
286//=======================================================================
287
288void TCollection_List::InsertBefore(TCollection_List& Other,
289 TCollection_ListIterator& It)
290{
291 Standard_NoSuchObject_Raise_if(!It.More(), "TCollection_List::InsertBefore");
292 if (!Other.IsEmpty()) {
293 if (It.previous == NULL) {
294 It.previous = Other.myLast;
295 Prepend(Other);
296 }
297 else {
298 ((TCollection_ListNode*)It.previous)->Next() = (TCollection_ListNode*)Other.myFirst;
299 ((TCollection_ListNode*)Other.myLast)->Next() = (TCollection_ListNode*)It.current;
300 It.previous = Other.myLast;
301 Other.myLast = Other.myFirst = NULL;
302 }
303 }
304}
305
306//=======================================================================
307//function : InsertAfter
308//purpose :
309//=======================================================================
310
311void TCollection_List::InsertAfter(const Item& I, TCollection_ListIterator& It)
312{
313 Standard_NoSuchObject_Raise_if(!It.More(),"TCollection_List::InsertAfter");
314
315 if (It.current == myLast)
316 Append(I);
317 else {
318 TCollection_ListNode* p = new TCollection_ListNode(I,((TCollection_ListNode*)It.current)->Next());
319 ((TCollection_ListNode*)It.current)->Next() = (TCollection_ListNode*)p;
320 }
321}
322
323//=======================================================================
324//function : InsertAfter
325//purpose :
326//=======================================================================
327
328void TCollection_List::InsertAfter(TCollection_List& Other,
329 TCollection_ListIterator& It)
330{
331 Standard_NoSuchObject_Raise_if(!It.More(),"TCollection_List::InsertAfter");
332
333 if (It.current == myLast)
334 Append(Other);
335 else if (!Other.IsEmpty()) {
336 ((TCollection_ListNode*)Other.myLast)->Next() = ((TCollection_ListNode*)It.current)->Next();
337 ((TCollection_ListNode*)It.current)->Next() = (TCollection_ListNode*)Other.myFirst;
338 Other.myLast = Other.myFirst = NULL;
339 }
340}
341
342
343//=======================================================================
344//function : TCollection_ListIterator
345//purpose :
346//=======================================================================
347
348void TCollection_ListIterator::Next()
349{
350 Standard_NoMoreObject_Raise_if(current == NULL,
351 "TCollection_ListIteratorOfList");
352 previous = current;
353 current = ((TCollection_ListNode*)previous)->Next();
354}
355
356//=======================================================================
357//function : Value
358//purpose :
359//=======================================================================
360
361Item& TCollection_ListIterator::Value() const
362{
363 Standard_NoSuchObject_Raise_if(current == NULL,
364 "TCollection_ListIteratorOfList");
365 return ((TCollection_ListNode*)current)->Value();
366}
367
368
369
370
371
372
373