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