os/kernelhwsrv/kernel/eka/euser/us_func.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
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_func.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "us_std.h"
sl@0
    19
//#define __DEBUG_IMAGE__ 1
sl@0
    20
#if defined(__DEBUG_IMAGE__) && defined (__EPOC32__)
sl@0
    21
#include "e32svr.h" 
sl@0
    22
#define __IF_DEBUG(t) {RDebug debug;debug.t;}
sl@0
    23
#else
sl@0
    24
#define __IF_DEBUG(t)
sl@0
    25
#endif
sl@0
    26
#ifdef _UNICODE
sl@0
    27
#include <collate.h>
sl@0
    28
#include "CompareImp.h"
sl@0
    29
#endif
sl@0
    30
sl@0
    31
#include "us_data.h"
sl@0
    32
sl@0
    33
typedef union
sl@0
    34
	{
sl@0
    35
	TAny *tany;
sl@0
    36
	TText8 *ttext8;
sl@0
    37
	TText16 *ttext16;
sl@0
    38
	TDesC8 *tdesc8;
sl@0
    39
	TDesC16 *tdesc16;
sl@0
    40
	TInt8 *tint8;
sl@0
    41
	TInt16 *tint16;
sl@0
    42
	TInt32 *tint32;
sl@0
    43
	TInt64 *tint64;
sl@0
    44
	TInt *tint;
sl@0
    45
	TUint8 *tuint8;
sl@0
    46
	TUint16 *tuint16;
sl@0
    47
	TUint32 *tuint32;
sl@0
    48
	TUint *tuint;
sl@0
    49
	} UPTR;
sl@0
    50
sl@0
    51
const TUint crcTab[256] =
sl@0
    52
    {
sl@0
    53
	0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,0x8108,0x9129,0xa14a,
sl@0
    54
	0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,
sl@0
    55
	0x72f7,0x62d6,0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,0x2462,
sl@0
    56
	0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,0xa56a,0xb54b,0x8528,0x9509,
sl@0
    57
	0xe5ee,0xf5cf,0xc5ac,0xd58d,0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,
sl@0
    58
	0x46b4,0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,0x48c4,0x58e5,
sl@0
    59
	0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,
sl@0
    60
	0x9969,0xa90a,0xb92b,0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
sl@0
    61
	0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,0x6ca6,0x7c87,0x4ce4,
sl@0
    62
	0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,
sl@0
    63
	0x8d68,0x9d49,0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,0xff9f,
sl@0
    64
	0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,0x9188,0x81a9,0xb1ca,0xa1eb,
sl@0
    65
	0xd10c,0xc12d,0xf14e,0xe16f,0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,
sl@0
    66
	0x6067,0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,0x02b1,0x1290,
sl@0
    67
	0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,
sl@0
    68
	0xe54f,0xd52c,0xc50d,0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
sl@0
    69
	0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,0x26d3,0x36f2,0x0691,
sl@0
    70
	0x16b0,0x6657,0x7676,0x4615,0x5634,0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,
sl@0
    71
	0xb98a,0xa9ab,0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,0xcb7d,
sl@0
    72
	0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,0x4a75,0x5a54,0x6a37,0x7a16,
sl@0
    73
	0x0af1,0x1ad0,0x2ab3,0x3a92,0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,
sl@0
    74
	0x8dc9,0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,0xef1f,0xff3e,
sl@0
    75
	0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,
sl@0
    76
	0x3eb2,0x0ed1,0x1ef0
sl@0
    77
    };
sl@0
    78
sl@0
    79
const TInt KQDepth=150; // Maximum queue depth
sl@0
    80
sl@0
    81
LOCAL_C TUint checkSum(const TAny *aPtr)
sl@0
    82
//
sl@0
    83
// Checksum every other byte
sl@0
    84
//
sl@0
    85
	{
sl@0
    86
sl@0
    87
	const TUint8* pB=(const TUint8*)aPtr;
sl@0
    88
	const TUint8* pE=pB+(KMaxCheckedUid*sizeof(TUid));
sl@0
    89
	TUint8 buf[(KMaxCheckedUid*sizeof(TUid))>>1];
sl@0
    90
	TUint8* pT=(&buf[0]);
sl@0
    91
	while (pB<pE)
sl@0
    92
		{
sl@0
    93
		*pT++=(*pB);
sl@0
    94
		pB+=2;
sl@0
    95
		}
sl@0
    96
	TUint16 crc=0;
sl@0
    97
	Mem::Crc(crc,&buf[0],(KMaxCheckedUid*sizeof(TUid))>>1);
sl@0
    98
	return(crc);
sl@0
    99
	}
sl@0
   100
	
sl@0
   101
LOCAL_C TInt partit(TInt n,TInt m,const TKey &aKey,const TSwap &aSwap)
sl@0
   102
//
sl@0
   103
// Partition n elements of array stating from element m, 
sl@0
   104
// return element no. of partition point. 
sl@0
   105
//
sl@0
   106
	{
sl@0
   107
sl@0
   108
	TInt i=m-1;
sl@0
   109
	TInt j=i+n;
sl@0
   110
	TInt pivlin=j;
sl@0
   111
	aSwap.Swap((j+m)>>1,j);
sl@0
   112
	while (i<j) 
sl@0
   113
		{
sl@0
   114
		for (i++;aKey.Compare(i,pivlin)<0;i++)
sl@0
   115
			{
sl@0
   116
			}
sl@0
   117
		for (--j;j>i;j--)
sl@0
   118
			{
sl@0
   119
			if (aKey.Compare(j,pivlin)<=0)
sl@0
   120
				break;
sl@0
   121
			}
sl@0
   122
		if (i<j)
sl@0
   123
			aSwap.Swap(i,j);
sl@0
   124
		}
sl@0
   125
	aSwap.Swap(i,m+n-1);
sl@0
   126
	return(i);
sl@0
   127
	}
sl@0
   128
sl@0
   129
static const TCollationMethod TheCollationMethod[] =
sl@0
   130
	{
sl@0
   131
		{
sl@0
   132
		KUidBasicCollationMethod,				// this is the standard unlocalised method
sl@0
   133
		NULL,									// null means use the standard table
sl@0
   134
		NULL,									// there's no override table
sl@0
   135
		0										// the flags are standard
sl@0
   136
		}
sl@0
   137
	};
sl@0
   138
sl@0
   139
static const TCollationDataSet TheCollationDataSet =
sl@0
   140
	{
sl@0
   141
	TheCollationMethod,
sl@0
   142
	1
sl@0
   143
	};
sl@0
   144
sl@0
   145
// The one and only locale character set object.
sl@0
   146
const LCharSet TheCharSet =
sl@0
   147
	{
sl@0
   148
	NULL,
sl@0
   149
	&TheCollationDataSet
sl@0
   150
	};
sl@0
   151
sl@0
   152
const LCharSet* GetLocaleDefaultCharSet()
sl@0
   153
	{
sl@0
   154
	return &TheCharSet;
sl@0
   155
	}
sl@0
   156
sl@0
   157
const LCharSet* GetLocaleCharSet()
sl@0
   158
	{
sl@0
   159
	const LCharSet* charSet = (const LCharSet*)Exec::GetGlobalUserData(ELocaleDefaultCharSet);
sl@0
   160
	if(charSet)
sl@0
   161
		return charSet;
sl@0
   162
	return &TheCharSet;
sl@0
   163
	}
sl@0
   164
sl@0
   165
const LCharSet* GetLocalePreferredCharSet()
sl@0
   166
	{
sl@0
   167
	const LCharSet* charSet = (const LCharSet*)Exec::GetGlobalUserData(ELocalePreferredCharSet);
sl@0
   168
	if(charSet)
sl@0
   169
		return charSet;
sl@0
   170
	return &TheCharSet;
sl@0
   171
	}
sl@0
   172
sl@0
   173
EXPORT_C TCollationMethod TExtendedLocale::GetPreferredCollationMethod(TInt aIndex)
sl@0
   174
/**
sl@0
   175
Get the preferred collation method for the preferred charset.
sl@0
   176
sl@0
   177
Note that some charsets may contain more than one collation
sl@0
   178
method (e.g "dictionary" v "phonebook" ordering) so an optional
sl@0
   179
index parameter can be used to select between them.
sl@0
   180
sl@0
   181
@param aIndex Optional parameter specifying the index of the collation 
sl@0
   182
              method in the locale to get. This is the responsibility of 
sl@0
   183
			  the caller to make sure that the index is less than the total 
sl@0
   184
			  number of collation methods in the preferred charset in this locale.
sl@0
   185
sl@0
   186
@return TCollationMethod representing the requested collation method.
sl@0
   187
sl@0
   188
@panic USER 185 In both debug and release builds, if either the current charset 
sl@0
   189
       is not set up or aIndex is greater than or equal to the total number of 
sl@0
   190
	   collation methods in the preferred charset in this locale.
sl@0
   191
sl@0
   192
@see TCollationMethod
sl@0
   193
*/
sl@0
   194
	{
sl@0
   195
	__ASSERT_ALWAYS(iPreferredCharSet && (TUint(aIndex)<=TUint(iPreferredCharSet->iCollationDataSet->iMethods)), Panic(EBadLocaleParameter));
sl@0
   196
	return iPreferredCharSet->iCollationDataSet->iMethod[aIndex];
sl@0
   197
	}
sl@0
   198
sl@0
   199
extern const TUint8 __FoldCollTab8[256];
sl@0
   200
sl@0
   201
EXPORT_C TInt Mem::CompareF(const TUint8 *aLeft,TInt aLeftL,const TUint8 *aRight,TInt aRightL)
sl@0
   202
/**
sl@0
   203
Compares a block of data at one specified location with a block of data at 
sl@0
   204
another specified location, using the standard folding method appropriate 
sl@0
   205
to the current locale.
sl@0
   206
sl@0
   207
@param aLeft   A pointer to the first (or left) block of 8 bit data to be
sl@0
   208
               compared.
sl@0
   209
@param aLeftL  The length of the first (or left) block of data to be compared, 
sl@0
   210
               i.e. the number of bytes.
sl@0
   211
@param aRight  A pointer to the second (or right) block of 8 bit data to be 
sl@0
   212
               compared.
sl@0
   213
@param aRightL The length of the second (or right) block of data to be
sl@0
   214
               compared, i.e. the number of bytes.
sl@0
   215
sl@0
   216
@return Positive, if the first (or left) block of data is greater than the 
sl@0
   217
        second (or right) block of data.
sl@0
   218
        Negative, if the first (or left) block of data is less than the second
sl@0
   219
        (or right) block of data.
sl@0
   220
        Zero, if both the first (or left) and second (or right) blocks of data
sl@0
   221
        have the same length and the same content. 
sl@0
   222
        
sl@0
   223
@see Mem::Compare
sl@0
   224
*/
sl@0
   225
	{
sl@0
   226
sl@0
   227
	__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
sl@0
   228
	__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
sl@0
   229
	const TUint8 *pE=aLeft+Min(aLeftL,aRightL);
sl@0
   230
	const TUint8* table=__FoldCollTab8;
sl@0
   231
    while (aLeft<pE)
sl@0
   232
		{
sl@0
   233
		TUint l=*aLeft++;
sl@0
   234
		TUint r=*aRight++;
sl@0
   235
		l = table[l];
sl@0
   236
		r = table[r];
sl@0
   237
		TInt d=l-r;
sl@0
   238
		if (d!=0)
sl@0
   239
		    return(d);
sl@0
   240
		}
sl@0
   241
    return(aLeftL-aRightL);
sl@0
   242
	}
sl@0
   243
sl@0
   244
sl@0
   245
sl@0
   246
sl@0
   247
EXPORT_C TInt Mem::CompareC(const TUint8 *aLeft,TInt aLeftL,const TUint8 *aRight,TInt aRightL)
sl@0
   248
