0
|
1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\euser\us_que.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "us_std.h"
|
|
19 |
|
|
20 |
EXPORT_C void TSglQueLink::Enque(TSglQueLink* aLink)
|
|
21 |
//
|
|
22 |
// Enque this after aLink.
|
|
23 |
//
|
|
24 |
{
|
|
25 |
|
|
26 |
iNext=aLink->iNext;
|
|
27 |
aLink->iNext=this;
|
|
28 |
}
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
EXPORT_C void TDblQueLinkBase::Enque(TDblQueLinkBase* aLink)
|
|
34 |
/**
|
|
35 |
Inserts this link object after the specified link object.
|
|
36 |
|
|
37 |
The specified link object must already be in the doubly linked list.
|
|
38 |
|
|
39 |
The function cannot be used to insert a list element into the beginning or
|
|
40 |
end of a doubly linked list; this is handled by the TDblQue::AddFirst()
|
|
41 |
and TDblQue::AddLast() functions.
|
|
42 |
|
|
43 |
@param aLink A pointer to the link object embedded within the list element
|
|
44 |
to which this link object is to be connected. It must not be NULL.
|
|
45 |
|
|
46 |
@see TDblQue
|
|
47 |
*/
|
|
48 |
{
|
|
49 |
|
|
50 |
iNext=aLink->iNext;
|
|
51 |
iPrev=aLink;
|
|
52 |
aLink->iNext->iPrev=this;
|
|
53 |
aLink->iNext=this;
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
EXPORT_C void TDblQueLinkBase::AddBefore(TDblQueLinkBase* aLink)
|
|
60 |
/**
|
|
61 |
Inserts this link object before the specified link object.
|
|
62 |
|
|
63 |
The specified link object must already be in the doubly linked list.
|
|
64 |
|
|
65 |
The function cannot be used to insert a list element into the beginning or
|
|
66 |
end of a doubly linked list; this is handled by the TDblQue::AddFirst()
|
|
67 |
and TDblQue::AddLast() functions.
|
|
68 |
|
|
69 |
@param aLink A pointer to the link object embedded within the list element
|
|
70 |
to which this link object is to be connected. It must not be NULL.
|
|
71 |
|
|
72 |
@see TDblQue
|
|
73 |
*/
|
|
74 |
{
|
|
75 |
|
|
76 |
iNext=aLink;
|
|
77 |
iPrev=aLink->iPrev;
|
|
78 |
aLink->iPrev->iNext=this;
|
|
79 |
aLink->iPrev=this;
|
|
80 |
}
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
EXPORT_C void TDblQueLink::Deque()
|
|
86 |
/**
|
|
87 |
Removes this link object from the doubly linked list.
|
|
88 |
|
|
89 |
In effect, this removes the list element that acts as host to this link object
|
|
90 |
from the doubly linked list.
|
|
91 |
|
|
92 |
The link object can be any in the doubly linked list.
|
|
93 |
|
|
94 |
It is safe to use this method on an object which has already been removed from the list.
|
|
95 |
|
|
96 |
@post iNext member is set to NULL
|
|
97 |
*/
|
|
98 |
{
|
|
99 |
|
|
100 |
if (iNext)
|
|
101 |
{
|
|
102 |
iPrev->iNext=iNext;
|
|
103 |
iNext->iPrev=iPrev;
|
|
104 |
iNext=NULL;
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
EXPORT_C TSglQueBase::TSglQueBase()
|
|
112 |
: iHead(NULL),iLast((TSglQueLink*)&iHead),iOffset(0)
|
|
113 |
/**
|
|
114 |
Default constructor.
|
|
115 |
|
|
116 |
It sets:
|
|
117 |
|
|
118 |
1. iHead to Null.
|
|
119 |
|
|
120 |
2. iLast to point to the head of queue.
|
|
121 |
|
|
122 |
3. iOffset to zero.
|
|
123 |
|
|
124 |
@see iHead
|
|
125 |
@see iLast
|
|
126 |
@see iOffset
|
|
127 |
*/
|
|
128 |
{}
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
EXPORT_C TSglQueBase::TSglQueBase(TInt aOffset)
|
|
134 |
: iHead(NULL),iLast((TSglQueLink*)&iHead),iOffset(aOffset)
|
|
135 |
/**
|
|
136 |
Constructor with specified offset.
|
|
137 |
|
|
138 |
It sets:
|
|
139 |
|
|
140 |
1. iHead to Null
|
|
141 |
|
|
142 |
2. iLast to point to the head of queue.
|
|
143 |
|
|
144 |
3. iOffset to the specified value.
|
|
145 |
|
|
146 |
@param aOffset The offset of a link object within an element.
|
|
147 |
|
|
148 |
@panic USER 75, if aOffset is not divisible by four
|
|
149 |
|
|
150 |
@see iHead
|
|
151 |
@see iLast
|
|
152 |
@see iOffset
|
|
153 |
*/
|
|
154 |
{
|
|
155 |
|
|
156 |
__ASSERT_ALWAYS(iOffset%4==0,Panic(ESQueOffsetNotAligned));
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
EXPORT_C TBool TSglQueBase::IsEmpty() const
|
|
163 |
/**
|
|
164 |
Tests whether the singly linked list is empty, i.e. has no list elements.
|
|
165 |
|
|
166 |
@return True, if the singly linked list is empty; false, otherwise.
|
|
167 |
*/
|
|
168 |
{
|
|
169 |
|
|
170 |
return(iHead==NULL);
|
|
171 |
}
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
EXPORT_C void TSglQueBase::SetOffset(TInt aOffset)
|
|
177 |
/**
|
|
178 |
Sets the offset of the link object from the start of a singly linked
|
|
179 |
list element.
|
|
180 |
|
|
181 |
@param aOffset The offset of the link object from the start of a singly linked
|
|
182 |
list element.
|
|
183 |
|
|
184 |
@panic USER 75, if aOffset is not divisible by four.
|
|
185 |
|
|
186 |
@see TSglQue
|
|
187 |
*/
|
|
188 |
{
|
|
189 |
|
|
190 |
__ASSERT_ALWAYS(iOffset%4==0,Panic(ESQueOffsetNotAligned));
|
|
191 |
iOffset=aOffset;
|
|
192 |
}
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
EXPORT_C void TSglQueBase::Reset()
|
|
199 |
/**
|
|
200 |
Empties the singly linked list.
|
|
201 |
|
|
202 |
After a call to this function, there are no elements queued from the header;
|
|
203 |
the elements are orphaned. Special care must be taken when list elements are
|
|
204 |
CBase derived objects, i.e. are allocated on the heap.
|
|
205 |
*/
|
|
206 |
{
|
|
207 |
|
|
208 |
iHead=NULL;
|
|
209 |
iLast=(TSglQueLink*)&iHead;
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
EXPORT_C void TSglQueBase::DoAddFirst(TAny* aPtr)
|
|
217 |
/**
|
|
218 |
Implements the insertion of a list element at the front of the singly linked
|
|
219 |
list.
|
|
220 |
|
|
221 |
This function is called by TSglQue::AddFirst().
|
|
222 |
|
|
223 |
@param aPtr An untyped pointer to the element to be inserted.
|
|
224 |
|
|
225 |
@see TSglQue::AddFirst
|
|
226 |
*/
|
|
227 |
{
|
|
228 |
|
|
229 |
TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
|
|
230 |
pL->Enque((TSglQueLink*)&iHead);
|
|
231 |
if (iLast==(TSglQueLink*)(&iHead))
|
|
232 |
iLast=pL;
|
|
233 |
}
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
EXPORT_C void TSglQueBase::DoAddLast(TAny* aPtr)
|
|
239 |
/**
|
|
240 |
Implements the insertion of a list element at the back of the singly linked
|
|
241 |
list.
|
|
242 |
|
|
243 |
This function is called by TSglQue::AddLast().
|
|
244 |
|
|
245 |
@param aPtr An untyped pointer to the element to be inserted.
|
|
246 |
|
|
247 |
@see TSglQue::AddLast
|
|
248 |
*/
|
|
249 |
{
|
|
250 |
|
|
251 |
TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
|
|
252 |
pL->Enque(iLast);
|
|
253 |
iLast=pL;
|
|
254 |
}
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
EXPORT_C void TSglQueBase::DoRemove(TAny* aPtr)
|
|
260 |
/**
|
|
261 |
Implements the removal of a list element from the singly linked list.
|
|
262 |
|
|
263 |
This function is called by TSglQue::Remove().
|
|
264 |
|
|
265 |
@param aPtr An untyped pointer to the element to be removed.
|
|
266 |
|
|
267 |
@see TSglQue::Remove
|
|
268 |
*/
|
|
269 |
{
|
|
270 |
|
|
271 |
TSglQueLink* pP=(TSglQueLink*)(&iHead);
|
|
272 |
TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
|
|
273 |
TSglQueLink* pN=pP->iNext;
|
|
274 |
while (pN)
|
|
275 |
{
|
|
276 |
if (pN==pL)
|
|
277 |
{
|
|
278 |
pP->iNext=pN->iNext;
|
|
279 |
if (iLast==pL)
|
|
280 |
{
|
|
281 |
iLast=pP;
|
|
282 |
if (iLast==NULL)
|
|
283 |
iLast=(TSglQueLink*)(&iHead);
|
|
284 |
}
|
|
285 |
return;
|
|
286 |
}
|
|
287 |
pP=pN;
|
|
288 |
pN=pP->iNext;
|
|
289 |
}
|
|
290 |
Panic(ESQueLinkNotQueued);
|
|
291 |
}
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
#pragma warning( disable : 4705 ) // statement has no effect
|
|
297 |
EXPORT_C TDblQueBase::TDblQueBase()
|
|
298 |
: iOffset(0)
|
|
299 |
/**
|
|
300 |
Default constructor.
|
|
301 |
|
|
302 |
It sets:
|
|
303 |
|
|
304 |
1. iHead to point to this object in both the forwards and backwards direction.
|
|
305 |
|
|
306 |
2. iOffset to zero.
|
|
307 |
|
|
308 |
@see iHead
|
|
309 |
@see iOffset
|
|
310 |
*/
|
|
311 |
{
|
|
312 |
|
|
313 |
iHead.iNext=iHead.iPrev=(&iHead);
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
EXPORT_C TDblQueBase::TDblQueBase(TInt aOffset)
|
|
320 |
: iOffset(aOffset)
|
|
321 |
/**
|
|
322 |
Constructor with specified offset.
|
|
323 |
|
|
324 |
It sets:
|
|
325 |
|
|
326 |
1. iHead to point to this object in both the forwards and backwards direction.
|
|
327 |
|
|
328 |
2. iOffset to the specified value.
|
|
329 |
|
|
330 |
@param aOffset The offset of a link object within an element.
|
|
331 |
|
|
332 |
@panic USER 78, if aOffset is not divisible by four
|
|
333 |
|
|
334 |
@see iHead
|
|
335 |
@see iOffset
|
|
336 |
*/
|
|
337 |
{
|
|
338 |
|
|
339 |
__ASSERT_ALWAYS(iOffset%4==0,Panic(ETQueOffsetNotAligned));
|
|
340 |
iHead.iNext=iHead.iPrev=(&iHead);
|
|
341 |
}
|
|
342 |
#pragma warning( default : 4705 )
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
EXPORT_C TBool TDblQueBase::IsEmpty() const
|
|
348 |
/**
|
|
349 |
Tests whether the doubly linked list is empty, i.e. has no list elements.
|
|
350 |
|
|
351 |
@return True, if the doubly linked list is empty; false, otherwise.
|
|
352 |
*/
|
|
353 |
{
|
|
354 |
|
|
355 |
return((const TDblQueLinkBase*)iHead.iNext==(&iHead));
|
|
356 |
}
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
EXPORT_C void TDblQueBase::SetOffset(TInt aOffset)
|
|
362 |
/**
|
|
363 |
Sets the offset of the link object from the start of a doubly linked list element.
|
|
364 |
|
|
365 |
@param aOffset The offset of the link object from the start of a doubly linked
|
|
366 |
list element.
|
|
367 |
|
|
368 |
@panic USER 78, if aOffset is not divisible by four.
|
|
369 |
|
|
370 |
@see TDblQue
|
|
371 |
*/
|
|
372 |
{
|
|
373 |
|
|
374 |
__ASSERT_ALWAYS(iOffset%4==0,Panic(ETQueOffsetNotAligned));
|
|
375 |
iOffset=aOffset;
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
EXPORT_C void TDblQueBase::Reset()
|
|
382 |
/**
|
|
383 |
Empties the doubly linked list.
|
|
384 |
|
|
385 |
After a call to this function, there are no elements queued from the header;
|
|
386 |
the elements are orphaned. Special care must be taken when list elements are
|
|
387 |
CBase derived objects, i.e. are allocated on the heap.
|
|
388 |
*/
|
|
389 |
{
|
|
390 |
|
|
391 |
iHead.iNext=iHead.iPrev=(&iHead);
|
|
392 |
}
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
EXPORT_C void TDblQueBase::DoAddFirst(TAny* aPtr)
|
|
398 |
/**
|
|
399 |
Implements the insertion of the specified list element at the front of the
|
|
400 |
doubly linked list.
|
|
401 |
|
|
402 |
This function is called by TDblQue::AddFirst().
|
|
403 |
|
|
404 |
@param aPtr An untyped pointer to the element to be inserted.
|
|
405 |
|
|
406 |
@see TDblQue::AddFirst
|
|
407 |
*/
|
|
408 |
{
|
|
409 |
|
|
410 |
PtrAdd((TDblQueLinkBase*)aPtr,iOffset)->Enque(&iHead);
|
|
411 |
}
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
EXPORT_C void TDblQueBase::DoAddLast(TAny* aPtr)
|
|
417 |
/**
|
|
418 |
Implements the insertion of the specified list element at the back of the
|
|
419 |
doubly linked list.
|
|
420 |
|
|
421 |
This function is called by TDblQue::AddLast().
|
|
422 |
|
|
423 |
@param aPtr An untyped pointer to the element to be inserted.
|
|
424 |
|
|
425 |
@see TDblQue::AddLast*/
|
|
426 |
{
|
|
427 |
|
|
428 |
PtrAdd((TDblQueLinkBase*)aPtr,iOffset)->Enque(iHead.iPrev);
|
|
429 |
}
|
|
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
EXPORT_C void TDblQueBase::DoAddPriority(TAny* aPtr)
|
|
435 |
/**
|
|
436 |
Implements the insertion of the specified list element in priority order.
|
|
437 |
|
|
438 |
This function is called by TPriQue::Add().
|
|
439 |
|
|
440 |
@param aPtr An untyped pointer to the element to be inserted.
|
|
441 |
|
|
442 |
@see TPriQue::Add
|
|
443 |
*/
|
|
444 |
{
|
|
445 |
|
|
446 |
TPriQueLink* pN=(TPriQueLink*)iHead.iNext;
|
|
447 |
TPriQueLink* pI=PtrAdd((TPriQueLink*)aPtr,iOffset);
|
|
448 |
TInt p=pI->iPriority;
|
|
449 |
while (pN!=(TPriQueLink*)&iHead && p<=pN->iPriority)
|
|
450 |
pN=(TPriQueLink*)pN->iNext;
|
|
451 |
pI->Enque(pN->iPrev);
|
|
452 |
}
|
|
453 |
|
|
454 |
|
|
455 |
|
|
456 |
|
|
457 |
EXPORT_C TDeltaQueBase::TDeltaQueBase()
|
|
458 |
: iFirstDelta(NULL)
|
|
459 |
/**
|
|
460 |
Default constructor.
|
|
461 |
|
|
462 |
It sets iFirstDelta to NULL.
|
|
463 |
|
|
464 |
@see TDeltaQueBase::iFirstDelta
|
|
465 |
*/
|
|
466 |
{
|
|
467 |
}
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
EXPORT_C TDeltaQueBase::TDeltaQueBase(TInt aOffset)
|
|
473 |
: TDblQueBase(aOffset),iFirstDelta(NULL)
|
|
474 |
/**
|
|
475 |
Constructor with specified offset.
|
|
476 |
|
|
477 |
It sets:
|
|
478 |
|
|
479 |
1. iFirstDelta to NULL
|
|
480 |
|
|
481 |
2. TDblQueBase::iOffset to the specified value, through a call to the
|
|
482 |
base class constructor.
|
|
483 |
|
|
484 |
@param aOffset The offset of a link object within an element.
|
|
485 |
|
|
486 |
@see TDeltaQueBase::iFirstDelta
|
|
487 |
@see TDblQueBase::iOffset
|
|
488 |
*/
|
|
489 |
{
|
|
490 |
}
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
EXPORT_C void TDeltaQueBase::Reset()
|
|
496 |
/**
|
|
497 |
Empties the doubly linked list, and resets the first delta pointer.
|
|
498 |
*/
|
|
499 |
{
|
|
500 |
|
|
501 |
TDblQueBase::Reset();
|
|
502 |
iFirstDelta=NULL;
|
|
503 |
}
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
|
508 |
EXPORT_C TBool TDeltaQueBase::FirstDelta(TInt& aValue)
|
|
509 |
/**
|
|
510 |
Gets the delta value of the first list element.
|
|
511 |
|
|
512 |
@param aValue On return, contsins the delta value of the first element.
|
|
513 |
Note that this remains unchanged if there is no first element.
|
|
514 |
|
|
515 |
@return True, if there is a first element; false, otherwise.
|
|
516 |
*/
|
|
517 |
{
|
|
518 |
if (iFirstDelta)
|
|
519 |
{
|
|
520 |
aValue=*iFirstDelta;
|
|
521 |
return(ETrue);
|
|
522 |
}
|
|
523 |
return(EFalse);
|
|
524 |
}
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
|
529 |
EXPORT_C TBool TDeltaQueBase::CountDown()
|
|
530 |
/**
|
|
531 |
Decrements the delta value of the first element by one, and returns true if
|
|
532 |
the result is negative or zero.
|
|
533 |
|
|
534 |
@return True, if the resulting delta value is negative or zero; false, if
|
|
535 |
the value is positive, or there is no first element.
|
|
536 |
*/
|
|
537 |
{
|
|
538 |
|
|
539 |
return(CountDown(1));
|
|
540 |
}
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
|
545 |
EXPORT_C TBool TDeltaQueBase::CountDown(TInt aValue)
|
|
546 |
/**
|
|
547 |
Decrements the delta value of the first element by the specified value, and
|
|
548 |
returns true if the result is negative or zero.
|
|
549 |
|
|
550 |
@param aValue The amount by which the delta value is to be reduced.
|
|
551 |
|
|
552 |
@return True, if the resulting delta value is negative or zero; false, if the
|
|
553 |
value is positive, or there is no first element.
|
|
554 |
*/
|
|
555 |
{
|
|
556 |
|
|
557 |
if (iFirstDelta)
|
|
558 |
{
|
|
559 |
(*iFirstDelta)-=aValue;
|
|
560 |
if (*iFirstDelta<=0)
|
|
561 |
return(ETrue);
|
|
562 |
}
|
|
563 |
return(EFalse);
|
|
564 |
}
|
|
565 |
|
|
566 |
|
|
567 |
|
|
568 |
|
|
569 |
EXPORT_C void TDeltaQueBase::DoAddDelta(TAny* aPtr,TInt aDelta)
|
|
570 |
/**
|
|
571 |
Implements the addition of the specified list element into the list.
|
|
572 |
|
|
573 |
This function is called by TDeltaQue::Add().
|
|
574 |
|
|
575 |
@param aPtr Pointer to the list element to be inserted.
|
|
576 |
@param aDelta The 'distance' from the nominal zero point.
|
|
577 |
|
|
578 |
@see TDeltaQue::Add
|
|
579 |
*/
|
|
580 |
{
|
|
581 |
|
|
582 |
TDeltaQueLink* pD=(TDeltaQueLink*)iHead.iNext;
|
|
583 |
TDeltaQueLink* pI=PtrAdd((TDeltaQueLink*)aPtr,iOffset);
|
|
584 |
while (pD!=(TDeltaQueLink*)&iHead && aDelta>=pD->iDelta)
|
|
585 |
{
|
|
586 |
aDelta-=pD->iDelta;
|
|
587 |
pD=(TDeltaQueLink*)pD->iNext;
|
|
588 |
}
|
|
589 |
pI->iDelta=aDelta;
|
|
590 |
pI->Enque(pD->iPrev);
|
|
591 |
if (pI->iNext!=&iHead)
|
|
592 |
pD->iDelta-=aDelta;
|
|
593 |
iFirstDelta=(&((TDeltaQueLink*)iHead.iNext)->iDelta);
|
|
594 |
}
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
EXPORT_C void TDeltaQueBase::DoRemove(TAny* aPtr)
|
|
600 |
/**
|
|
601 |
Implements the removal of the specified list element from the list.
|
|
602 |
|
|
603 |
This function is called by TDeltaQue::Remove().
|
|
604 |
|
|
605 |
@param aPtr Pointer to the list element to be removed.
|
|
606 |
|
|
607 |
@see TDeltaQue::Remove
|
|
608 |
*/
|
|
609 |
{
|
|
610 |
|
|
611 |
TDeltaQueLink* pI=PtrAdd((TDeltaQueLink*)aPtr,iOffset);
|
|
612 |
TDeltaQueLink* pN=(TDeltaQueLink*)pI->iNext;
|
|
613 |
if (pN!=(TDeltaQueLink*)&iHead)
|
|
614 |
pN->iDelta+=pI->iDelta;
|
|
615 |
((TDblQueLink*)pI)->Deque();
|
|
616 |
iFirstDelta=(iHead.iNext!=(&iHead) ? &((TDeltaQueLink*)iHead.iNext)->iDelta : NULL);
|
|
617 |
}
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
EXPORT_C TAny* TDeltaQueBase::DoRemoveFirst()
|
|
623 |
/**
|
|
624 |
Implements the removal of the first list element from the linked list if its
|
|
625 |
delta value is zero or negative.
|
|
626 |
|
|
627 |
This function is called by TDeltaQue::RemoveFirst().
|
|
628 |
|
|
629 |
@return A pointer to the element removed from the linked list. This is NULL,
|
|
630 |
if the first element has a positive delta value.
|
|
631 |
|
|
632 |
@see TDeltaQue::RemoveFirst
|
|
633 |
*/
|
|
634 |
{
|
|
635 |
|
|
636 |
TDeltaQueLink* pN=(TDeltaQueLink*)iHead.iNext;
|
|
637 |
if (pN!=(TDeltaQueLink*)&iHead && pN->iDelta<=0)
|
|
638 |
{
|
|
639 |
pN=PtrSub(pN,iOffset);
|
|
640 |
DoRemove(pN);
|
|
641 |
return(pN);
|
|
642 |
}
|
|
643 |
return(NULL);
|
|
644 |
}
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
EXPORT_C TSglQueIterBase::TSglQueIterBase(TSglQueBase& aQue)
|
|
650 |
//
|
|
651 |
// Cosntructor.
|
|
652 |
//
|
|
653 |
: iOffset(aQue.iOffset),iHead((TSglQueLink*)&aQue.iHead),iNext(aQue.iHead)
|
|
654 |
{}
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
|
659 |
EXPORT_C void TSglQueIterBase::SetToFirst()
|
|
660 |
/**
|
|
661 |
Sets the iterator to point to the first element in the singly linked list.
|
|
662 |
|
|
663 |
The function can be called to re-set the pointer at any time during the iterator's
|
|
664 |
existence.
|
|
665 |
|
|
666 |
The function can be called even if the list has no elements.
|
|
667 |
*/
|
|
668 |
{
|
|
669 |
|
|
670 |
iNext=iHead->iNext;
|
|
671 |
}
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
|
676 |
EXPORT_C void TSglQueIterBase::DoSet(TAny* aLink)
|
|
677 |
//
|
|
678 |
// Start the iterator at aLink.
|
|
679 |
//
|
|
680 |
{
|
|
681 |
|
|
682 |
iNext=PtrAdd((TSglQueLink*)aLink,iOffset);
|
|
683 |
}
|
|
684 |
|
|
685 |
EXPORT_C TAny* TSglQueIterBase::DoPostInc()
|
|
686 |
//
|
|
687 |
// Return the current pointer and increment.
|
|
688 |
//
|
|
689 |
{
|
|
690 |
|
|
691 |
TAny* pN=iNext;
|
|
692 |
if (pN==NULL)
|
|
693 |
return NULL;
|
|
694 |
iNext=iNext->iNext;
|
|
695 |
return(PtrSub(pN,iOffset));
|
|
696 |
}
|
|
697 |
|
|
698 |
EXPORT_C TAny* TSglQueIterBase::DoCurrent()
|
|
699 |
//
|
|
700 |
// Return the current pointer.
|
|
701 |
//
|
|
702 |
{
|
|
703 |
|
|
704 |
return(iNext==NULL ? NULL : PtrSub((TAny*)iNext,iOffset));
|
|
705 |
}
|
|
706 |
|
|
707 |
|
|
708 |
|
|
709 |
|
|
710 |
EXPORT_C TDblQueIterBase::TDblQueIterBase(TDblQueBase& aQue)
|
|
711 |
: iOffset(aQue.iOffset),iHead(&aQue.iHead),iNext(aQue.iHead.iNext)
|
|
712 |
/**
|
|
713 |
Constructs the iterator for the specified doubly linked list.
|
|
714 |
|
|
715 |
@param aQue A reference to a doubly linked list header.
|
|
716 |
*/
|
|
717 |
{}
|
|
718 |
|
|
719 |
|
|
720 |
|
|
721 |
|
|
722 |
EXPORT_C void TDblQueIterBase::SetToFirst()
|
|
723 |
/**
|
|
724 |
Sets the iterator to point to the first element in the doubly linked list.
|
|
725 |
|
|
726 |
The function can be called to re-set the pointer at any time during the
|
|
727 |
iterator's existence.
|
|
728 |
|
|
729 |
The function can be called even if the list has no elements.
|
|
730 |
*/
|
|
731 |
{
|
|
732 |
|
|
733 |
iNext=iHead->iNext;
|
|
734 |
}
|
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
|
739 |
EXPORT_C void TDblQueIterBase::SetToLast()
|
|
740 |
/**
|
|
741 |
Sets the iterator to point to the last element in the doubly linked list. The
|
|
742 |
function can be called to re-set the pointer at any time during the
|
|
743 |
iterator's existence.
|
|
744 |
|
|
745 |
The function can be called even if the list has no elements.
|
|
746 |
*/
|
|
747 |
{
|
|
748 |
|
|
749 |
iNext=iHead->iPrev;
|
|
750 |
}
|
|
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
|
755 |
EXPORT_C void TDblQueIterBase::DoSet(TAny* aLink)
|
|
756 |
/**
|
|
757 |
Sets the iterator to point to a specific element in the list.
|
|
758 |
|
|
759 |
The function is an implementation for TDblQueIter::Set().
|
|
760 |
|
|
761 |
@param aLink A pointer to the current list element.
|
|
762 |
|
|
763 |
@see TDblQueIter::Set
|
|
764 |
*/
|
|
765 |
{
|
|
766 |
|
|
767 |
iNext=PtrAdd((TDblQueLinkBase*)aLink,iOffset);
|
|
768 |
}
|
|
769 |
|
|
770 |
|
|
771 |
|
|
772 |
|
|
773 |
EXPORT_C TAny* TDblQueIterBase::DoPostInc()
|
|
774 |
/**
|
|
775 |
Gets the current item and then moves to the next item.
|
|
776 |
|
|
777 |
The function is an implementation for TDblQueIter::operator++().
|
|
778 |
|
|
779 |
@return A pointer to the current list element.
|
|
780 |
|
|
781 |
@see TDblQueIter::operator++
|
|
782 |
*/
|
|
783 |
{
|
|
784 |
|
|
785 |
if (iNext==iHead)
|
|
786 |
return(NULL);
|
|
787 |
__ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
|
|
788 |
TAny* p=PtrSub(iNext,iOffset);
|
|
789 |
iNext=iNext->iNext;
|
|
790 |
return(p);
|
|
791 |
}
|
|
792 |
|
|
793 |
|
|
794 |
|
|
795 |
|
|
796 |
EXPORT_C TAny* TDblQueIterBase::DoPostDec()
|
|
797 |
/**
|
|
798 |
Gets the current item and then moves to the previous item.
|
|
799 |
|
|
800 |
The function is an implementation for TDblQueIter::operator--().
|
|
801 |
|
|
802 |
@return A pointer to the current list element.
|
|
803 |
|
|
804 |
@see TDblQueIter::operator--
|
|
805 |
*/
|
|
806 |
{
|
|
807 |
|
|
808 |
if (iNext==iHead)
|
|
809 |
return(NULL);
|
|
810 |
__ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
|
|
811 |
TAny* p=PtrSub(iNext,iOffset);
|
|
812 |
iNext=iNext->iPrev;
|
|
813 |
return(p);
|
|
814 |
}
|
|
815 |
|
|
816 |
|
|
817 |
|
|
818 |
|
|
819 |
EXPORT_C TAny* TDblQueIterBase::DoCurrent()
|
|
820 |
/**
|
|
821 |
Gets the current item in the queue.
|
|
822 |
|
|
823 |
The function is an implementation for TDblQueIter::operator T*().
|
|
824 |
|
|
825 |
@return A pointer to the current list element.
|
|
826 |
|
|
827 |
@see TDblQueIter::operator T*
|
|
828 |
*/
|
|
829 |
{
|
|
830 |
|
|
831 |
if (iNext==iHead)
|
|
832 |
return(NULL);
|
|
833 |
__ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
|
|
834 |
return(PtrSub(iNext,iOffset));
|
|
835 |
}
|
|
836 |
|
|
837 |
|
|
838 |
|
|
839 |
|
|
840 |
EXPORT_C void TDblQueBase::__DbgTestEmpty() const
|
|
841 |
/**
|
|
842 |
Tests whether the queue is empty.
|
|
843 |
|
|
844 |
The function is implemented as an __ASSERT_DEBUG.
|
|
845 |
|
|
846 |
@panic USER 79, if the assertion fails.
|
|
847 |
*/
|
|
848 |
{
|
|
849 |
|
|
850 |
__ASSERT_DEBUG((((TDblQueLink*)iHead.iNext)!=&iHead)&&(((TDblQueLink*)iHead.iPrev)!=&iHead),Panic(ETQueQueueEmpty));
|
|
851 |
}
|
|
852 |
|