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