/**
sl@0
   249
Compares a block of data at one specified location with a block of data at 
sl@0
   250
another specified location using the standard collation method appropriate 
sl@0
   251
to the current locale.
sl@0
   252
sl@0
   253
@param aLeft   A pointer to the first (or left) block of 8 bit data to be
sl@0
   254
               compared.
sl@0
   255
@param aLeftL  The length of the first (or left) block of data to be compared 
sl@0
   256
               i.e. the number of bytes.
sl@0
   257
@param aRight  A pointer to the second (or right) block of 8 bit data to be 
sl@0
   258
               compared.
sl@0
   259
@param aRightL The length of the second (or right) block of data to be compared 
sl@0
   260
               i.e. the number of bytes.
sl@0
   261
sl@0
   262
@return Positive, if the first (or left) block of data is greater than the 
sl@0
   263
        second (or right) block of data.
sl@0
   264
        Negative, if the first (or left) block of data is less than the second
sl@0
   265
        (or right) block of data.
sl@0
   266
        Zero, if both the first (or left) and second (or right) blocks of data
sl@0
   267
        have the same length and the same content.
sl@0
   268
        
sl@0
   269
@see Mem::Compare
sl@0
   270
@deprecated
sl@0
   271
*/
sl@0
   272
	{
sl@0
   273
	return Mem::CompareF(aLeft, aLeftL, aRight, aRightL);
sl@0
   274
	}
sl@0
   275
sl@0
   276
sl@0
   277
sl@0
   278
sl@0
   279
EXPORT_C TInt Mem::Compare(const TUint16 *aLeft,TInt aLeftL,const TUint16 *aRight,TInt aRightL)
sl@0
   280
/**
sl@0
   281
Compares a block of data at one specified location with a block of data at 
sl@0
   282
another specified location.
sl@0
   283
sl@0
   284
The comparison proceeds on a double-byte for double-byte basis, the result 
sl@0
   285
of the comparison is based on the difference of the first pair of bytes to 
sl@0
   286
disagree.
sl@0
   287
sl@0
   288
The data at the two locations are equal if they have the same length and content. 
sl@0
   289
Where the lengths are different and the shorter section of data is the same 
sl@0
   290
as the first part of the longer section of data, the shorter is considered 
sl@0
   291
to be less than the longer.
sl@0
   292
sl@0
   293
@param aLeft   A pointer to the first (or left) block of 16 bit data to be
sl@0
   294
               compared.
sl@0
   295
@param aLeftL  The length of the first (or left) block of data to be compared 
sl@0
   296
               i.e. the number of double-bytes. 
sl@0
   297
@param aRight  A pointer to the second (or right) block of 16 bit data to be 
sl@0
   298
               compared.
sl@0
   299
@param aRightL The length of the second (or right) block of data to be compared 
sl@0
   300
               i.e. the number of double-bytes.
sl@0
   301
sl@0
   302
@return Positive, if the first (or left) block of data is greater than the 
sl@0
   303
        second (or right) block of data.
sl@0
   304
        Negative, if the first (or left) block of data is less than the second
sl@0
   305
        (or right) block of data.
sl@0
   306
        Zero, if both the first (or left) and second (or right) blocks of data
sl@0
   307
        have the same length and the same content.
sl@0
   308
*/
sl@0
   309
	{
sl@0
   310
sl@0
   311
	__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
sl@0
   312
	__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
sl@0
   313
	const TUint16 *pE=aLeft+Min(aLeftL,aRightL);
sl@0
   314
    while (aLeft<pE)
sl@0
   315
		{
sl@0
   316
		TInt d=(*aLeft++)-(*aRight++);
sl@0
   317
		if (d!=0)
sl@0
   318
		    return(d);
sl@0
   319
		}
sl@0
   320
    return(aLeftL-aRightL);
sl@0
   321
	}
sl@0
   322
sl@0
   323
sl@0
   324
sl@0
   325
sl@0
   326
EXPORT_C TInt Mem::CompareF(const TUint16 *aLeft,TInt aLeftL,const TUint16 *aRight,TInt aRightL)
sl@0
   327
/**
sl@0
   328
Compares a block of data at one specified location with a block of data at 
sl@0
   329
another specified location, using the standard folding method appropriate 
sl@0
   330
to the current locale.
sl@0
   331
sl@0
   332
@param aLeft   A pointer to the first (or left) block of 16 bit data to be
sl@0
   333
               compared.
sl@0
   334
@param aLeftL  The length of the first (or left) block of data to be compared 
sl@0
   335
               i.e. the number of double-bytes.
sl@0
   336
@param aRight  A pointer to the second (or right) block of 16 bit data to be 
sl@0
   337
               compared.
sl@0
   338
@param aRightL The length of the second (or right) block of data to be compared 
sl@0
   339
               i.e the number of double-bytes.
sl@0
   340
sl@0
   341
@return Positive, if the first (or left) block of data is greater than the 
sl@0
   342
        second (or right) block of data.
sl@0
   343
        Negative, if the first (or left) block of data is less than the second
sl@0
   344
        (or right) block of data.
sl@0
   345
        Zero, if both the first (or left) and second (or right) blocks of data
sl@0
   346
        have the same length and the same content.
sl@0
   347
        
sl@0
   348
@see Mem::Compare
sl@0
   349
*/
sl@0
   350
	{
sl@0
   351
	__ASSERT_DEBUG(aLeftL >= 0,Panic(EMemLeftNegative));
sl@0
   352
	__ASSERT_DEBUG(aRightL >= 0,Panic(EMemRightNegative));
sl@0
   353
sl@0
   354
	const TText16* aLeftEnd = aLeft + aLeftL;
sl@0
   355
	const TText16* aRightEnd = aRight + aRightL;
sl@0
   356
	
sl@0
   357
	const TUint8* table=__FoldCollTab8;
sl@0
   358
sl@0
   359
	while (aLeft != aLeftEnd)
sl@0
   360
		{
sl@0
   361
		if (aRight == aRightEnd)
sl@0
   362
			return 1;
sl@0
   363
sl@0
   364
		TUint l = *aLeft;
sl@0
   365
		TUint r = *aRight;
sl@0
   366
sl@0
   367
		// check if character is Ascii, if so treat as Ascii
sl@0
   368
		if (l < 128 && r < 128)
sl@0
   369
			{
sl@0
   370
			l = table[l];
sl@0
   371
			r = table[r];
sl@0
   372
sl@0
   373
			if (r != l)
sl@0
   374
				return l-r;
sl@0
   375
			
sl@0
   376
			aLeft++;
sl@0
   377
			aRight++;
sl@0
   378
			}
sl@0
   379
		// covers Unicode characters...
sl@0
   380
		else
sl@0
   381
			{
sl@0
   382
			TUTF32Iterator leftIt(aLeft, aLeftEnd);
sl@0
   383
			TUTF32Iterator rightIt(aRight, aRightEnd);
sl@0
   384
			return ::CompareFolded(leftIt, rightIt);
sl@0
   385
			}
sl@0
   386
		}
sl@0
   387
sl@0
   388
	return aRight == aRightEnd? 0:-1;
sl@0
   389
	}
sl@0
   390
	
sl@0
   391
sl@0
   392
sl@0
   393
sl@0
   394
sl@0
   395
EXPORT_C TInt Mem::CompareC(const TUint16 *aLeft,TInt aLeftL,const TUint16 *aRight,TInt aRightL)
sl@0
   396
/**
sl@0
   397
Compares a block of data at one specified location with a block of data at 
sl@0
   398
another specified location using the standard collation method appropriate 
sl@0
   399
to the current locale.
sl@0
   400
sl@0
   401
@param aLeft   A pointer to the first (or left) block of 16 bit data to be
sl@0
   402
               compared.
sl@0
   403
@param aLeftL  The length of the first (or left) block of data to be compared 
sl@0
   404
               i.e. the number of double-bytes).
sl@0
   405
@param aRight  A pointer to the second (or right) block of 16 bit data to be 
sl@0
   406
               compared.
sl@0
   407
@param aRightL The length of the second (or right) block of data to be compared 
sl@0
   408
               i.e. the number of double-bytes. 
sl@0
   409
               
sl@0
   410
@return Positive, if the first (or left) block of data is greater than the 
sl@0
   411
        second (or right) block of data.
sl@0
   412
        Negative, if the first (or left) block of data is less than the second
sl@0
   413
        (or right) block of data.
sl@0
   414
        Zero, if both the first (or left) and second (or right) blocks of data
sl@0
   415
        have the same length and the same content. 
sl@0
   416
        
sl@0
   417
@see Mem::Compare
sl@0
   418
*/
sl@0
   419
	{
sl@0
   420
	__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
sl@0
   421
	__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
sl@0
   422
#ifdef _UNICODE
sl@0
   423
	TCollate c(GetLocaleCharSet());
sl@0
   424
	return c.Compare(aLeft,aLeftL,aRight,aRightL);
sl@0
   425
#else
sl@0
   426
	const TUint16 *pE=aLeft+Min(aLeftL,aRightL);
sl@0
   427
    while (aLeft<pE)
sl@0
   428
		{
sl@0
   429
		TInt d=User::Collate(*aLeft++)-User::Collate(*aRight++);
sl@0
   430
		if (d!=0)
sl@0
   431
		    return(d);
sl@0
   432
		}
sl@0
   433
    return(aLeftL-aRightL);
sl@0
   434
#endif
sl@0
   435
	}
sl@0
   436
sl@0
   437
sl@0
   438
sl@0
   439
sl@0
   440
#ifdef _UNICODE
sl@0
   441
EXPORT_C TInt Mem::CompareC(const TUint16* aLeft,TInt aLeftL,const TUint16* aRight,TInt aRightL,
sl@0
   442
							TInt aMaxLevel,const TCollationMethod* aCollationMethod)
sl@0
   443
/**
sl@0
   444
Compares a block of data at one location with a block of data at another location 
sl@0
   445
using the specified collation method and collating to the specified maximum 
sl@0
   446
collation level.
sl@0
   447
sl@0
   448
If no collation method is supplied, a default method, appropriate to the current 
sl@0
   449
locale, is used.
sl@0
   450
sl@0
   451
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   452
that the function is not defined for 8 bit build variants, even when an explicit 
sl@0
   453
16 bit descriptor is used.
sl@0
   454
sl@0
   455
@param aLeft            A pointer to the first (or left) block of 16 bit data
sl@0
   456
                        to be compared.
sl@0
   457
@param aLeftL           The length of the first (or left) block of data to be
sl@0
   458
                        compared. This is the number of double-bytes. 
sl@0
   459
@param aRight           A pointer to the second (or right) block of 16 bit data
sl@0
   460
                        to be compared.
sl@0
   461
@param aRightL          The length of the second (or right) block of data to be
sl@0
   462
                        compared. This is the number of double-bytes. 
sl@0
   463
@param aMaxLevel        The maximum collation level. 
sl@0
   464
@param aCollationMethod A pointer to the collation method or NULL. 
sl@0
   465
sl@0
   466
@return Positive, if this descriptor is greater than the specified descriptor. 
sl@0
   467
        Negative, if this descriptor is less than the specified descriptor.
sl@0
   468
        Zero, if both descriptors have the same length and their contents
sl@0
   469
        are the same.
sl@0
   470
*/
sl@0
   471
	{
sl@0
   472
	__ASSERT_DEBUG(aLeftL>=0,Panic(EMemLeftNegative));
sl@0
   473
	__ASSERT_DEBUG(aRightL>=0,Panic(EMemRightNegative));
sl@0
   474
	if (aCollationMethod == NULL)
sl@0
   475
		{
sl@0
   476
		TCollate c(GetLocaleCharSet());
sl@0
   477
		return c.Compare(aLeft,aLeftL,aRight,aRightL,aMaxLevel);
sl@0
   478
		}
sl@0
   479
	else
sl@0
   480
		{
sl@0
   481
		TCollate c(*aCollationMethod);
sl@0
   482
		return c.Compare(aLeft,aLeftL,aRight,aRightL,aMaxLevel);
sl@0
   483
		}
sl@0
   484
	}
sl@0
   485
#endif
sl@0
   486
sl@0
   487
sl@0
   488
sl@0
   489
sl@0
   490
#ifdef _UNICODE
sl@0
   491
