Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\us_que.cpp
20 EXPORT_C void TSglQueLink::Enque(TSglQueLink* aLink)
22 // Enque this after aLink.
33 EXPORT_C void TDblQueLinkBase::Enque(TDblQueLinkBase* aLink)
35 Inserts this link object after the specified link object.
37 The specified link object must already be in the doubly linked list.
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.
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.
52 aLink->iNext->iPrev=this;
59 EXPORT_C void TDblQueLinkBase::AddBefore(TDblQueLinkBase* aLink)
61 Inserts this link object before the specified link object.
63 The specified link object must already be in the doubly linked list.
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.
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.
78 aLink->iPrev->iNext=this;
85 EXPORT_C void TDblQueLink::Deque()
87 Removes this link object from the doubly linked list.
89 In effect, this removes the list element that acts as host to this link object
90 from the doubly linked list.
92 The link object can be any in the doubly linked list.
94 It is safe to use this method on an object which has already been removed from the list.
96 @post iNext member is set to NULL
111 EXPORT_C TSglQueBase::TSglQueBase()
112 : iHead(NULL),iLast((TSglQueLink*)&iHead),iOffset(0)
120 2. iLast to point to the head of queue.
133 EXPORT_C TSglQueBase::TSglQueBase(TInt aOffset)
134 : iHead(NULL),iLast((TSglQueLink*)&iHead),iOffset(aOffset)
136 Constructor with specified offset.
142 2. iLast to point to the head of queue.
144 3. iOffset to the specified value.
146 @param aOffset The offset of a link object within an element.
148 @panic USER 75, if aOffset is not divisible by four
156 __ASSERT_ALWAYS(iOffset%4==0,Panic(ESQueOffsetNotAligned));
162 EXPORT_C TBool TSglQueBase::IsEmpty() const
164 Tests whether the singly linked list is empty, i.e. has no list elements.
166 @return True, if the singly linked list is empty; false, otherwise.
176 EXPORT_C void TSglQueBase::SetOffset(TInt aOffset)
178 Sets the offset of the link object from the start of a singly linked
181 @param aOffset The offset of the link object from the start of a singly linked
184 @panic USER 75, if aOffset is not divisible by four.
190 __ASSERT_ALWAYS(iOffset%4==0,Panic(ESQueOffsetNotAligned));
198 EXPORT_C void TSglQueBase::Reset()
200 Empties the singly linked list.
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.
209 iLast=(TSglQueLink*)&iHead;
216 EXPORT_C void TSglQueBase::DoAddFirst(TAny* aPtr)
218 Implements the insertion of a list element at the front of the singly linked
221 This function is called by TSglQue::AddFirst().
223 @param aPtr An untyped pointer to the element to be inserted.
225 @see TSglQue::AddFirst
229 TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
230 pL->Enque((TSglQueLink*)&iHead);
231 if (iLast==(TSglQueLink*)(&iHead))
238 EXPORT_C void TSglQueBase::DoAddLast(TAny* aPtr)
240 Implements the insertion of a list element at the back of the singly linked
243 This function is called by TSglQue::AddLast().
245 @param aPtr An untyped pointer to the element to be inserted.
247 @see TSglQue::AddLast
251 TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
259 EXPORT_C void TSglQueBase::DoRemove(TAny* aPtr)
261 Implements the removal of a list element from the singly linked list.
263 This function is called by TSglQue::Remove().
265 @param aPtr An untyped pointer to the element to be removed.
271 TSglQueLink* pP=(TSglQueLink*)(&iHead);
272 TSglQueLink* pL=PtrAdd((TSglQueLink*)aPtr,iOffset);
273 TSglQueLink* pN=pP->iNext;
283 iLast=(TSglQueLink*)(&iHead);
290 Panic(ESQueLinkNotQueued);
296 #pragma warning( disable : 4705 ) // statement has no effect
297 EXPORT_C TDblQueBase::TDblQueBase()
304 1. iHead to point to this object in both the forwards and backwards direction.
313 iHead.iNext=iHead.iPrev=(&iHead);
319 EXPORT_C TDblQueBase::TDblQueBase(TInt aOffset)
322 Constructor with specified offset.
326 1. iHead to point to this object in both the forwards and backwards direction.
328 2. iOffset to the specified value.
330 @param aOffset The offset of a link object within an element.
332 @panic USER 78, if aOffset is not divisible by four
339 __ASSERT_ALWAYS(iOffset%4==0,Panic(ETQueOffsetNotAligned));
340 iHead.iNext=iHead.iPrev=(&iHead);
342 #pragma warning( default : 4705 )
347 EXPORT_C TBool TDblQueBase::IsEmpty() const
349 Tests whether the doubly linked list is empty, i.e. has no list elements.
351 @return True, if the doubly linked list is empty; false, otherwise.
355 return((const TDblQueLinkBase*)iHead.iNext==(&iHead));
361 EXPORT_C void TDblQueBase::SetOffset(TInt aOffset)
363 Sets the offset of the link object from the start of a doubly linked list element.
365 @param aOffset The offset of the link object from the start of a doubly linked
368 @panic USER 78, if aOffset is not divisible by four.
374 __ASSERT_ALWAYS(iOffset%4==0,Panic(ETQueOffsetNotAligned));
381 EXPORT_C void TDblQueBase::Reset()
383 Empties the doubly linked list.
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.
391 iHead.iNext=iHead.iPrev=(&iHead);
397 EXPORT_C void TDblQueBase::DoAddFirst(TAny* aPtr)
399 Implements the insertion of the specified list element at the front of the
402 This function is called by TDblQue::AddFirst().
404 @param aPtr An untyped pointer to the element to be inserted.
406 @see TDblQue::AddFirst
410 PtrAdd((TDblQueLinkBase*)aPtr,iOffset)->Enque(&iHead);
416 EXPORT_C void TDblQueBase::DoAddLast(TAny* aPtr)
418 Implements the insertion of the specified list element at the back of the
421 This function is called by TDblQue::AddLast().
423 @param aPtr An untyped pointer to the element to be inserted.
425 @see TDblQue::AddLast*/
428 PtrAdd((TDblQueLinkBase*)aPtr,iOffset)->Enque(iHead.iPrev);
434 EXPORT_C void TDblQueBase::DoAddPriority(TAny* aPtr)
436 Implements the insertion of the specified list element in priority order.
438 This function is called by TPriQue::Add().
440 @param aPtr An untyped pointer to the element to be inserted.
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);
457 EXPORT_C TDeltaQueBase::TDeltaQueBase()
462 It sets iFirstDelta to NULL.
464 @see TDeltaQueBase::iFirstDelta
472 EXPORT_C TDeltaQueBase::TDeltaQueBase(TInt aOffset)
473 : TDblQueBase(aOffset),iFirstDelta(NULL)
475 Constructor with specified offset.
479 1. iFirstDelta to NULL
481 2. TDblQueBase::iOffset to the specified value, through a call to the
482 base class constructor.
484 @param aOffset The offset of a link object within an element.
486 @see TDeltaQueBase::iFirstDelta
487 @see TDblQueBase::iOffset
495 EXPORT_C void TDeltaQueBase::Reset()
497 Empties the doubly linked list, and resets the first delta pointer.
501 TDblQueBase::Reset();
508 EXPORT_C TBool TDeltaQueBase::FirstDelta(TInt& aValue)
510 Gets the delta value of the first list element.
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.
515 @return True, if there is a first element; false, otherwise.
529 EXPORT_C TBool TDeltaQueBase::CountDown()
531 Decrements the delta value of the first element by one, and returns true if
532 the result is negative or zero.
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.
539 return(CountDown(1));
545 EXPORT_C TBool TDeltaQueBase::CountDown(TInt aValue)
547 Decrements the delta value of the first element by the specified value, and
548 returns true if the result is negative or zero.
550 @param aValue The amount by which the delta value is to be reduced.
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.
559 (*iFirstDelta)-=aValue;
569 EXPORT_C void TDeltaQueBase::DoAddDelta(TAny* aPtr,TInt aDelta)
571 Implements the addition of the specified list element into the list.
573 This function is called by TDeltaQue::Add().
575 @param aPtr Pointer to the list element to be inserted.
576 @param aDelta The 'distance' from the nominal zero point.
582 TDeltaQueLink* pD=(TDeltaQueLink*)iHead.iNext;
583 TDeltaQueLink* pI=PtrAdd((TDeltaQueLink*)aPtr,iOffset);
584 while (pD!=(TDeltaQueLink*)&iHead && aDelta>=pD->iDelta)
587 pD=(TDeltaQueLink*)pD->iNext;
590 pI->Enque(pD->iPrev);
591 if (pI->iNext!=&iHead)
593 iFirstDelta=(&((TDeltaQueLink*)iHead.iNext)->iDelta);
599 EXPORT_C void TDeltaQueBase::DoRemove(TAny* aPtr)
601 Implements the removal of the specified list element from the list.
603 This function is called by TDeltaQue::Remove().
605 @param aPtr Pointer to the list element to be removed.
607 @see TDeltaQue::Remove
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);
622 EXPORT_C TAny* TDeltaQueBase::DoRemoveFirst()
624 Implements the removal of the first list element from the linked list if its
625 delta value is zero or negative.
627 This function is called by TDeltaQue::RemoveFirst().
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.
632 @see TDeltaQue::RemoveFirst
636 TDeltaQueLink* pN=(TDeltaQueLink*)iHead.iNext;
637 if (pN!=(TDeltaQueLink*)&iHead && pN->iDelta<=0)
639 pN=PtrSub(pN,iOffset);
649 EXPORT_C TSglQueIterBase::TSglQueIterBase(TSglQueBase& aQue)
653 : iOffset(aQue.iOffset),iHead((TSglQueLink*)&aQue.iHead),iNext(aQue.iHead)
659 EXPORT_C void TSglQueIterBase::SetToFirst()
661 Sets the iterator to point to the first element in the singly linked list.
663 The function can be called to re-set the pointer at any time during the iterator's
666 The function can be called even if the list has no elements.
676 EXPORT_C void TSglQueIterBase::DoSet(TAny* aLink)
678 // Start the iterator at aLink.
682 iNext=PtrAdd((TSglQueLink*)aLink,iOffset);
685 EXPORT_C TAny* TSglQueIterBase::DoPostInc()
687 // Return the current pointer and increment.
695 return(PtrSub(pN,iOffset));
698 EXPORT_C TAny* TSglQueIterBase::DoCurrent()
700 // Return the current pointer.
704 return(iNext==NULL ? NULL : PtrSub((TAny*)iNext,iOffset));
710 EXPORT_C TDblQueIterBase::TDblQueIterBase(TDblQueBase& aQue)
711 : iOffset(aQue.iOffset),iHead(&aQue.iHead),iNext(aQue.iHead.iNext)
713 Constructs the iterator for the specified doubly linked list.
715 @param aQue A reference to a doubly linked list header.
722 EXPORT_C void TDblQueIterBase::SetToFirst()
724 Sets the iterator to point to the first element in the doubly linked list.
726 The function can be called to re-set the pointer at any time during the
727 iterator's existence.
729 The function can be called even if the list has no elements.
739 EXPORT_C void TDblQueIterBase::SetToLast()
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.
745 The function can be called even if the list has no elements.
755 EXPORT_C void TDblQueIterBase::DoSet(TAny* aLink)
757 Sets the iterator to point to a specific element in the list.
759 The function is an implementation for TDblQueIter::Set().
761 @param aLink A pointer to the current list element.
763 @see TDblQueIter::Set
767 iNext=PtrAdd((TDblQueLinkBase*)aLink,iOffset);
773 EXPORT_C TAny* TDblQueIterBase::DoPostInc()
775 Gets the current item and then moves to the next item.
777 The function is an implementation for TDblQueIter::operator++().
779 @return A pointer to the current list element.
781 @see TDblQueIter::operator++
787 __ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
788 TAny* p=PtrSub(iNext,iOffset);
796 EXPORT_C TAny* TDblQueIterBase::DoPostDec()
798 Gets the current item and then moves to the previous item.
800 The function is an implementation for TDblQueIter::operator--().
802 @return A pointer to the current list element.
804 @see TDblQueIter::operator--
810 __ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
811 TAny* p=PtrSub(iNext,iOffset);
819 EXPORT_C TAny* TDblQueIterBase::DoCurrent()
821 Gets the current item in the queue.
823 The function is an implementation for TDblQueIter::operator T*().
825 @return A pointer to the current list element.
827 @see TDblQueIter::operator T*
833 __ASSERT_DEBUG((iNext->iNext!=NULL)&&(iNext->iPrev!=NULL),Panic(ETQueLinkHasBeenRemoved));
834 return(PtrSub(iNext,iOffset));
840 EXPORT_C void TDblQueBase::__DbgTestEmpty() const
842 Tests whether the queue is empty.
844 The function is implemented as an __ASSERT_DEBUG.
846 @panic USER 79, if the assertion fails.
850 __ASSERT_DEBUG((((TDblQueLink*)iHead.iNext)!=&iHead)&&(((TDblQueLink*)iHead.iPrev)!=&iHead),Panic(ETQueQueueEmpty));