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