EXPORT_C TInt Mem::CollationMethods()
sl@0
   492
/**
sl@0
   493
Gets the number of collation methods in this locale.
sl@0
   494
sl@0
   495
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   496
that the function is not defined for 8 bit build variants, even when an
sl@0
   497
explicit 16 bit descriptor is used.
sl@0
   498
sl@0
   499
@return The number of collation methods.
sl@0
   500
*/
sl@0
   501
	{
sl@0
   502
	return GetLocaleCharSet()->iCollationDataSet->iMethods;
sl@0
   503
	}
sl@0
   504
#endif
sl@0
   505
sl@0
   506
sl@0
   507
sl@0
   508
sl@0
   509
#ifdef _UNICODE
sl@0
   510
EXPORT_C TUint Mem::CollationMethodId(TInt aIndex)
sl@0
   511
/**
sl@0
   512
Gets the Uid associated with the specified collation method.
sl@0
   513
sl@0
   514
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   515
that the function is not defined for 8 bit build variants, even when an
sl@0
   516
explicit 16 bit descriptor is used.
sl@0
   517
sl@0
   518
@param aIndex An index into the set of collation methods in thie locale. This 
sl@0
   519
              value is relative to zero; i.e. a zero value refers to the first
sl@0
   520
              collation method. This value must not be negative, and must be
sl@0
   521
              less than the total number of collation methods in this locale.
sl@0
   522
sl@0
   523
@return The Uid of the collation method.
sl@0
   524
sl@0
   525
@panic USER 132 In debug builds only, if aIndex is negative or is greater than
sl@0
   526
       or equal to the total number of collation methods in this locale.
sl@0
   527
*/
sl@0
   528
	{
sl@0
   529
	const TCollationDataSet* s = GetLocaleCharSet()->iCollationDataSet;
sl@0
   530
	__ASSERT_DEBUG(aIndex >= 0 && aIndex < s->iMethods,Panic(EBadCollationRulesIndex));
sl@0
   531
	return s->iMethod[aIndex].iId;
sl@0
   532
	}
sl@0
   533
#endif
sl@0
   534
sl@0
   535
sl@0
   536
sl@0
   537
sl@0
   538
#ifdef _UNICODE
sl@0
   539
EXPORT_C const TCollationMethod* Mem::CollationMethodByIndex(TInt aIndex)
sl@0
   540
/**
sl@0
   541
Gets the collation method identified by the specified index.
sl@0
   542
sl@0
   543
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   544
that the function is not defined for 8 bit build variants, even when an
sl@0
   545
explicit 16 bit descriptor is used.
sl@0
   546
sl@0
   547
@param aIndex An index into the set of collation methods in this locale. This 
sl@0
   548
              value is relative to zero; i.e. a zero value refers to the first
sl@0
   549
              collation method. This value must not be negative, and must be
sl@0
   550
              less than the total number of collation methods in this locale.
sl@0
   551
              
sl@0
   552
@return A pointer to the collation method.
sl@0
   553
sl@0
   554
@panic USER 132 In debug builds only, if aIndex is negative or is greater than
sl@0
   555
       or equal to the total number of collation methods in this locale.
sl@0
   556
*/
sl@0
   557
	{
sl@0
   558
	const TCollationDataSet* s = GetLocaleCharSet()->iCollationDataSet;
sl@0
   559
	__ASSERT_DEBUG(aIndex >= 0 && aIndex < s->iMethods,Panic(EBadCollationRulesIndex));
sl@0
   560
	return &s->iMethod[aIndex];
sl@0
   561
	}
sl@0
   562
#endif
sl@0
   563
sl@0
   564
sl@0
   565
sl@0
   566
sl@0
   567
#ifdef _UNICODE
sl@0
   568
EXPORT_C const TCollationMethod* Mem::CollationMethodById(TUint aId)
sl@0
   569
/**
sl@0
   570
Gets the collation method identified by the specified Uid.
sl@0
   571
sl@0
   572
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   573
that the function is not defined for 8 bit build variants, even when an
sl@0
   574
explicit 16 bit descriptor is used.
sl@0
   575
sl@0
   576
@param aId The Uid of a collation method in the set of collation methods in 
sl@0
   577
           this locale. 
sl@0
   578
           
sl@0
   579
@return A pointer to the collation method.
sl@0
   580
*/
sl@0
   581
	{
sl@0
   582
	const TCollationDataSet* set = GetLocaleCharSet()->iCollationDataSet;
sl@0
   583
	const TCollationMethod* method = set->iMethod;
sl@0
   584
	const TCollationMethod* m = method;
sl@0
   585
	int methods = set->iMethods;
sl@0
   586
	for (int i = 0; i < methods; i++, m++)
sl@0
   587
		if (m->iId == aId)
sl@0
   588
			{
sl@0
   589
			method = m;
sl@0
   590
			break;
sl@0
   591
			}
sl@0
   592
	return method;
sl@0
   593
	}
sl@0
   594
#endif
sl@0
   595
sl@0
   596
#ifdef _UNICODE
sl@0
   597
EXPORT_C const TCollationMethod* Mem::GetDefaultMatchingTable()
sl@0
   598
/**
sl@0
   599
Gets the collation method specific for matching purpose.
sl@0
   600
sl@0
   601
This function is only defined for 16 bit (Unicode) build variants. This means 
sl@0
   602
that the function is not defined for 8 bit build variants, even when an
sl@0
   603
explicit 16 bit descriptor is used.
sl@0
   604
sl@0
   605
@return A pointer to the collation method
sl@0
   606
*/
sl@0
   607
	{
sl@0
   608
	const TCollationDataSet* set=GetLocaleCharSet()->iCollationDataSet;
sl@0
   609
	const TCollationMethod* method=set->iMethod;
sl@0
   610
	const TCollationMethod* m= method;
sl@0
   611
	int methods = set->iMethods;
sl@0
   612
	for (; methods-->0; m++)
sl@0
   613
		if (m->iFlags & TCollationMethod::EMatchingTable)
sl@0
   614
			{
sl@0
   615
			method=m;
sl@0
   616
			break;
sl@0
   617
			}
sl@0
   618
	return method;
sl@0
   619
	}
sl@0
   620
#endif
sl@0
   621
sl@0
   622
sl@0
   623
#if !defined(__MEM_MACHINE_CODED__)
sl@0
   624
EXPORT_C void Mem::Swap(TAny *aPtr1,TAny *aPtr2,TInt aLength)
sl@0
   625
/**
sl@0
   626
Swaps a number of bytes of data between two specified locations.
sl@0
   627
sl@0
   628
The source and target areas can overlap.
sl@0
   629
sl@0
   630
@param aPtr1   A pointer to the first location taking part in the swap. 
sl@0
   631
@param aPtr2   A pointer to second location taking part in the swap. 
sl@0
   632
@param aLength The number of bytes to be swapped between the two locations. 
sl@0
   633
               This value must not be negative.
sl@0
   634
sl@0
   635
@panic USER 94 In debug builds only, if aLength is negative.
sl@0
   636
*/
sl@0
   637
	{
sl@0
   638
sl@0
   639
	__ASSERT_DEBUG(aLength>=0,Panic(EMemSwapLengthNegative));
sl@0
   640
	if (aPtr1==aPtr2)
sl@0
   641
		return;
sl@0
   642
	TUint8 *pT=(TUint8 *)aPtr1;
sl@0
   643
	TUint8 *pE=pT+aLength;
sl@0
   644
	TUint8 *pS=(TUint8 *)aPtr2;
sl@0
   645
	while (pT<pE)
sl@0
   646
		{
sl@0
   647
		TUint b=(*pT);
sl@0
   648
		*pT++=(*pS);
sl@0
   649
		*pS++=(TUint8)b;
sl@0
   650
		}
sl@0
   651
	}
sl@0
   652
#endif
sl@0
   653
sl@0
   654
sl@0
   655
sl@0
   656
sl@0
   657
EXPORT_C void Mem::Crc(TUint16& aCrc,const TAny* aPtr,TInt aLength)
sl@0
   658
/**
sl@0
   659
Performs a CCITT CRC checksum on the specified data.
sl@0
   660
sl@0
   661
On return from this function, the referenced 16 bit integer contains the checksummed 
sl@0
   662
value.
sl@0
   663
sl@0
   664
@param aCrc    A reference to a 16 bit integer to contain the checksummed value. 
sl@0
   665
@param aPtr    A pointer to the start of the data to be checksummed. 
sl@0
   666
@param aLength The length of the data to be checksummed.
sl@0
   667
*/
sl@0
   668
	{
sl@0
   669
sl@0
   670
	const TUint8* pB=(const TUint8*)aPtr;
sl@0
   671
	const TUint8* pE=pB+aLength;
sl@0
   672
	TUint crc=aCrc;
sl@0
   673
    while (pB<pE)
sl@0
   674
		crc=(crc<<8)^crcTab[((crc>>8)^*pB++)&0xff];
sl@0
   675
	aCrc=(TUint16)crc;
sl@0
   676
	}
sl@0
   677
sl@0
   678
sl@0
   679
sl@0
   680
sl@0
   681
EXPORT_C TInt User::StringLength(const TUint8 *aString)
sl@0
   682
/**
sl@0
   683
Gets the length of a C style, null terminated, string of single-byte valued 
sl@0
   684
characters.
sl@0
   685
sl@0
   686
The length does not include the null terminator.
sl@0
   687
sl@0
   688
@param aString A pointer to the single byte valued, null terminated, string.
sl@0
   689
sl@0
   690
@return The length of the string.
sl@0
   691
*/
sl@0
   692
	{
sl@0
   693
sl@0
   694
	const TUint8 *pS=aString;
sl@0
   695
	while (*pS)
sl@0
   696
		pS++;
sl@0
   697
	return(pS-aString);
sl@0
   698
	}
sl@0
   699
sl@0
   700
sl@0
   701
sl@0
   702
sl@0
   703
EXPORT_C TInt User::StringLength(const TUint16 *aString)
sl@0
   704
/**
sl@0
   705
Gets the length of a C style, null terminated, string of double-byte valued 
sl@0
   706
characters.
sl@0
   707
sl@0
   708
The length does not include the null terminator.
sl@0
   709
sl@0
   710
@param aString A pointer to the double-byte valued, null terminated, string.
sl@0
   711
sl@0
   712
@return The length of the string.
sl@0
   713
*/
sl@0
   714
	{
sl@0
   715
sl@0
   716
	const TUint16 *pS=aString;
sl@0
   717
	while (*pS)
sl@0
   718
		pS++;
sl@0
   719
	return(pS-aString);
sl@0
   720
	}
sl@0
   721
sl@0
   722
sl@0
   723
sl@0
   724
sl@0
   725
EXPORT_C void User::Panic(const TDesC &aCategory,TInt aReason)
sl@0
   726
/**
sl@0
   727
Panics the current thread, specifying a category name and panic number.
sl@0
   728
sl@0
   729
Keep the length of the category name small; it is limited to 16 characters.
sl@0
   730
sl@0
   731
@param aCategory A reference to the descriptor containing the text that defines 
sl@0
   732
                 the category for this panic.
sl@0
   733
@param aReason   The panic number.
sl@0
   734
*/
sl@0
   735
	{
sl@0
   736
sl@0
   737
	__IF_DEBUG(Print(_L("User::Panic %S %d\n"),&aCategory,aReason));
sl@0
   738
	TPtrC cat16(aCategory.Ptr(),Min(KMaxExitCategoryName,aCategory.Length()));
sl@0
   739
	TBuf8<KMaxExitCategoryName> cat;
sl@0
   740
	cat.Copy(cat16);
sl@0
   741
	ExitCurrentThread(EExitPanic,aReason,&cat);
sl@0
   742
	}
sl@0
   743
sl@0
   744
sl@0
   745
sl@0
   746
sl@0
   747
void CallStaticEntryPoints(TBool aInit)
sl@0
   748
	{
sl@0
   749
	TLinAddr ep[KMaxLibraryEntryPoints];
sl@0
   750
	TInt numEps=KMaxLibraryEntryPoints;
sl@0
   751
	TInt r=E32Loader::StaticCallList(numEps, ep);
sl@0
   752
	if (r!=KErrNone)
sl@0
   753
		return;
sl@0
   754
	if (aInit)
sl@0
   755
		{
sl@0
   756
		for (TInt i=0; i<numEps-1; ++i)	// last EP is always process entry point
sl@0
   757
			{
sl@0
   758
			TLibraryEntry f=(TLibraryEntry)ep[i];
sl@0
   759
			(*f)(KModuleEntryReasonProcessAttach);
sl@0
   760
			}
sl@0
   761
		}
sl@0
   762
	else
sl@0
   763
		{
sl@0
   764
		for (TInt i=numEps-2; i>=0; --i)	// last EP is always process entry point
sl@0
   765
			{
sl@0
   766
			TLibraryEntry f=(TLibraryEntry)ep[i];
sl@0
   767
			(*f)(KModuleEntryReasonProcessDetach);
sl@0
   768
			}
sl@0
   769
		}
sl@0
   770
	}
sl@0
   771
sl@0
   772
sl@0
   773
sl@0
   774
sl@0
   775
EXPORT_C void User::InitProcess()
sl@0
   776
/**
sl@0
   777
@internalAll
sl@0
   778
*/
sl@0
   779
	{
sl@0
   780
	CallStaticEntryPoints(ETrue);
sl@0
   781
	}
sl@0
   782
sl@0
   783
sl@0
   784
sl@0
   785
sl@0
   786
EXPORT_C void User::Exit(TInt aReason)
sl@0
   787
/**
sl@0
   788
Terminates the current thread, specifying a reason.
sl@0
   789
All child threads are terminated and all resources are cleaned up.
sl@0
   790
sl@0
   791
If the current thread is the main thread in a process, the process is also 
sl@0
   792
terminated.
sl@0
   793
sl@0
   794
@param aReason The reason code.
sl@0
   795
*/
sl@0
   796
	{
sl@0
   797
	// Notify kernel that thread is exiting
sl@0
   798
	TBool lastThread = Exec::UserThreadExiting(aReason);
sl@0
   799
	if (lastThread)
sl@0
   800
		{
sl@0
   801
		// Call global destructors if we're the last thread in the process
sl@0
   802
		TGlobalDestructorFunc func = (TGlobalDestructorFunc)UserSvr::DllTls(KGlobalDestructorTlsKey, KDllUid_Special);
sl@0
   803
		if (func)
sl@0
   804
			{
sl@0
   805
			func();
sl@0
   806
			CallStaticEntryPoints(EFalse);
sl@0
   807
			}
sl@0
   808
		}
sl@0
   809
	
sl@0
   810
	FOREVER
sl@0
   811
		{
sl@0
   812
		TInt h=Exec::LastThreadHandle();
sl@0
   813
		if (h==0)
sl@0
   814
			break;
sl@0
   815
		if (Exec::HandleClose(h)>0)
sl@0
   816
			RHandleBase::DoExtendedClose();
sl@0
   817
		}
sl@0
   818
sl@0
   819
#ifdef __USERSIDE_THREAD_DATA__
sl@0
   820
	LocalThreadData()->Close();
sl@0
   821
#endif
sl@0
   822
	
sl@0
   823
	ExitCurrentThread(EExitKill,aReason,NULL);
sl@0
   824
	}
sl@0
   825
sl@0
   826
sl@0
   827
sl@0
   828
sl@0
   829
EXPORT_C TInt User::QuickSort(TInt aCount,const TKey &aKey,const TSwap &aSwap)
sl@0
   830
//
sl@0
   831
// Routine sorts a set of records into the order defined by the key aKey.
sl@0
   832
// There are aCount records to sort, each record is numbered, the first is
sl@0
   833
// record 0, the last record aCount-1.
sl@0
   834
// Each time the quicksort algorithm needs to compare two records it calls
sl@0
   835
//     aKey.Compare(TInt n,TInt m).
sl@0
   836
// where n and m (both type TUint) are the record no.s of the two records to compare.
sl@0
   837
// The compare routine should return
sl@0
   838
//     >0 if record(n) > record(m)
sl@0
   839
//      0 if record(n) == record(m)
sl@0
   840
//     <0 if record(n) < record(m)
sl@0
   841
// Each time the quicksort algorithm needs to exchange two records it calls
sl@0
   842
//     aSwap.Swap(n,m)
sl@0
   843
// where n and m (both type TUint) are the record numbers of the two records to 
sl@0
   844
// exchange.
sl@0
   845
// The swap routine should exchange the positions of records n and m so that
sl@0
   846
// the value of record m becomes the former value of record n and visa versa.
sl@0
   847
//
sl@0
   848
/**
sl@0
   849
Quick sorts array elements.
sl@0
   850
sl@0
   851
It is used by the standard Symbian OS arrays having 
sl@0
   852
CArrayFixBase, CArrayVarBase or CArrayPakBase in their class hierarchy in 
sl@0
   853
the implementation of their sort functions. The function can be used by other 
sl@0
   854
arrays. 
sl@0
   855
sl@0
   856
The function returns KErrNone if the operation is successful otherwise it 
sl@0
   857
returns KErrGeneral.
sl@0
   858
sl@0
   859
@param aCount The number of elements in the array.
sl@0
   860
@param aKey   A reference to a suitably initialised TKey derived object.
sl@0
   861
@param aSwap  A reference to a suitably initialised TSwap derived object.
sl@0
   862
sl@0
   863
@return KErrNone if the operation is successful; KErrGeneral otherwise.
sl@0
   864
sl@0
   865
@panic USER 96, if aCount is negative.
sl@0
   866
*/
sl@0
   867
	{
sl@0
   868
	TInt *parts_sp; // Stack pointer for partitions todo
sl@0
   869
	TInt m; // First element of partition
sl@0
   870
	TInt n; // No. of elements in partition
sl@0
   871
	TInt d1,d2; // Temporary variables
sl@0
   872
	TInt division_point; // Seperation point of partitions
sl@0
   873
	TInt parts_todo[KQDepth]; // Stack pairs are <n,base>
sl@0
   874
sl@0
   875
	__ASSERT_ALWAYS(aCount>=0,::Panic(ESortCountNegative));
sl@0
   876
	if (aCount<=1) 
sl@0
   877
		return(KErrNone); // Discard trivial sorts
sl@0
   878
	parts_sp=(&parts_todo[0]); // Reset partitions to do stack
sl@0
   879
	m=0; // Initial limits, first element
sl@0
   880
	n=aCount; // No_elm elements to do
sl@0
   881
	do  {
sl@0
   882
		while (n>1 && parts_sp<(&parts_todo[KQDepth-2]))
sl@0
   883
			{
sl@0
   884
			division_point=partit(n,m,aKey,aSwap);
sl@0
   885
			d1=division_point-m;
sl@0
   886
			d2=m+n-division_point-1;
sl@0
   887
			if (d1<d2)
sl@0
   888
				{
sl@0
   889
				// Less elements in first partition, do it first
sl@0
   890
				// Stack bigger partition for later
sl@0
   891
				*(parts_sp++)=d2;
sl@0
   892
				*(parts_sp++)=division_point+1;
sl@0
   893
				n=d1;
sl@0
   894
				}
sl@0
   895
			else
sl@0
   896
				{
sl@0
   897
				// Less elements in second partition,do it first
sl@0
   898
				// Stack bigger partition for later
sl@0
   899
				*(parts_sp++)=d1;
sl@0
   900
				*(parts_sp++)=m;                      
sl@0
   901
				n=d2;
sl@0
   902
				m=division_point+1;
sl@0
   903
				}
sl@0
   904
			}
sl@0
   905
		if (parts_sp>=&parts_todo[KQDepth-2]) 
sl@0
   906
			return(KErrGeneral); // Stack overflow
sl@0
   907
		m=(*(--parts_sp));
sl@0
   908
		n=(*(--parts_sp)); // Unstack next partit to do
sl@0
   909
		} while (parts_sp>=(&parts_todo[0])); // Stop on stack underflow
sl@0
   910
	return(KErrNone);
sl@0
   911
	}
sl@0
   912
sl@0
   913
sl@0
   914
sl@0
   915
sl@0
   916
EXPORT_C TInt User::BinarySearch(TInt aCount,const TKey &aKey,TInt &aPos)
sl@0
   917
//
sl@0
   918
// Perform a binary search on any array. aKey.Compare() will be
sl@0
   919
// called to lexically compare a record in the array with the
sl@0
   920
// value being searched for. The second index to aKey.Compare() will
sl@0
   921
// always be KIndexPtr, meaning the value being compared. The result
sl@0
   922
// returned will be 0 if a match is found and >0 if no match is found.
sl@0
   923
// The index of the matching record or the index of the record logically
sl@0
   924
// following the value being searched for will be returned in aPos.
sl@0
   925
//
sl@0
   926
/**
sl@0
   927
Performs a binary search for an array element containing a specified key.
sl@0
   928
sl@0
   929
It can be used on any kind of array where elements can be identified by key. 
sl@0
   930
It is used by the standard Symbian OS arrays having CArrayFix, CArrayVar or 
sl@0
   931
CArrayPak in their class hierarchy in the implementation of the various
sl@0
   932
functions for inserting, deleting and finding elements by key. The function
sl@0
   933
can be used by other arrays. 
sl@0
   934
sl@0
   935
The function returns a zero value if the search is successful and a non-zero 
sl@0
   936
value otherwise.
sl@0
   937
sl@0
   938
If the search is successful, the function puts the position (i.e. the index) 
sl@0
   939
of the element into aPos. If the search is unsuccessful, then the function 
sl@0
   940
puts into aPos the position of the first element in the array whose key is 
sl@0
   941
greater than the search key.
sl@0
   942
sl@0
   943
If the array is empty, i.e. aCount is zero, then the search is unsuccessful 
sl@0
   944
and aPos is not defined.
sl@0
   945
sl@0
   946
@param aCount The number of elements in the array.
sl@0
   947
@param aKey   A reference to a suitably initialised TKey derived object.
sl@0
   948
              In particular, the object will have been initialised with
sl@0
   949
              a pointer to a sample element containing the search key.
sl@0
   950
@param aPos   If the element is found, the reference is set to the position of 
sl@0
   951
              that element within the array. The position is relative to zero,
sl@0
   952
              (i.e. the first element in the array is at position 0).
sl@0
   953
              If the element is not found and the array is not empty, then
sl@0
   954
              the reference is set to the position of the first element in
sl@0
   955
              the array with a key which is greater than the search key. 
sl@0
   956
              If the element is not found and the array is empty, then the
sl@0
   957
              reference is undefined.
sl@0
   958
sl@0
   959
@return Zero, if the element with the specified key is found. Non-zero, if 
sl@0
   960
the element with the specified key is not found.
sl@0
   961
sl@0
   962
@panic USER 97, if aCount is negative.
sl@0
   963
*/
sl@0
   964
	{
sl@0
   965
sl@0
   966
	__ASSERT_ALWAYS(aCount>=0,::Panic(EBinarySearchCountNegative));
sl@0
   967
    TInt mid=0;
sl@0
   968
    TInt r=(-1);
sl@0
   969
    if (aCount)
sl@0
   970
        {
sl@0
   971
        TInt low=0;
sl@0
   972
        TInt high=aCount-1;
sl@0
   973
        while (low<=high)
sl@0
   974
            {
sl@0
   975
            mid=(low+high)>>1;
sl@0
   976
            if ((r=aKey.Compare(mid,KIndexPtr))==0)
sl@0
   977
                break;
sl@0
   978
            if (r<0)
sl@0
   979
                low=mid+1;
sl@0
   980
            else
sl@0
   981
                high=mid-1;
sl@0
   982
            }
sl@0
   983
        }
sl@0
   984
	if (r<0)
sl@0
   985
		mid++;
sl@0
   986
    aPos=mid;
sl@0
   987
    return(r);
sl@0
   988
	}
sl@0
   989
sl@0
   990
sl@0
   991
sl@0
   992
sl@0
   993
EXPORT_C TVersion User::Version()
sl@0
   994
/**
sl@0
   995
Retrieves the E32 component version number, which is the kernel architecture version number.  
sl@0
   996
For example for EKA2 the major part of the version number will be 2.
sl@0
   997
sl@0
   998
@return  The E32 component version number.
sl@0
   999
*/
sl@0
  1000
	{
sl@0
  1001
sl@0
  1002
	return(TVersion(KE32MajorVersionNumber,KE32MinorVersionNumber,KE32BuildVersionNumber));
sl@0
  1003
	}
sl@0
  1004
sl@0
  1005
sl@0
  1006
sl@0
  1007
sl@0
  1008
EXPORT_C void User::Invariant()
sl@0
  1009
/**
sl@0
  1010
Panics the current thread with a USER 0 panic.
sl@0
  1011
sl@0
  1012
Typically, this is called when a test for a class invariant fails, i.e. when
sl@0
  1013
a test which checks that the internal data of an object is
sl@0
  1014
self-consistent, fails.
sl@0
  1015
sl@0
  1016
Such tests are almost always done in debug builds, commonly using
sl@0
  1017
the __ASSERT_DEBUG macro.
sl@0
  1018
*/
sl@0
  1019
	{
sl@0
  1020
sl@0
  1021
	::Panic(EInvariantFalse);
sl@0
  1022
	}
sl@0
  1023
sl@0
  1024
sl@0
  1025
sl@0
  1026
sl@0
  1027
EXPORT_C TBool User::QueryVersionSupported(const TVersion &aCurrent,const TVersion &aRequested)
sl@0
  1028
/**
sl@0
  1029
Compares two version objects and returns true if the test version is less 
sl@0
  1030
than the current version.
sl@0
  1031
sl@0
  1032
Version information is encapsulated by a TVersion type object and consists
sl@0
  1033
of a major version number, a minor version number and a build number.
sl@0
  1034
sl@0
  1035
The function returns true if one of the following conditions is true:
sl@0
  1036
sl@0
  1037
1. the test major version is strictly less than the current major version
sl@0
  1038
sl@0
  1039
2. the test major version is equal to the current major version and the test 
sl@0
  1040
   minor version is less than or equal to the current minor version
sl@0
  1041
sl@0
  1042
If neither condition is true, the function returns false.
sl@0
  1043
sl@0
  1044
@param aCurrent   A reference to the current version against which aRequested 
sl@0
  1045
                  is compared.
sl@0
  1046
@param aRequested A reference to the test version to be compared
sl@0
  1047
                  against aCurrent.
sl@0
  1048
                  
sl@0
  1049
@return True, if one or both conditions are true. False otherwise.
sl@0
  1050
*/
sl@0
  1051
	{
sl@0
  1052
sl@0
  1053
	if (aRequested.iMajor<aCurrent.iMajor || (aRequested.iMajor==aCurrent.iMajor && aRequested.iMinor<=aCurrent.iMinor))
sl@0
  1054
		return(ETrue);
sl@0
  1055
	return(EFalse);
sl@0
  1056
	}
sl@0
  1057
sl@0
  1058
sl@0
  1059
sl@0
  1060
sl@0
  1061
EXPORT_C TKey::TKey()
sl@0
  1062
/**
sl@0
  1063
Protected default constructor.
sl@0
  1064
sl@0
  1065
This constructor prevents TKey objects from being constructed directly.
sl@0
  1066
*/
sl@0
  1067
	{}
sl@0
  1068
sl@0
  1069
sl@0
  1070
sl@0
  1071
sl@0
  1072
EXPORT_C TKey::TKey(TInt anOffset,TKeyCmpText aType)
sl@0
  1073
	: iKeyOffset(anOffset),iCmpType(ECmpCollated16+aType+1)
sl@0
  1074
/**
sl@0
  1075
Constructs the characteristics of a descriptor type key.
sl@0
  1076
sl@0
  1077
This constructor should be called by the corresponding derived class
sl@0
  1078
constructor that takes the same arguments. Typically, the derived class
sl@0
  1079
constructor calls this constructor in its constructor initialization list.
sl@0
  1080
sl@0
  1081
No length value is passed as this is implied by the type of key.
sl@0
  1082
sl@0
  1083
Note that the constructor sets the offset value into the protected data member 
sl@0
  1084
iKeyOffset.
sl@0
  1085
sl@0
  1086
@param anOffset The offset of the key from the start of an array element.
sl@0
  1087
@param aType    An enumeration which defines the type of comparison to be made 
sl@0
  1088
                between two descriptor keys.
sl@0
  1089
                
sl@0
  1090
@panic USER 98, if anOffset is negative.
sl@0
  1091
                
sl@0
  1092
@see TKeyCmpText
sl@0
  1093
*/
sl@0
  1094
	{
sl@0
  1095
sl@0
  1096
	__ASSERT_ALWAYS(iKeyOffset>=0,Panic(EKeyOffsetNegative));
sl@0
  1097
	}
sl@0
  1098
sl@0
  1099
sl@0
  1100
sl@0
  1101
sl@0
  1102
EXPORT_C TKey::TKey(TInt anOffset,TKeyCmpText aType,TInt aLength)
sl@0
  1103
	: iKeyOffset(anOffset),iKeyLength(aLength),iCmpType(aType)
sl@0
  1104
/**
sl@0
  1105
Constructs the characteristics of a text key.
sl@0
  1106
sl@0
  1107
This constructor should be called by the corresponding derived class
sl@0
  1108
constructor that takes the same arguments. Typically, the derived class
sl@0
  1109
constructor calls this constructor in its constructor initialization list.
sl@0
  1110
sl@0
  1111
Note that the constructor sets the offset value into the protected data member 
sl@0
  1112
iKeyOffset.
sl@0
  1113
sl@0
  1114
@param anOffset The offset of the key from the start of an array element.
sl@0
  1115
@param aType    An enumeration which defines the type of comparison to be made 
sl@0
  1116
                between two text keys.
sl@0
  1117
@param aLength  The length of the text key.
sl@0
  1118
sl@0
  1119
@panic USER 98, if anOffset is negative.
sl@0
  1120
sl@0
  1121
@see TKeyCmpText
sl@0
  1122
*/
sl@0
  1123
	{
sl@0
  1124
sl@0
  1125
	__ASSERT_ALWAYS(iKeyOffset>=0,Panic(EKeyOffsetNegative));
sl@0
  1126
	}
sl@0
  1127
sl@0
  1128
sl@0
  1129
sl@0
  1130
sl@0
  1131
EXPORT_C TKey::TKey(TInt anOffset,TKeyCmpNumeric aType)
sl@0
  1132
	: iKeyOffset(anOffset),iCmpType(aType)
sl@0
  1133
/**
sl@0
  1134
Constructs the characteristics of a numeric key.
sl@0
  1135
sl@0
  1136
This constructor should be called by the corresponding derived class
sl@0
  1137
constructor that takes the same arguments. Typically, the derived class
sl@0
  1138
constructor calls this constructor in its constructor initialization list.
sl@0
  1139
sl@0
  1140
No length value is passed as this is implied by the type of key.
sl@0
  1141
sl@0
  1142
Note that the constructor sets the offset value into the protected data member 
sl@0
  1143
iKeyOffset.
sl@0
  1144
sl@0
  1145
@param anOffset The offset of the key from the start of an array element.
sl@0
  1146
@param aType    An enumeration which defines the type of the numeric key.
sl@0
  1147
sl@0
  1148
@panic USER 98, if anOffset is negative.
sl@0
  1149
sl@0
  1150
@see TKeyCmpNumeric
sl@0
  1151
*/
sl@0
  1152
	{
sl@0
  1153
sl@0
  1154
	__ASSERT_ALWAYS(iKeyOffset>=0,Panic(EKeyOffsetNegative));
sl@0
  1155
	}
sl@0
  1156
sl@0
  1157
sl@0
  1158
sl@0
  1159
sl@0
  1160
EXPORT_C TInt TKey::Compare(TInt aLeft,TInt aRight) const
sl@0
  1161
/**
sl@0
  1162
Compares the keys of two array elements.
sl@0
  1163
sl@0
  1164
This function is called by User::BinarySearch() and User::QuickSort().
sl@0
  1165
sl@0
  1166
The position of the elements are identified by the specified index values. 
sl@0
  1167
The default implementation uses the At() virtual function to convert the index 
sl@0
  1168
values into pointers to the elements themselves.
sl@0
  1169
sl@0
  1170
The default implementation also uses:
sl@0
  1171
sl@0
  1172
1. the TDesC comparison functions to compare descriptor type keys
sl@0
  1173
sl@0
  1174
2. the Mem functions to compare text type keys
sl@0
  1175
sl@0
  1176
3. numeric comparison for numeric type keys.
sl@0
  1177
sl@0
  1178
@param aLeft  The index of an array element participating in the comparison, 
sl@0
  1179
              designated the left element.
sl@0
  1180
@param aRight The index of an array element participating in the comparison, 
sl@0
  1181
              designated the right element.
sl@0
  1182
              
sl@0
  1183
@return Zero, if the two keys are equal;
sl@0
  1184
        negative, if the left key is less than the right key;
sl@0
  1185
        positive, if the left key is greater than the right key.
sl@0
  1186
        
sl@0
  1187
@see User::BinarySearch()
sl@0
  1188
@see User::QuickSort()
sl@0
  1189
@see TDesC
sl@0
  1190
@see Mem
sl@0
  1191
*/
sl@0
  1192
	{
sl@0
  1193
sl@0
  1194
	UPTR left;
sl@0
  1195
	left.tany=At(aLeft);
sl@0
  1196
	UPTR right;
sl@0
  1197
	// coverity[returned_pointer]
sl@0
  1198
	right.tany=At(aRight);
sl@0
  1199
	TInt r=(-1);
sl@0
  1200
	switch (iCmpType)
sl@0
  1201
		{
sl@0
  1202
#if !defined(_UNICODE)
sl@0
  1203
	case ECmpNormal:
sl@0
  1204
#endif
sl@0
  1205
	case ECmpNormal8:
sl@0
  1206
		r=Mem::Compare(left.ttext8,iKeyLength,right.ttext8,iKeyLength);
sl@0
  1207
		break;
sl@0
  1208
#if defined(_UNICODE)
sl@0
  1209
	case ECmpNormal:
sl@0
  1210
#endif
sl@0
  1211
	case ECmpNormal16:
sl@0
  1212
		r=Mem::Compare(left.ttext16,iKeyLength,right.ttext16,iKeyLength);
sl@0
  1213
		break;
sl@0
  1214
#if !defined(_UNICODE)
sl@0
  1215
	case ECmpFolded:
sl@0
  1216
#endif
sl@0
  1217
	case ECmpFolded8:
sl@0
  1218
		r=Mem::CompareF(left.ttext8,iKeyLength,right.ttext8,iKeyLength);
sl@0
  1219
		break;
sl@0
  1220
#if defined(_UNICODE)
sl@0
  1221
	case ECmpFolded:
sl@0
  1222
#endif
sl@0
  1223
	case ECmpFolded16:
sl@0
  1224
		r=Mem::CompareF(left.ttext16,iKeyLength,right.ttext16,iKeyLength);
sl@0
  1225
		break;
sl@0
  1226
#if !defined(_UNICODE)
sl@0
  1227
	case ECmpCollated:
sl@0
  1228
#endif
sl@0
  1229
	case ECmpCollated8:
sl@0
  1230
		r=Mem::CompareC(left.ttext8,iKeyLength,right.ttext8,iKeyLength);
sl@0
  1231
		break;
sl@0
  1232
#if defined(_UNICODE)
sl@0
  1233
	case ECmpCollated:
sl@0
  1234
#endif
sl@0
  1235
	case ECmpCollated16:
sl@0
  1236
		r=Mem::CompareC(left.ttext16,iKeyLength,right.ttext16,iKeyLength);
sl@0
  1237
		break;
sl@0
  1238
#if !defined(_UNICODE)
sl@0
  1239
	case ECmpCollated16+ECmpNormal+1:
sl@0
  1240
#endif
sl@0
  1241
	case ECmpCollated16+ECmpNormal8+1:
sl@0
  1242
		r=left.tdesc8->Compare(*right.tdesc8);
sl@0
  1243
		break;
sl@0
  1244
#if defined(_UNICODE)
sl@0
  1245
	case ECmpCollated16+ECmpNormal+1:
sl@0
  1246
#endif
sl@0
  1247
	case ECmpCollated16+ECmpNormal16+1:
sl@0
  1248
		r=left.tdesc16->Compare(*right.tdesc16);
sl@0
  1249
		break;
sl@0
  1250
#if !defined(_UNICODE)
sl@0
  1251
	case ECmpCollated16+ECmpFolded+1:
sl@0
  1252
#endif
sl@0
  1253
	case ECmpCollated16+ECmpFolded8+1:
sl@0
  1254
		r=left.tdesc8->CompareF(*right.tdesc8);
sl@0
  1255
		break;
sl@0
  1256
#if defined(_UNICODE)
sl@0
  1257
	case ECmpCollated16+ECmpFolded+1:
sl@0
  1258
#endif
sl@0
  1259
	case ECmpCollated16+ECmpFolded16+1:
sl@0
  1260
		r=left.tdesc16->CompareF(*right.tdesc16);
sl@0
  1261
		break;
sl@0
  1262
#if !defined(_UNICODE)
sl@0
  1263
	case ECmpCollated16+ECmpCollated+1:
sl@0
  1264
#endif
sl@0
  1265
	case ECmpCollated16+ECmpCollated8+1:
sl@0
  1266
		r=left.tdesc8->CompareC(*right.tdesc8);
sl@0
  1267
		break;
sl@0
  1268
#if defined(_UNICODE)
sl@0
  1269
	case ECmpCollated16+ECmpCollated+1:
sl@0
  1270
#endif
sl@0
  1271
	case ECmpCollated16+ECmpCollated16+1:
sl@0
  1272
		r=left.tdesc16->CompareC(*right.tdesc16);
sl@0
  1273
		break;
sl@0
  1274
	case ECmpTInt:
sl@0
  1275
		if (*left.tint==*right.tint)
sl@0
  1276
			r=0;
sl@0
  1277
		else if (*left.tint>*right.tint)
sl@0
  1278
			r=1;
sl@0
  1279
		break;	   
sl@0
  1280
	case ECmpTUint:
sl@0
  1281
		if (*left.tuint==*right.tuint)
sl@0
  1282
			r=0;
sl@0
  1283
		else if (*left.tuint>*right.tuint)
sl@0
  1284
			r=1;
sl@0
  1285
		break;	   
sl@0
  1286
	case ECmpTInt8:
sl@0
  1287
		if (*left.tint8==*right.tint8)
sl@0
  1288
			r=0;
sl@0
  1289
		else if (*left.tint8>*right.tint8)
sl@0
  1290
			r=1;
sl@0
  1291
		break;	   
sl@0
  1292
	case ECmpTUint8:
sl@0
  1293
		if (*left.tuint8==*right.tuint8)
sl@0
  1294
			r=0;
sl@0
  1295
		else if (*left.tuint8>*right.tuint8)
sl@0
  1296
			r=1;
sl@0
  1297
		break;
sl@0
  1298
	case ECmpTInt16:
sl@0
  1299
		if (*left.tint16==*right.tint16)
sl@0
  1300
			r=0;
sl@0
  1301
		else if (*left.tint16>*right.tint16)
sl@0
  1302
			r=1;
sl@0
  1303
		break;	   
sl@0
  1304
	case ECmpTUint16:
sl@0
  1305
		if (*left.tuint16==*right.tuint16)
sl@0
  1306
			r=0;
sl@0
  1307
		else if (*left.tuint16>*right.tuint16)
sl@0
  1308
			r=1;
sl@0
  1309
		break;
sl@0
  1310
	case ECmpTInt32:
sl@0
  1311
		if (*left.tint32==*right.tint32) 
sl@0
  1312
			r=0;
sl@0
  1313
		else if (*left.tint32>*right.tint32) 
sl@0
  1314
			r=1;
sl@0
  1315
		break;	   
sl@0
  1316
	case ECmpTUint32:
sl@0
  1317
		if (*left.tuint32==*right.tuint32)
sl@0
  1318
			r=0;
sl@0
  1319
		else if (*left.tuint32>*right.tuint32)
sl@0
  1320
			r=1;
sl@0
  1321
		break;
sl@0
  1322
	case ECmpTInt64:
sl@0
  1323
		if (*left.tint64==*right.tint64) 
sl@0
  1324
			r=0;
sl@0
  1325
		else if (*left.tint64>*right.tint64) 
sl@0
  1326
			r=1;
sl@0
  1327
		break;	   
sl@0
  1328
		}
sl@0
  1329
	return(r);
sl@0
  1330
	}
sl@0
  1331
sl@0
  1332
sl@0
  1333
sl@0
  1334
sl@0
  1335
EXPORT_C TAny* TKey::At(TInt /*anIndex*/) const
sl@0
  1336
/**
sl@0
  1337
Gets a pointer to the key of a specified array element.
sl@0
  1338
	
sl@0
  1339
The default implementation raises a USER 35 panic.
sl@0
  1340
	
sl@0
  1341
The function is called by TKey::Compare() to compare the keys of two elements.
sl@0
  1342
	
sl@0
  1343
The implementation provided by a derived class must convert the index to a 
sl@0
  1344
pointer to the key within the corresponding element. The implementation depends 
sl@0
  1345
on the design of the array but, as general rule, use the index value to get 
sl@0
  1346
a pointer to the corresponding element and then add the TKey protected data 
sl@0
  1347
member iKeyOffset to this pointer to get a pointer to the key itself.
sl@0
  1348
	
sl@0
  1349
By convention, the index value is relative to zero; i.e. a zero value refers 
sl@0
  1350
to the first element in the array. By this convention, the index can take 
sl@0
  1351
any value between zero and the number of elements within the array minus one.
sl@0
  1352
	
sl@0
  1353
The function must also handle the special index value KIndexPtr. When this 
sl@0
  1354
value is passed, the function should return a pointer to the key within the 
sl@0
  1355
sample element. A pointer to the sample element is held in the protected data 
sl@0
  1356
member iPtr and can be set up using SetPtr().
sl@0
  1357
	
sl@0
  1358
The implementation of this function also assumes that the derived class has 
sl@0
  1359
a pointer to the array itself or has a function for finding it.
sl@0
  1360
	
sl@0
  1361
@param anIndex The index of the array element or the special index value KIndexPtr.
sl@0
  1362
sl@0
  1363
@return An untyped pointer to the key within the specified array element or 
sl@0
  1364
        an untyped pointer to the key within the sample element, if KIndexPtr
sl@0
  1365
        is passed as an argument.
sl@0
  1366
sl@0
  1367
@panic USER 35, if no replacement function has been provided by a derived class.
sl@0
  1368
        
sl@0
  1369
@see TKey::Compare
sl@0
  1370
@see TKey::SetPtr
sl@0
  1371
@see KIndexPtr
sl@0
  1372
*/
sl@0
  1373
	{
sl@0
  1374
sl@0
  1375
	Panic(ETFuncTKeyVirtualAt);
sl@0
  1376
	return(NULL);
sl@0
  1377
	}
sl@0
  1378
sl@0
  1379
sl@0
  1380
sl@0
  1381
sl@0
  1382
EXPORT_C TSwap::TSwap()
sl@0
  1383
/**
sl@0
  1384
Default constructor.
sl@0
  1385
sl@0
  1386
The constructor has an empty implementation.
sl@0
  1387
*/
sl@0
  1388
	{}
sl@0
  1389
sl@0
  1390
sl@0
  1391
sl@0
  1392
sl@0
  1393
EXPORT_C void TSwap::Swap(TInt /*aLeft*/,TInt /*aRight*/) const
sl@0
  1394
/**
sl@0
  1395
Swaps two elements of an array.
sl@0
  1396
	
sl@0
  1397
This function is called by User::QuickSort().
sl@0
  1398
	
sl@0
  1399
The default implementation raises a USER 36 panic.
sl@0
  1400
	
sl@0
  1401
In general, the class must provide a way of translating the indexes representing 
sl@0
  1402
the two elements into pointers to the elements themselves. The Mem::Swap() 
sl@0
  1403
utility function can then be used to swap the two elements. This implies that 
sl@0
  1404
the derived class must contain a pointer to the array itself and have access 
sl@0
  1405
to other information about the array, such as the length of elements.
sl@0
  1406
	
sl@0
  1407
By convention, the index value is relative to zero; i.e. a zero value refers 
sl@0
  1408
to the first element in the array.
sl@0
  1409
	
sl@0
  1410
@param aLeft  The index of an array element participating in the swap
sl@0
  1411
@param aRight The index of an array element participating in the swap
sl@0
  1412
sl@0
  1413
@panic USER 36, if no replacement function has been provided by a derived class.
sl@0
  1414
sl@0
  1415
@see User::QuickSort
sl@0
  1416
@see Mem::Swap
sl@0
  1417
*/
sl@0
  1418
	{
sl@0
  1419
sl@0
  1420
	Panic(ETFuncTSwapVirtualSwap);
sl@0
  1421
	}
sl@0
  1422
sl@0
  1423
sl@0
  1424
sl@0
  1425
sl@0
  1426
EXPORT_C TVersion::TVersion()
sl@0
  1427
/**
sl@0
  1428
Default constructor.
sl@0
  1429
sl@0
  1430
It sets the major, minor and build numbers to zero.
sl@0
  1431
*/
sl@0
  1432
	: iMajor(0),iMinor(0),iBuild(0)
sl@0
  1433
	{}
sl@0
  1434
sl@0
  1435
sl@0
  1436
sl@0
  1437
sl@0
  1438
EXPORT_C TVersion::TVersion(TInt aMajor,TInt aMinor,TInt aBuild)
sl@0
  1439
/**
sl@0
  1440
Constructs the object with the specified major version number, the minor
sl@0
  1441
version number and the build number.
sl@0
  1442
sl@0
  1443
Note that the constructor does not check that the values passed are within
sl@0
  1444
the specified ranges. As the parameters are TInt types, care must be taken to
sl@0
  1445
ensure that values passed do not exceed the specified maxima, otherwise they
sl@0
  1446
will be interpreted as negative values.
sl@0
  1447
sl@0
  1448
@param aMajor The major version number. This must be a number in the
sl@0
  1449
              range 0 to 127.
sl@0
  1450
@param aMinor The minor version number. This must be a number in the
sl@0
  1451
              range 0 to 99.
sl@0
  1452
@param aBuild The build number. This must be a number in the range 0 to 32,767.
sl@0
  1453
sl@0
  1454
*/
sl@0
  1455
	: iMajor((TInt8)aMajor),iMinor((TInt8)aMinor),iBuild((TInt16)aBuild)
sl@0
  1456
	{}
sl@0
  1457
sl@0
  1458
sl@0
  1459
sl@0
  1460
sl@0
  1461
EXPORT_C TVersionName TVersion::Name() const
sl@0
  1462
/**
sl@0
  1463
Gets a descriptor buffer containing the formatted character representation
sl@0
  1464
of the version information.
sl@0
  1465
sl@0
  1466
The general format of the representation is: xxx.yy(zzzzz)
sl@0
  1467
sl@0
  1468
where:
sl@0
  1469
sl@0
  1470
1. xxx is the major version number; depending on the value, this may have
sl@0
  1471
   a length of one, two or three characters.
sl@0
  1472
sl@0
  1473
2. yy is the minor version number; this is always two characters, padded
sl@0
  1474
   with a leading zero, if necessary. 
sl@0
  1475
sl@0
  1476
3. zzzzz is the build number; depending on the value, this may have a length
sl@0
  1477
   of one to 5 characters.
sl@0
  1478
sl@0
  1479
Note that if the object is constructed with values that exceed the permitted
sl@0
  1480
range, they will appear negative in their formatted character representation.
sl@0
  1481
sl@0
  1482
@return A buffer descriptor containing the formatted character representation.
sl@0
  1483
*/
sl@0
  1484
	{
sl@0
  1485
sl@0
  1486
	TVersionName v;
sl@0
  1487
	v.AppendNum(iMajor);
sl@0
  1488
	v.Append(TChar('.'));
sl@0
  1489
	v.AppendNumFixedWidth(iMinor,EDecimal,2);
sl@0
  1490
	v.Append(TChar('('));
sl@0
  1491
	v.AppendNum(iBuild);
sl@0
  1492
	v.Append(TChar(')'));
sl@0
  1493
//	v.Format(_L("%d.%02d(%d)"),iMajor,iMinor,iBuild);
sl@0
  1494
	return(v);
sl@0
  1495
	}
sl@0
  1496
sl@0
  1497
sl@0
  1498
sl@0
  1499
sl@0
  1500
/**
sl@0
  1501
Signals the current thread that the asynchronous request associated with the 
sl@0
  1502
specified request status object is complete.
sl@0
  1503
sl@0
  1504
This function is used to complete an asynchronous request originating in the 
sl@0
  1505
same thread as the code that is currently executing. If a request originates 
sl@0
  1506
in another thread, then executing code must use RThread::RequestComplete() 
sl@0
  1507
to signal the completion of that request.
sl@0
  1508
sl@0
  1509
The request is completed with the completion code passed in aReason. This 
sl@0
  1510
value is copied into the request status, pointed to by aStatus, before 
sl@0
  1511
signalling the current thread's request semaphore.
sl@0
  1512
sl@0
  1513
The meaning of the completion code passed in aReason is a matter of convention 
sl@0
  1514
to be decided between the service requester and the service provider.
sl@0
  1515
sl@0
  1516
@param aStatus A reference to a pointer to the request status object. This 
sl@0
  1517
               is a pointer into the current thread's address space. 
sl@0
  1518
               On return, the pointer to the request status is set to NULL.
sl@0
  1519
               Note that setting the pointer to NULL is a convenience, 
sl@0
  1520
               not all servers need it, and is done before 
sl@0
  1521
               the function returns.
sl@0
  1522
               
sl@0
  1523
@param aReason The completion code of this request.
sl@0
  1524
sl@0
  1525
@see  RThread::RequestComplete
sl@0
  1526
*/
sl@0
  1527
EXPORT_C void User::RequestComplete(TRequestStatus * &aStatus,TInt aReason)
sl@0
  1528
	{
sl@0
  1529
	*aStatus=KRequestPending;
sl@0
  1530
	RThread().RequestComplete(aStatus,aReason);
sl@0
  1531
	}
sl@0
  1532
sl@0
  1533
sl@0
  1534
sl@0
  1535
sl@0
  1536
EXPORT_C TLdrInfo::TLdrInfo()
sl@0
  1537
//
sl@0
  1538
// Constructor
sl@0
  1539
//
sl@0
  1540
	{
sl@0
  1541
	memclr(this, sizeof(TLdrInfo));
sl@0
  1542
	iRequestedVersion = KModuleVersionWild;
sl@0
  1543
	}
sl@0
  1544
sl@0
  1545
EXPORT_C TPtrC8 TCodeSegCreateInfo::RootName() const
sl@0
  1546
	{
sl@0
  1547
	return iFileName.Mid(iRootNameOffset,iRootNameLength);
sl@0
  1548
	}
sl@0
  1549
sl@0
  1550
EXPORT_C TBool TUid::operator==(const TUid& aUid) const
sl@0
  1551
/**
sl@0
  1552
Compares two UIDs for equality.
sl@0
  1553
sl@0
  1554
@param aUid The UID to be compared with this UID.
sl@0
  1555
sl@0
  1556
@return True, if the two UIDs are equal; false otherwise. 
sl@0
  1557
*/
sl@0
  1558
	{
sl@0
  1559
sl@0
  1560
	return(iUid==aUid.iUid);
sl@0
  1561
	}
sl@0
  1562
sl@0
  1563
sl@0
  1564
sl@0
  1565
sl@0
  1566
EXPORT_C TBool TUid::operator!=(const TUid& aUid) const
sl@0
  1567
/**
sl@0
  1568
Compares two UIDs for inequality.
sl@0
  1569
sl@0
  1570
@param aUid The UID to be compared with this UID.
sl@0
  1571
sl@0
  1572
@return True, if the two UIDs are unequal; false otherwise. 
sl@0
  1573
*/
sl@0
  1574
	{
sl@0
  1575
sl@0
  1576
	return(iUid!=aUid.iUid);
sl@0
  1577
	}
sl@0
  1578
sl@0
  1579
sl@0
  1580
sl@0
  1581
sl@0
  1582
EXPORT_C TUidName TUid::Name() const
sl@0
  1583
/**
sl@0
  1584
Generates and returns the standard text form of the UID.
sl@0
  1585
sl@0
  1586
The resulting text has the form:
sl@0
  1587
sl@0
  1588
@code
sl@0
  1589
[12345678]
sl@0
  1590
@endcode
sl@0
  1591
sl@0
  1592
The function always generates 10 characters, where the first and last characters 
sl@0
  1593
are open and close square brackets enclosing exactly 8 hexadecimal digits 
sl@0
  1594
(padded to the left with zeroes, if necessary).
sl@0
  1595
sl@0
  1596
@return A modifiable descriptor containing the standard text format of the 
sl@0
  1597
        UID.
sl@0
  1598
*/
sl@0
  1599
	{
sl@0
  1600
sl@0
  1601
	TUidName n;
sl@0
  1602
	n.Append(TChar('['));
sl@0
  1603
	n.AppendNumFixedWidth(iUid,EHex,8);
sl@0
  1604
	n.Append(TChar(']'));
sl@0
  1605
//	n.Format(_L("[%08x]"),iUid);
sl@0
  1606
	return(n);
sl@0
  1607
	}
sl@0
  1608
sl@0
  1609
sl@0
  1610
sl@0
  1611
sl@0
  1612
EXPORT_C TUidType::TUidType()
sl@0
  1613
/**
sl@0
  1614
Default constructor.
sl@0
  1615
sl@0
  1616
Creates a UID type, and sets all three component UIDs to KNullUid.
sl@0
  1617
*/
sl@0
  1618
    {
sl@0
  1619
sl@0
  1620
	Mem::FillZ(this,sizeof(TUidType));
sl@0
  1621
    }
sl@0
  1622
sl@0
  1623
sl@0
  1624
sl@0
  1625
sl@0
  1626
EXPORT_C TUidType::TUidType(TUid aUid1)
sl@0
  1627
/**
sl@0
  1628
Constructor that creates a UID type and sets the UID1 component
sl@0
  1629
to the specified value.
sl@0
  1630
sl@0
  1631
The UID2 and UID3 components are set to KNullUid.
sl@0
  1632
sl@0
  1633
@param aUid1 Value for UID1.
sl@0
  1634
*/
sl@0
  1635
    {
sl@0
  1636
sl@0
  1637
sl@0
  1638
	Mem::FillZ(this,sizeof(TUidType));
sl@0
  1639
    iUid[0]=aUid1;
sl@0
  1640
    }
sl@0
  1641
sl@0
  1642
sl@0
  1643
sl@0
  1644
sl@0
  1645
EXPORT_C TUidType::TUidType(TUid aUid1,TUid aUid2)
sl@0
  1646
/**
sl@0
  1647
Constructor that creates a UID type and sets the UID1 and UID2 components
sl@0
  1648
to the specified values. 
sl@0
  1649
sl@0
  1650
The UID3 component is set to KNullUid.
sl@0
  1651
sl@0
  1652
@param aUid1 Value for UID1. 
sl@0
  1653
@param aUid2 Value for UID2.
sl@0
  1654
*/
sl@0
  1655
    {
sl@0
  1656
sl@0
  1657
    iUid[0]=aUid1;
sl@0
  1658
    iUid[1]=aUid2;
sl@0
  1659
    iUid[2]=KNullUid;
sl@0
  1660
    }
sl@0
  1661
sl@0
  1662
sl@0
  1663
sl@0
  1664
sl@0
  1665
EXPORT_C TUidType::TUidType(TUid aUid1,TUid aUid2,TUid aUid3)
sl@0
  1666
/**
sl@0
  1667
Constructor that creates a UID type and sets all three UID components
sl@0
  1668
to the specified values.
sl@0
  1669
sl@0
  1670
@param aUid1 Value for UID1.
sl@0
  1671
@param aUid2 Value for UID2.
sl@0
  1672
@param aUid3 Value for UID3.
sl@0
  1673
*/
sl@0
  1674
    {
sl@0
  1675
sl@0
  1676
sl@0
  1677
    iUid[0]=aUid1;
sl@0
  1678
    iUid[1]=aUid2;
sl@0
  1679
    iUid[2]=aUid3;
sl@0
  1680
    }
sl@0
  1681
sl@0
  1682
sl@0
  1683
sl@0
  1684
sl@0
  1685
EXPORT_C TBool TUidType::operator==(const TUidType& aUidType) const
sl@0
  1686
/**
sl@0
  1687
Compares this UID type for equality with the specified UID type.
sl@0
  1688
sl@0
  1689
@param aUidType The UID type to be compared. 
sl@0
  1690
sl@0
  1691
@return True, if each component UID is equal to the corresponding component 
sl@0
  1692
        UID in the specified UID type; false, otherwise.
sl@0
  1693
*/
sl@0
  1694
    {
sl@0
  1695
sl@0
  1696
    return(iUid[0]==aUidType.iUid[0] &&
sl@0
  1697
           iUid[1]==aUidType.iUid[1] &&
sl@0
  1698
           iUid[2]==aUidType.iUid[2]);
sl@0
  1699
    }
sl@0
  1700
sl@0
  1701
sl@0
  1702
sl@0
  1703
sl@0
  1704
EXPORT_C TBool TUidType::operator!=(const TUidType& aUidType) const
sl@0
  1705
/** 
sl@0
  1706
Compares this UID type for inequality with the specified UID type.
sl@0
  1707
sl@0
  1708
@param aUidType The UID type to be compared.
sl@0
  1709
sl@0
  1710
@return True, if any component UID is not equal to the corresponding component 
sl@0
  1711
UID in the specified UID type; false otherwise.
sl@0
  1712
*/
sl@0
  1713
    {
sl@0
  1714
sl@0
  1715
sl@0
  1716
    return(!(*this==aUidType));
sl@0
  1717
    }
sl@0
  1718
sl@0
  1719
sl@0
  1720
sl@0
  1721
sl@0
  1722
EXPORT_C const TUid& TUidType::operator[](TInt aIndex) const
sl@0
  1723
/**
sl@0
  1724
Gets the UID component as identified by the specified index.
sl@0
  1725
sl@0
  1726
@param aIndex Index value indicating which UID component to return.
sl@0
  1727
               0 specifies UID1,
sl@0
  1728
               1 specifies UID2,
sl@0
  1729
               2 specifies UID3.
sl@0
  1730
sl@0
  1731
@return A reference to the required UID component.
sl@0
  1732
sl@0
  1733
@panic USER 37 if aIndex is not in the range 0 to 2, inclusive.
sl@0
  1734
*/
sl@0
  1735
    {
sl@0
  1736
sl@0
  1737
	__ASSERT_ALWAYS(aIndex>=0 && aIndex<KMaxCheckedUid,Panic(ETFuncUidTypeBadIndex));
sl@0
  1738
	return(iUid[aIndex]);
sl@0
  1739
    }
sl@0
  1740
sl@0
  1741
sl@0
  1742
sl@0
  1743
sl@0
  1744
EXPORT_C TUid TUidType::MostDerived() const
sl@0
  1745
/**
sl@0
  1746
Gets the most derived UID.
sl@0
  1747
sl@0
  1748
Taking the three UID components as a hierarchy with UID1 being the most general, 
sl@0
  1749
UID2 being more specific than UID1 and UID3 being more specific than UID2, 
sl@0
  1750
then the function returns:
sl@0
  1751
sl@0
  1752
UID3, if UID3 is not KNullUid.
sl@0
  1753
sl@0
  1754
UID2, if UID2 is not KNullUid.
sl@0
  1755
sl@0
  1756
UID1, otherwise
sl@0
  1757
sl@0
  1758
@return The most derived UID.
sl@0
  1759
sl@0
  1760
@see KNullUid
sl@0
  1761
*/
sl@0
  1762
    {
sl@0
  1763
sl@0
  1764
    if (iUid[2]!=KNullUid)
sl@0
  1765
        return(iUid[2]);
sl@0
  1766
    if (iUid[1]!=KNullUid)
sl@0
  1767
        return(iUid[1]);
sl@0
  1768
    return(iUid[0]);
sl@0
  1769
    }
sl@0
  1770
sl@0
  1771
sl@0
  1772
sl@0
  1773
sl@0
  1774
EXPORT_C TBool TUidType::IsPresent(TUid aUid) const
sl@0
  1775
/**
sl@0
  1776
Tests if any of the component UIDs are equal to the specified UID.
sl@0
  1777
sl@0
  1778
@param aUid The UID to be tested.
sl@0
  1779
sl@0
  1780
@return True, if any one of the component UIDs are the same as the specified 
sl@0
  1781
        UID; false, if none of the component UIDs are the same.
sl@0
  1782
*/
sl@0
  1783
    {
sl@0
  1784
sl@0
  1785
	return(iUid[0]==aUid || iUid[1]==aUid || iUid[2]==aUid);
sl@0
  1786
    }
sl@0
  1787
sl@0
  1788
sl@0
  1789
sl@0
  1790
sl@0
  1791
EXPORT_C TBool TUidType::IsValid() const
sl@0
  1792
/**
sl@0
  1793
Tests the object for a valid (non-KNullUid) UID type.
sl@0
  1794
sl@0
  1795
@return True, if at least one of the component UIDs is not KNullUid; false, 
sl@0
  1796
        if all component UIDs are KNullUid.
sl@0
  1797
sl@0
  1798
@see KNullUid
sl@0
  1799
*/
sl@0
  1800
    {
sl@0
  1801
sl@0
  1802
    return(MostDerived()!=KNullUid);
sl@0
  1803
    }
sl@0
  1804
sl@0
  1805
sl@0
  1806
sl@0
  1807
sl@0
  1808
EXPORT_C TCheckedUid::TCheckedUid()
sl@0
  1809
/**
sl@0
  1810
Default constructor.
sl@0
  1811
sl@0
  1812
Initialises the object to binary zeroes.
sl@0
  1813
*/
sl@0
  1814
	{
sl@0
  1815
sl@0
  1816
	Mem::FillZ(this,sizeof(TCheckedUid));
sl@0
  1817
	}
sl@0
  1818
sl@0
  1819
sl@0
  1820
sl@0
  1821
sl@0
  1822
EXPORT_C TCheckedUid::TCheckedUid(const TUidType& aUidType)
sl@0
  1823
/**
sl@0
  1824
Constructor taking an existing Uid type.
sl@0
  1825
sl@0
  1826
The constructor calculates a checksum.
sl@0
  1827
sl@0
  1828
@param aUidType The Uid type to be packaged.
sl@0
  1829
*/
sl@0
  1830
	{
sl@0
  1831
sl@0
  1832
    Set(aUidType);
sl@0
  1833
    }
sl@0
  1834
sl@0
  1835
sl@0
  1836
sl@0
  1837
sl@0
  1838
EXPORT_C TCheckedUid::TCheckedUid(const TDesC8& aPtr)
sl@0
  1839
/**
sl@0
  1840
Constructor taking an existing TCheckedUid object encapsulated within
sl@0
  1841
a descriptor.
sl@0
  1842
sl@0
  1843
The checksum is recalculated and must match the checksum value passed in the 
sl@0
  1844
encapsulated TCheckedUid object, otherwise the content of this object is reset 
sl@0
  1845
to binary zeroes.
sl@0
  1846
sl@0
  1847
@param aPtr A pointer to a descriptor containing an existing TCheckedUid object. 
sl@0
  1848
                        
sl@0
  1849
@panic USER 38 If the length of the descriptor is not the same as the size 
sl@0
  1850
       of a TCheckedUid object.
sl@0
  1851
*/
sl@0
  1852
	{
sl@0
  1853
sl@0
  1854
	Set(aPtr);
sl@0
  1855
	}
sl@0
  1856
sl@0
  1857
sl@0
  1858
sl@0
  1859
sl@0
  1860
EXPORT_C void TCheckedUid::Set(const TUidType& aUidType)
sl@0
  1861
/**
sl@0
  1862
Sets the specified Uid type to be packaged, and recalculates the checksum.
sl@0
  1863
sl@0
  1864
@param aUidType The Uid type to be packaged.
sl@0
  1865
*/
sl@0
  1866
	{
sl@0
  1867
sl@0
  1868
    iType=aUidType;
sl@0
  1869
    iCheck=Check();
sl@0
  1870
    }
sl@0
  1871
sl@0
  1872
sl@0
  1873
sl@0
  1874
sl@0
  1875
EXPORT_C void TCheckedUid::Set(const TDesC8& aPtr)
sl@0
  1876
/**
sl@0
  1877
Sets an existing TCheckedUid object encapsulated within a descriptor.
sl@0
  1878
sl@0
  1879
The checksum is recalculated and must match the checksum value passed in the 
sl@0
  1880
encapsulated TCheckedUid object, otherwise the content of this object is reset 
sl@0
  1881
to binary zeroes.
sl@0
  1882
sl@0
  1883
@param aPtr A pointer to a descriptor containing an existing
sl@0
  1884
            TCheckedUid object.
sl@0
  1885
sl@0
  1886
@panic USER 38 If the length of the descriptor is not the same as the size 
sl@0
  1887
       of a TCheckedUid object.
sl@0
  1888
*/
sl@0
  1889
	{
sl@0
  1890
sl@0
  1891
	__ASSERT_ALWAYS(aPtr.Length()==sizeof(TCheckedUid),Panic(ETFuncCheckedUidBadSet));
sl@0
  1892
	Mem::Move(this,aPtr.Ptr(),sizeof(TCheckedUid));
sl@0
  1893
	if (iCheck!=Check())
sl@0
  1894
		Mem::FillZ(this,sizeof(TCheckedUid));
sl@0
  1895
	}
sl@0
  1896
sl@0
  1897
sl@0
  1898
sl@0
  1899
sl@0
  1900
EXPORT_C TPtrC8 TCheckedUid::Des() const
sl@0
  1901
/**
sl@0
  1902
Gets a pointer descriptor to represent this object's data.
sl@0
  1903
sl@0
  1904
@return The pointer descriptor for this object's data. The descriptor's length
sl@0
  1905
        is the same as the length of a TCheckedUid object.
sl@0
  1906
*/
sl@0
  1907
	{
sl@0
  1908
sl@0
  1909
	return(TPtrC8((const TUint8*)this,sizeof(TCheckedUid)));
sl@0
  1910
	}
sl@0
  1911
sl@0
  1912
sl@0
  1913
sl@0
  1914
sl@0
  1915
EXPORT_C TUint TCheckedUid::Check() const
sl@0
  1916
/**
sl@0
  1917
Calculates the checksum of the UIDs.
sl@0
  1918
sl@0
  1919
@return The checksum.
sl@0
  1920
*/
sl@0
  1921
	{
sl@0
  1922
sl@0
  1923
	return((checkSum(((TUint8*)this)+1)<<16)|checkSum(this));
sl@0
  1924
	}
sl@0
  1925
sl@0
  1926
sl@0
  1927
sl@0
  1928
sl@0
  1929
EXPORT_C TInt User::InfoPrint(const TDesC& aDes)
sl@0
  1930
/**
sl@0
  1931
Invokes the notifier server to display a text message on the screen for a short 
sl@0
  1932
time. 
sl@0
  1933
sl@0
  1934
@param aDes A reference to the descriptor containing the text to be sent to 
sl@0
  1935
            the notifier server.
sl@0
  1936
            
sl@0
  1937
@return KErrNone if successful, otherwise one of the system-wide error codes.
sl@0
  1938
sl@0
  1939
@see RNotifier
sl@0
  1940
*/
sl@0
  1941
	{
sl@0
  1942
sl@0
  1943
	RNotifier notif;
sl@0
  1944
	TInt r=notif.Connect();
sl@0
  1945
	if (r!=KErrNone)
sl@0
  1946
		return(KErrGeneral);
sl@0
  1947
	r=notif.InfoPrint(aDes);
sl@0
  1948
	notif.Close();
sl@0
  1949
	return(r);
sl@0
  1950
	}
sl@0
  1951
sl@0
  1952
static const TUint32 CrcTab32[256] =
sl@0
  1953
	{
sl@0
  1954
	0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
sl@0
  1955
	0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
sl@0
  1956
	0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
sl@0
  1957
	0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
sl@0
  1958
	0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
sl@0
  1959
	0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
sl@0
  1960
	0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
sl@0
  1961
	0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
sl@0
  1962
	0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
sl@0
  1963
	0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
sl@0
  1964
	0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
sl@0
  1965
	0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
sl@0
  1966
	0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
sl@0
  1967
	0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
sl@0
  1968
	0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
sl@0
  1969
	0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
sl@0
  1970
	0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
sl@0
  1971
	0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
sl@0
  1972
	0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
sl@0
  1973
	0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
sl@0
  1974
	0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
sl@0
  1975
	0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
sl@0
  1976
	0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
sl@0
  1977
	0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
sl@0
  1978
	0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
sl@0
  1979
	0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
sl@0
  1980
	0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
sl@0
  1981
	0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
sl@0
  1982
	0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
sl@0
  1983
	0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
sl@0
  1984
	0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
sl@0
  1985
	0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
sl@0
  1986
	0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
sl@0
  1987
	0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
sl@0
  1988
	0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
sl@0
  1989
	0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
sl@0
  1990
	0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
sl@0
  1991
	0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
sl@0
  1992
	0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
sl@0
  1993
	0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
sl@0
  1994
	0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
sl@0
  1995
	0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
sl@0
  1996
	0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
sl@0
  1997
	0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
sl@0
  1998
	0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
sl@0
  1999
	0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
sl@0
  2000
	0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
sl@0
  2001
	0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
sl@0
  2002
	0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
sl@0
  2003
	0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
sl@0
  2004
	0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
sl@0
  2005
	0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
sl@0
  2006
	0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
sl@0
  2007
	0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
sl@0
  2008
	0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
sl@0
  2009
	0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
sl@0
  2010
	0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
sl@0
  2011
	0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
sl@0
  2012
	0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
sl@0
  2013
	0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
sl@0
  2014
	0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
sl@0
  2015
	0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
sl@0
  2016
	0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
sl@0
  2017
	0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
sl@0
  2018
	};
sl@0
  2019
sl@0
  2020
/**
sl@0
  2021
Performs a CCITT CRC-32 checksum on the specified data.
sl@0
  2022
sl@0
  2023
On return from this function, the referenced 32 bit integer contains the CRC
sl@0
  2024
value.
sl@0
  2025
sl@0
  2026
@param aCrc		A reference to a 32 bit integer to contain the CRC value. 
sl@0
  2027
@param aPtr		A pointer to the start of the data to be checksummed. 
sl@0
  2028
@param aLength	The length of the data to be checksummed.
sl@0
  2029
*/
sl@0
  2030
EXPORT_C void Mem::Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength)
sl@0
  2031
	{
sl@0
  2032
	const TUint8* p = (const TUint8*)aPtr;
sl@0
  2033
	const TUint8* q = p + aLength;
sl@0
  2034
	TUint32 crc = aCrc;
sl@0
  2035
	while (p < q)
sl@0
  2036
		crc = (crc >> 8) ^ CrcTab32[(crc ^ *p++) & 0xff];
sl@0
  2037
	aCrc = crc;
sl@0
  2038
	}