|
1 // Copyright (c) 1997-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 "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 // Written by DavidW, October 1996 |
|
15 // Descriptor arrays |
|
16 // |
|
17 // |
|
18 |
|
19 #include <badesca.h> |
|
20 |
|
21 |
|
22 // Class to provide an interface for Sort function - two variants |
|
23 // for 8 and 16-bit descriptors. (should this be templated? -PNJ) |
|
24 |
|
25 |
|
26 NONSHARABLE_CLASS(TKeyDesC8Array) : public TKeyArrayFix |
|
27 { |
|
28 public: |
|
29 TKeyDesC8Array(TKeyCmpText aType); |
|
30 private: // from TKey |
|
31 TInt Compare(TInt aLeft,TInt aRight) const; |
|
32 }; |
|
33 |
|
34 TKeyDesC8Array::TKeyDesC8Array(TKeyCmpText aType) |
|
35 : TKeyArrayFix(0,aType,0) |
|
36 { |
|
37 } |
|
38 |
|
39 TInt TKeyDesC8Array::Compare(TInt aLeft,TInt aRight) const |
|
40 { |
|
41 TDesC8* left=(*(TDesC8**)At(aLeft)); |
|
42 TDesC8* right=(*(TDesC8**)At(aRight)); |
|
43 switch (iCmpType) |
|
44 { |
|
45 case ECmpFolded: |
|
46 return(left->CompareF(*right)); |
|
47 case ECmpCollated: |
|
48 return(left->CompareC(*right)); |
|
49 default: |
|
50 break; |
|
51 } |
|
52 return(left->Compare(*right)); |
|
53 } |
|
54 |
|
55 |
|
56 NONSHARABLE_CLASS(TKeyDesC16Array) : public TKeyArrayFix |
|
57 { |
|
58 public: |
|
59 TKeyDesC16Array(TKeyCmpText aType); |
|
60 private: // from TKey |
|
61 TInt Compare(TInt aLeft,TInt aRight) const; |
|
62 }; |
|
63 |
|
64 TKeyDesC16Array::TKeyDesC16Array(TKeyCmpText aType) |
|
65 : TKeyArrayFix(0,aType,0) |
|
66 { |
|
67 } |
|
68 |
|
69 TInt TKeyDesC16Array::Compare(TInt aLeft,TInt aRight) const |
|
70 { |
|
71 TDesC16* left=(*(TDesC16**)At(aLeft)); |
|
72 TDesC16* right=(*(TDesC16**)At(aRight)); |
|
73 switch (iCmpType) |
|
74 { |
|
75 case ECmpFolded: |
|
76 return(left->CompareF(*right)); |
|
77 case ECmpCollated: |
|
78 return(left->CompareC(*right)); |
|
79 default: |
|
80 break; |
|
81 } |
|
82 return(left->Compare(*right)); |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 // CDesCxArray implementation... |
|
88 |
|
89 |
|
90 EXPORT_C CDesC8Array::CDesC8Array(TBufRep aRep,TInt aGranularity) |
|
91 : CArrayFixBase(aRep,sizeof(HBufC8*),aGranularity) |
|
92 { |
|
93 } |
|
94 |
|
95 EXPORT_C CDesC8Array::~CDesC8Array() |
|
96 /** Frees all resources owned by the object, prior to its destruction. In particular, |
|
97 it deletes all descriptors from the array and frees the memory allocated to |
|
98 the array buffer. */ |
|
99 { |
|
100 Reset(); |
|
101 } |
|
102 |
|
103 EXPORT_C void CDesC8Array::Reset() |
|
104 /** Deletes all descriptors from the array and frees the memory allocated to the |
|
105 array buffer. |
|
106 |
|
107 @see CDesC8Array::Delete() */ |
|
108 { |
|
109 Delete(0,Count()); |
|
110 } |
|
111 |
|
112 EXPORT_C void CDesC8Array::Delete(TInt aIndex) |
|
113 { |
|
114 Delete(aIndex,1); |
|
115 } |
|
116 |
|
117 /** |
|
118 * |
|
119 * Deletes one or more logically contiguous descriptor elements from the |
|
120 * array. |
|
121 * |
|
122 * The deletion starts at the specified position.Deleting descriptor |
|
123 * elements from the array frees the memory occupied by the associated |
|
124 * heap descriptors and removes their pointers from the array buffer but |
|
125 * does not cause the array buffer to be automatically compressed. Call |
|
126 * the Compress() function to return excess space in the array buffer to |
|
127 * the heap. |
|
128 * |
|
129 * @param " TInt aPos " |
|
130 * The starting position in the array from which |
|
131 * descriptor elements are to be deleted. The position is |
|
132 * relative to zero, i.e. zero implies the first |
|
133 * descriptor element. This value must not be negative |
|
134 * and must not be greater than the number of descriptor |
|
135 * elements currently in the array, otherwise the |
|
136 * functions raise an E32USER-CBase 21 panic. |
|
137 * @param " TInt aCount " |
|
138 * If specified, the number of contiguous descriptor |
|
139 * elements to be deleted from the array. This value must |
|
140 * not be negative otherwise the function raises an |
|
141 * E32USER-CBase 22 panic. This value plus the value of |
|
142 * the starting position must not be greater than the |
|
143 * number of descriptor elements in the array, otherwise |
|
144 * the function raises an E32USER-CBase 29 panic. This |
|
145 * value must not be negative otherwise the function |
|
146 * raises an E32USER-CBase 22 panic. This value plus the |
|
147 * value of the starting position must not be greater |
|
148 * than the number of descriptor elements in the array, |
|
149 * otherwise the function raises an E32USER-CBase 29 |
|
150 * panic. If not specified, one element is assumed. |
|
151 */ |
|
152 EXPORT_C void CDesC8Array::Delete(TInt aIndex,TInt aCount) |
|
153 { |
|
154 TInt count=aCount; |
|
155 for (TInt ii=aIndex; count--; ii++) |
|
156 User::Free(*(HBufC8**)At(ii)); |
|
157 CArrayFixBase::Delete(aIndex,aCount); |
|
158 } |
|
159 |
|
160 EXPORT_C TInt CDesC8Array::MdcaCount() const |
|
161 /** Returns the number of descriptor elements in the array. The function implements |
|
162 the interface MDesC8Array::MdcaCount(). |
|
163 |
|
164 @return The number of descriptor elements. */ |
|
165 { |
|
166 return Count(); |
|
167 } |
|
168 |
|
169 EXPORT_C TPtrC8 CDesC8Array::MdcaPoint(TInt anIndex) const |
|
170 /** Indexes into a descriptor array. The function implements the interface |
|
171 MDesC8Array::MdcaPoint(). |
|
172 |
|
173 @param aIndex The position of the descriptor element within the array. The |
|
174 position is relative to zero; i.e. zero implies the first descriptor element |
|
175 in the array. This value must be non-negative and less than the number of |
|
176 descriptors currently within the array otherwise the operator panics with |
|
177 EArrayIndexOutOfRange. |
|
178 @return A non-modifiable pointer descriptor representing the descriptor element |
|
179 located at position aIndex within the array. */ |
|
180 { |
|
181 HBufC8* temp=(*(HBufC8**)At(anIndex)); |
|
182 return (TPtrC8)(*temp); |
|
183 } |
|
184 |
|
185 EXPORT_C void CDesC8Array::AppendL(const TDesC8& aPtr) |
|
186 /** Appends a descriptor onto the end of any existing descriptor elements in the |
|
187 array. |
|
188 |
|
189 @param aPtr A reference to the descriptor to be appended to the array. |
|
190 @leave KErrNoMemory There is insufficient memory available. If the function |
|
191 leaves, the array is left in the state it was in before the call. */ |
|
192 { |
|
193 InsertL(Count(),aPtr); |
|
194 } |
|
195 |
|
196 EXPORT_C void CDesC8Array::InsertL(TInt aPos,const TDesC8& aPtr) |
|
197 /** Inserts a descriptor into the array at the specified position. |
|
198 |
|
199 If the specified position is the same as the current number of descriptor |
|
200 elements in the array, this has the effect of appending the element. |
|
201 |
|
202 @param aPos The position within the array where the descriptor element is |
|
203 to be inserted. The position is relative to zero, i.e. zero implies the first |
|
204 descriptor element. This value must not be negative and must not be greater |
|
205 than the number of descriptor elements currently in the array, otherwise the |
|
206 function rasises an E32USER-CBase 21 panic. |
|
207 @param aPtr The descriptor to be inserted into the array. |
|
208 @leave KErrNoMemory There is insufficient memory available. If the function |
|
209 leaves, the array is left in the state it was in before the call. */ |
|
210 { |
|
211 HBufC8* bufPtr=aPtr.AllocLC(); |
|
212 CArrayFixBase::InsertL(aPos,&bufPtr); |
|
213 CleanupStack::Pop(); |
|
214 } |
|
215 |
|
216 EXPORT_C TInt CDesC8Array::InsertIsqL(const TDesC8& aPtr,TKeyCmpText aTextComparisonType) |
|
217 /** Inserts a descriptor into the array at a position which maintains the |
|
218 sequence of the descriptors. |
|
219 |
|
220 The sequence is determined by comparing descriptors using one of the TDesC |
|
221 comparison functions. The enumeration aTextComparisonType governs how the |
|
222 descriptors are to be compared. |
|
223 |
|
224 The array should already be in sequence, otherwise the position of the new |
|
225 descriptor element is unpredictable. Descriptor elements which are the same |
|
226 are not permitted. |
|
227 |
|
228 @param aPtr A reference to the descriptor to be inserted into the array. |
|
229 @param aTextComparisonType An enumeration which determines the type of |
|
230 comparison to be made between descriptors for the purpose of choosing the |
|
231 insertion position. If no parameter is explicitly passed, ECmpFolded is used |
|
232 by default. |
|
233 @leave KErrAlreadyExists A descriptor with the same data (i.e. the same length |
|
234 and the same content) already exists within the array. |
|
235 @leave KErrNoMemory There is insufficient memory available. If the function |
|
236 leaves, the array is left in the state it was in before the call. |
|
237 @return The position within the array of the inserted descriptor. */ |
|
238 { |
|
239 HBufC8* bufPtr=aPtr.AllocLC(); |
|
240 TKeyDesC8Array key(aTextComparisonType); |
|
241 TInt found=CArrayFixBase::InsertIsqL(&bufPtr,key); |
|
242 CleanupStack::Pop(); |
|
243 return(found); |
|
244 } |
|
245 |
|
246 EXPORT_C TInt CDesC8Array::InsertIsqAllowDuplicatesL(const TDesC8& aPtr,TKeyCmpText aTextComparisonType) |
|
247 /** Inserts a descriptor into the array at a position which maintains the |
|
248 sequence of the descriptors - allows duplicates. |
|
249 |
|
250 The sequence is determined by comparing descriptors using one of the TDesC |
|
251 comparison functions. The enumeration aTextComparisonType governs how the |
|
252 descriptors are to be compared. |
|
253 |
|
254 The array should already be in sequence, otherwise the position of the new |
|
255 descriptor element is unpredictable. Descriptor elements which are the same |
|
256 are permitted; if the descriptor aPtr is a duplicate of an existing descriptor |
|
257 within the array, then the new descriptor element is positioned after the |
|
258 existing descriptor element. |
|
259 |
|
260 @param aPtr A reference to the descriptor to be inserted into the array. |
|
261 @param aTextComparisonType An enumeration which determines the type of comparison |
|
262 to be made between descriptors for the purpose of choosing the insertion position. |
|
263 If no parameter is explicitly passed, ECmpFolded is used by default. |
|
264 @leave KErrNoMemory There is insufficient memory available. If the function |
|
265 leaves, the array is left in the state it was in before the call. |
|
266 @return The position within the array of the inserted descriptor. */ |
|
267 { |
|
268 HBufC8* bufPtr=aPtr.AllocLC(); |
|
269 TKeyDesC8Array key(aTextComparisonType); |
|
270 TInt found=CArrayFixBase::InsertIsqAllowDuplicatesL(&bufPtr,key); |
|
271 CleanupStack::Pop(); |
|
272 return(found); |
|
273 } |
|
274 |
|
275 EXPORT_C void CDesC8Array::Sort(TKeyCmpText aTextComparisonType) |
|
276 /** Sorts the descriptor elements into sequence. |
|
277 |
|
278 The sequence is determined by comparing descriptors using one of the member |
|
279 functions of the descriptor base class TDesC. |
|
280 |
|
281 @param aTextComparisonType An enumeration which defines the type of comparison |
|
282 to be made between descriptors. By default the comparison type is ECmpFolded. */ |
|
283 { |
|
284 TKeyDesC8Array key(aTextComparisonType); |
|
285 CArrayFixBase::Sort(key); |
|
286 } |
|
287 |
|
288 EXPORT_C TInt CDesC8Array::Find(const TDesC8& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const |
|
289 /** Finds the position of a descriptor element within the array which matches the |
|
290 specified descriptor using a sequential search. |
|
291 |
|
292 The array is searched sequentially for a matching descriptor element, starting |
|
293 with the first descriptor element in the array. Descriptors are compared using |
|
294 one of the TDesC comparison functions. The enumeration aTextComparisonType |
|
295 governs how the descriptors are to be compared. |
|
296 |
|
297 Where an array has duplicate descriptor elements, the function only supplies |
|
298 the position of the first descriptor element. |
|
299 |
|
300 @param aPtr A reference to a descriptor to be used for comparison. |
|
301 @param aPos If the descriptor element is found, this reference is set to the |
|
302 position of that descriptor element within the array. The position is relative |
|
303 to zero, (i.e. the first descriptor element in the array is at position 0). |
|
304 If the descriptor element is not found and the array is not empty, then the |
|
305 value of the reference is set to the number of descriptor elements in the |
|
306 array. If the descriptor element is not found and the array is empty, then |
|
307 the reference is set to zero. |
|
308 @param aTextComparisonType An enumeration which determines the type of comparison |
|
309 to be made between descriptors. If no parameter is explicitly passed, ECmpFolded |
|
310 is used by default. |
|
311 @return Zero, if a matching descriptor element is found. Non-zero, if no matching |
|
312 descriptor element can be found. */ |
|
313 { |
|
314 TKeyDesC8Array key(aTextComparisonType); |
|
315 const TDesC8* tmp=(&aPtr); |
|
316 return(CArrayFixBase::Find(&tmp,key,aPos)); |
|
317 } |
|
318 |
|
319 EXPORT_C TInt CDesC8Array::FindIsq(const TDesC8& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const |
|
320 /** Finds the position of a descriptor element within the array which matches |
|
321 the specified descriptor using a binary search technique. The array must |
|
322 be in sequence, otherwise the outcome is unpredictable. |
|
323 |
|
324 Descriptors are compared using one of the TDesC comparison functions. The |
|
325 enumeration aTextComparisonType governs how the descriptors are to be compared. |
|
326 |
|
327 Where an array has duplicate descriptor elements, the function cannot guarantee |
|
328 which matching descriptor element it will return; except that it will find |
|
329 one of them. |
|
330 |
|
331 @param aPtr A reference to a descriptor to be used for comparison. |
|
332 @param aPos If the descriptor element is found, the reference is set to the |
|
333 position of that descriptor element within the array. The position is relative |
|
334 to zero, (i.e. the first descriptor element in the array is at position 0). |
|
335 If the descriptor element is not found and the array is not empty, then the |
|
336 reference is set to the position of the first descriptor element in the array |
|
337 whose content is greater than the content of aPtr. If the descriptor element |
|
338 is not found and the array is empty, then the reference is set to zero. |
|
339 @param aTextComparisonType An enumeration which determines the type of comparison |
|
340 to be made between descriptors. If no parameter is explicitly passed, ECmpFolded |
|
341 is used by default. |
|
342 @return Zero, if a matching descriptor element is found. Non-zero, if no matching |
|
343 descriptor element can be found. */ |
|
344 { |
|
345 TKeyDesC8Array key(aTextComparisonType); |
|
346 const TDesC8* tmp=(&aPtr); |
|
347 return(CArrayFixBase::FindIsq(&tmp,key,aPos)); |
|
348 } |
|
349 |
|
350 |
|
351 /** |
|
352 * |
|
353 * Constructs a flat descriptor array with the specified granularity. |
|
354 * |
|
355 * No memory is allocated to the array buffer by this constructor. |
|
356 * |
|
357 * @param "TInt aGranularity" |
|
358 * The granularity of the array. This value must be |
|
359 * positive otherwise the constructor raises an |
|
360 * E32USER-CBase 18 panic. |
|
361 */ |
|
362 EXPORT_C CDesC8ArrayFlat::CDesC8ArrayFlat(TInt aGranularity) |
|
363 : CDesC8Array((TBufRep)CBufFlat::NewL,aGranularity) |
|
364 { |
|
365 __DECLARE_NAME(_S("CDesC8ArrayFlat")); |
|
366 } |
|
367 |
|
368 EXPORT_C CDesC8ArrayFlat::~CDesC8ArrayFlat() |
|
369 /** Frees all resources owned by the object, prior to its destruction. */ |
|
370 {} |
|
371 |
|
372 EXPORT_C CDesC8ArraySeg::CDesC8ArraySeg(TInt aGranularity) |
|
373 : CDesC8Array((TBufRep)CBufSeg::NewL,aGranularity) |
|
374 /** Constructs a segmented descriptor array with the specified granularity. |
|
375 |
|
376 No memory is allocated to the array buffer by this constructor. |
|
377 |
|
378 @param aGranularity The granularity of the array. This value must be positive |
|
379 otherwise the constructor raises an E32USER-CBase 18 panic. */ |
|
380 { |
|
381 __DECLARE_NAME(_S("CDesC8ArraySeg")); |
|
382 } |
|
383 |
|
384 EXPORT_C CDesC8ArraySeg::~CDesC8ArraySeg() |
|
385 /** Frees all resources owned by the object, prior to its destruction. */ |
|
386 {} |
|
387 |
|
388 |
|
389 // 16-bit equivalents to the above. |
|
390 |
|
391 |
|
392 EXPORT_C CDesC16Array::CDesC16Array(TBufRep aRep,TInt aGranularity) |
|
393 : CArrayFixBase(aRep,sizeof(HBufC16*),aGranularity) |
|
394 { |
|
395 } |
|
396 |
|
397 EXPORT_C CDesC16Array::~CDesC16Array() |
|
398 /** Frees all resources owned by the object, prior to its destruction. In particular, |
|
399 it deletes all descriptors from the array and frees the memory allocated to |
|
400 the array buffer. */ |
|
401 { |
|
402 Reset(); |
|
403 } |
|
404 |
|
405 EXPORT_C void CDesC16Array::Reset() |
|
406 /** Deletes all descriptors from the array and frees the memory allocated to the |
|
407 array buffer. |
|
408 |
|
409 @see CDesC16Array::Delete() */ |
|
410 { |
|
411 Delete(0,Count()); |
|
412 } |
|
413 |
|
414 EXPORT_C void CDesC16Array::Delete(TInt aIndex) |
|
415 { |
|
416 Delete(aIndex,1); |
|
417 } |
|
418 |
|
419 /** |
|
420 * |
|
421 * Deletes one or more logically contiguous descriptor elements from the |
|
422 * array. |
|
423 * |
|
424 * The deletion starts at the specified position.Deleting descriptor |
|
425 * elements from the array frees the memory occupied by the associated |
|
426 * heap descriptors and removes their pointers from the array buffer but |
|
427 * does not cause the array buffer to be automatically compressed. Call |
|
428 * the Compress() function to return excess space in the array buffer to |
|
429 * the heap. |
|
430 * |
|
431 * @param " TInt aPos " |
|
432 * The starting position in the array from which |
|
433 * descriptor elements are to be deleted. The position is |
|
434 * relative to zero, i.e. zero implies the first |
|
435 * descriptor element. This value must not be negative |
|
436 * and must not be greater than the number of descriptor |
|
437 * elements currently in the array, otherwise the |
|
438 * functions raise an E32USER-CBase 21 panic. |
|
439 * @param " TInt aCount " |
|
440 * If specified, the number of contiguous descriptor |
|
441 * elements to be deleted from the array. This value must |
|
442 * not be negative otherwise the function raises an |
|
443 * E32USER-CBase 22 panic. This value must not be |
|
444 * negative otherwise the function raises an |
|
445 * E32USER-CBase 22 panic. This value must not be |
|
446 * negative otherwise the function raises an |
|
447 * E32USER-CBase 22 panic. This value plus the value of |
|
448 * the starting position must not be greater than the |
|
449 * number of descriptor elements in the array, otherwise |
|
450 * the function raises an E32USER-CBase 29 panic. If not |
|
451 * specified, one element is assumed. |
|
452 */ |
|
453 EXPORT_C void CDesC16Array::Delete(TInt aIndex,TInt aCount) |
|
454 { |
|
455 TInt count=aCount; |
|
456 for (TInt ii=aIndex; count--; ii++) |
|
457 User::Free(*(HBufC16**)At(ii)); |
|
458 CArrayFixBase::Delete(aIndex,aCount); |
|
459 } |
|
460 |
|
461 EXPORT_C TInt CDesC16Array::MdcaCount() const |
|
462 /** Returns the number of descriptor elements in the array. The function implements |
|
463 the function interface MDesC16Array::MdcaCount(). |
|
464 |
|
465 @return The number of descriptor elements. */ |
|
466 { |
|
467 return Count(); |
|
468 } |
|
469 |
|
470 EXPORT_C TPtrC16 CDesC16Array::MdcaPoint(TInt anIndex) const |
|
471 /** Indexes into a descriptor array. The function implements the interface MDesC16Array::MdcaPoint(). |
|
472 |
|
473 @param aIndex The position of the descriptor element within the array. The |
|
474 position is relative to zero; i.e. zero implies the first descriptor element |
|
475 in the array. This value must be non-negative and less than the number of |
|
476 descriptors currently within the array otherwise the operator panics with |
|
477 EArrayIndexOutOfRange. |
|
478 @return A non-modifiable pointer descriptor representing the descriptor element |
|
479 located at position aIndex within the array. */ |
|
480 { |
|
481 HBufC16* temp=(*(HBufC16**)At(anIndex)); |
|
482 return (TPtrC16)(*temp); |
|
483 } |
|
484 |
|
485 EXPORT_C void CDesC16Array::AppendL(const TDesC16& aPtr) |
|
486 /** Appends a descriptor onto the end of any existing descriptor elements in the |
|
487 array. |
|
488 |
|
489 @param aPtr A reference to the descriptor to be appended to the array. */ |
|
490 { |
|
491 InsertL(Count(),aPtr); |
|
492 } |
|
493 |
|
494 EXPORT_C void CDesC16Array::InsertL(TInt aPos,const TDesC16& aPtr) |
|
495 /** Inserts a descriptor into the array at the specified position. |
|
496 |
|
497 If the specified position is the same as the current number of descriptor |
|
498 elements in the array, this has the effect of appending the element. |
|
499 |
|
500 @param aPos The position within the array where the descriptor element is |
|
501 to be inserted. The position is relative to zero, i.e. zero implies the first |
|
502 descriptor element. This value must not be negative and must not be greater |
|
503 than the number of descriptor elements currently in the array, otherwise the |
|
504 function raises an E32USER-CBase 21 panic. |
|
505 @param aPtr The descriptor to be inserted into the array. */ |
|
506 { |
|
507 HBufC16* bufPtr=aPtr.AllocLC(); |
|
508 CArrayFixBase::InsertL(aPos,&bufPtr); |
|
509 CleanupStack::Pop(); |
|
510 } |
|
511 |
|
512 EXPORT_C TInt CDesC16Array::InsertIsqL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType) |
|
513 /** Inserts a descriptor into the array at a position which maintains the sequence |
|
514 of the descriptors. |
|
515 |
|
516 The sequence is determined by comparing descriptors using one of the TDesC |
|
517 comparison functions. The enumeration aTextComparisonType governs how the |
|
518 descriptors are to be compared. |
|
519 |
|
520 The array should already be in sequence, otherwise the position of the new |
|
521 descriptor element is unpredictable. Descriptor elements which are the same |
|
522 are not permitted. |
|
523 |
|
524 @param aPtr A reference to the descriptor to be inserted into the array. |
|
525 @param aTextComparisonType An enumeration which determines the type of comparison |
|
526 to be made between descriptors for the purpose of choosing the insertion position. |
|
527 If no parameter is explicitly passed, ECmpFolded is used by default. |
|
528 @return The position within the array of the inserted descriptor. */ |
|
529 { |
|
530 HBufC16* bufPtr=aPtr.AllocLC(); |
|
531 TKeyDesC16Array key(aTextComparisonType); |
|
532 TInt found=CArrayFixBase::InsertIsqL(&bufPtr,key); |
|
533 CleanupStack::Pop(); |
|
534 return(found); |
|
535 } |
|
536 |
|
537 EXPORT_C TInt CDesC16Array::InsertIsqAllowDuplicatesL(const TDesC16& aPtr,TKeyCmpText aTextComparisonType) |
|
538 /** Inserts a descriptor into the array at a position which maintains the sequence |
|
539 of the descriptors; allows duplicates. |
|
540 |
|
541 The sequence is determined by comparing descriptors using one of the TDesC |
|
542 comparison functions. The enumeration aTextComparisonType governs how the |
|
543 descriptors are to be compared. |
|
544 |
|
545 The array should already be in sequence, otherwise the position of the new |
|
546 descriptor element is unpredictable. Descriptor elements which are the same |
|
547 are permitted; if the descriptor aPtr is a duplicate of an existing descriptor |
|
548 within the array, then the new descriptor element is positioned after the |
|
549 existing descriptor element. |
|
550 |
|
551 @param aPtr A reference to the descriptor to be inserted into the array. |
|
552 @param aTextComparisonType An enumeration which determines the type of comparison |
|
553 to be made between descriptors for the purpose of choosing the insertion position. |
|
554 If no parameter is explicitly passed, ECmpFolded is used by default. |
|
555 @return The position within the array of the inserted descriptor. */ |
|
556 { |
|
557 HBufC16* bufPtr=aPtr.AllocLC(); |
|
558 TKeyDesC16Array key(aTextComparisonType); |
|
559 TInt found=CArrayFixBase::InsertIsqAllowDuplicatesL(&bufPtr,key); |
|
560 CleanupStack::Pop(); |
|
561 return(found); |
|
562 } |
|
563 |
|
564 EXPORT_C void CDesC16Array::Sort(TKeyCmpText aTextComparisonType) |
|
565 /** Sorts the descriptor elements into sequence. |
|
566 |
|
567 The sequence is determined by comparing descriptors using one of the member |
|
568 functions of the descriptor base class TDesC. |
|
569 |
|
570 @param aTextComparisonType An enumeration which defines the type of comparison |
|
571 to be made between descriptors. By default the comparison type is ECmpFolded. */ |
|
572 { |
|
573 TKeyDesC16Array key(aTextComparisonType); |
|
574 CArrayFixBase::Sort(key); |
|
575 } |
|
576 |
|
577 EXPORT_C TInt CDesC16Array::Find(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const |
|
578 /** Finds the position of a descriptor element within the array which matches the |
|
579 specified descriptor, using a sequential search. |
|
580 |
|
581 The array is searched sequentially for a matching descriptor element, starting |
|
582 with the first descriptor element in the array. Descriptors are compared using |
|
583 one of the TDesC comparison functions. The enumeration aTextComparisonType |
|
584 governs how the descriptors are to be compared. |
|
585 |
|
586 Where an array has duplicate descriptor elements, the function only supplies |
|
587 the position of the first descriptor element. |
|
588 |
|
589 @param aPtr A reference to a descriptor to be used for comparison. |
|
590 @param aPos If the descriptor element is found, this reference is set to the |
|
591 position of that descriptor element within the array. The position is relative |
|
592 to zero, (i.e. the first descriptor element in the array is at position 0). |
|
593 If the descriptor element is not found and the array is not empty, then the |
|
594 value of the reference is set to the number of descriptor elements in the |
|
595 array. If the descriptor element is not found and the array is empty, then |
|
596 the reference is set to zero. |
|
597 @param aTextComparisonType An enumeration which determines the type of comparison |
|
598 to be made between descriptors. If no parameter is explicitly passed,ECmpFolded |
|
599 is used by default. |
|
600 @return Zero, if a matching descriptor element is found. Non-zero, if no matching |
|
601 descriptor element can be found. */ |
|
602 { |
|
603 TKeyDesC16Array key(aTextComparisonType); |
|
604 const TDesC16* tmp=(&aPtr); |
|
605 return(CArrayFixBase::Find(&tmp,key,aPos)); |
|
606 } |
|
607 |
|
608 EXPORT_C TInt CDesC16Array::FindIsq(const TDesC16& aPtr,TInt& aPos,TKeyCmpText aTextComparisonType) const |
|
609 /** Finds the position of a descriptor element within the array which matches the |
|
610 specified descriptor, using a binary search technique. The array must |
|
611 be in sequence, otherwise the outcome is unpredictable. |
|
612 |
|
613 Descriptors are compared using one of the TDesC comparison functions. The |
|
614 enumeration aTextComparisonType governs how the descriptors are to be compared. |
|
615 |
|
616 Where an array has duplicate descriptor elements, the function cannot guarantee |
|
617 which matching descriptor element it will return; except that it will find |
|
618 one of them. |
|
619 |
|
620 @param aPtr A reference to a descriptor to be used for comparison. |
|
621 @param aPos If the descriptor element is found, the reference is set to the |
|
622 position of that descriptor element within the array. The position is relative |
|
623 to zero, (i.e. the first descriptor element in the array is at position 0). |
|
624 If the descriptor element is not found and the array is not empty, then the |
|
625 reference is set to the position of the first descriptor element in the array |
|
626 whose content is greater than the content of aPtr. If the descriptor element |
|
627 is not found and the array is empty, then the reference is set to zero. |
|
628 @param aTextComparisonType An enumeration which determines the type of comparison |
|
629 to be made between descriptors. If no parameter is explicitly passed, ECmpFolded |
|
630 is used by default. |
|
631 @return Zero, if a matching descriptor element is found. Non-zero, if no matching |
|
632 descriptor element can be found. */ |
|
633 { |
|
634 TKeyDesC16Array key(aTextComparisonType); |
|
635 const TDesC16* tmp=(&aPtr); |
|
636 return(CArrayFixBase::FindIsq(&tmp,key,aPos)); |
|
637 } |
|
638 |
|
639 /** |
|
640 * |
|
641 * Constructs a flat descriptor array with the specified granularity. |
|
642 * |
|
643 * No memory is allocated to the array buffer by this constructor. |
|
644 * |
|
645 * @param "TInt aGranularity" |
|
646 * The granularity of the array. This value must be |
|
647 * positive otherwise the constructor raises an |
|
648 * E32USER-CBase 18 panic. |
|
649 */ |
|
650 EXPORT_C CDesC16ArrayFlat::CDesC16ArrayFlat(TInt aGranularity) |
|
651 : CDesC16Array((TBufRep)CBufFlat::NewL,aGranularity) |
|
652 { |
|
653 __DECLARE_NAME(_S("CDesC16ArrayFlat")); |
|
654 } |
|
655 |
|
656 EXPORT_C CDesC16ArrayFlat::~CDesC16ArrayFlat() |
|
657 /** Frees all resources owned by the object, prior to its destruction. */ |
|
658 {} |
|
659 |
|
660 EXPORT_C CDesC16ArraySeg::CDesC16ArraySeg(TInt aGranularity) |
|
661 : CDesC16Array((TBufRep)CBufSeg::NewL,aGranularity) |
|
662 /** Construct a segmented descriptor array with the specified granularity. |
|
663 |
|
664 No memory is allocated to the array buffer by this C++ constructor. |
|
665 |
|
666 @param aGranularity The granularity of the array. This value must be positive |
|
667 otherwise the constructor raises an E32USER-CBase 18 panic. */ |
|
668 { |
|
669 __DECLARE_NAME(_S("CDesC16ArraySeg")); |
|
670 } |
|
671 |
|
672 EXPORT_C CDesC16ArraySeg::~CDesC16ArraySeg() |
|
673 /** Frees all resources owned by the object, prior to its destruction. */ |
|
674 {} |
|
675 |
|
676 // |
|
677 // class CPtrC8Array |
|
678 // |
|
679 |
|
680 EXPORT_C CPtrC8Array::CPtrC8Array(TInt aGranularity) |
|
681 : CArrayFixFlat<TPtrC8>(aGranularity) |
|
682 /** Constructs an array of 8 bit non-modifiable descriptors with the specified |
|
683 granularity. The length of all elements in the array buffer is the length |
|
684 of a TPtrC8 object. |
|
685 |
|
686 No memory is allocated to the array buffer by this constructor. |
|
687 |
|
688 @param aGranularity The granularity of the array. This value must be positive |
|
689 otherwise the constructor raises an E32USER-CBase 18 panic. */ |
|
690 { |
|
691 __DECLARE_NAME(_S("CPtrC8Array")); |
|
692 } |
|
693 |
|
694 EXPORT_C CPtrC8Array::~CPtrC8Array() |
|
695 /** Frees all resources owned by the object, prior to its destruction. */ |
|
696 {} |
|
697 |
|
698 EXPORT_C TInt CPtrC8Array::MdcaCount() const |
|
699 /** Returns the number of elements in the array. The function implements the pure |
|
700 virtual function MDesC8Array::MdcaCount(). |
|
701 |
|
702 @return The number of elements. */ |
|
703 { |
|
704 return(Count()); |
|
705 } |
|
706 |
|
707 EXPORT_C TPtrC8 CPtrC8Array::MdcaPoint(TInt aIndex) const |
|
708 /** Indexes into the descriptor array. The function implements the pure virtual |
|
709 function MDesC8Array::MdcaPoint(). |
|
710 |
|
711 @param aIndex The position of the descriptor element within the array. The |
|
712 position is relative to zero; i.e. zero implies the first descriptor element |
|
713 in the array. This value must be non-negative and must be less than the number |
|
714 of elements currently in the array otherwise the operator raises a E32USER-CBase |
|
715 21 panic. |
|
716 @return A non-modifiable pointer descriptor for the data represented by the |
|
717 element at position aIndex within the array. */ |
|
718 { |
|
719 return(At(aIndex)); |
|
720 } |
|
721 |
|
722 EXPORT_C void CPtrC8Array::CopyL(const MDesC8Array& aArray) |
|
723 /** Copies a descriptor array into this array, deleting any pre-existing elements. |
|
724 |
|
725 The function constructs TPtrC8 elements for each descriptor element in the |
|
726 specified descriptor array. |
|
727 |
|
728 @param aArray A reference to any descriptor array which satisfies the protocol |
|
729 defined by this mixin class. */ |
|
730 { |
|
731 Reset(); |
|
732 TInt count=aArray.MdcaCount(); |
|
733 for (TInt i=0;i<count;++i) |
|
734 AppendL(aArray.MdcaPoint(i)); |
|
735 } |
|
736 |
|
737 // |
|
738 // class CPtrC16Array |
|
739 // |
|
740 |
|
741 EXPORT_C CPtrC16Array::CPtrC16Array(TInt aGranularity) |
|
742 : CArrayFixFlat<TPtrC16>(aGranularity) |
|
743 /** Constructs an array of 16 bit non-modifiable descriptors with the specified |
|
744 granularity. The length of all elements in the array buffer is the length |
|
745 of a TPtrC16 object. |
|
746 |
|
747 No memory is allocated to the array buffer by constructor. |
|
748 |
|
749 @param aGranularity The granularity of the array. This value must be positive |
|
750 otherwise the constructor raises an E32USER-CBase 18 panic. */ |
|
751 { |
|
752 __DECLARE_NAME(_S("CPtrC16Array")); |
|
753 } |
|
754 |
|
755 EXPORT_C CPtrC16Array::~CPtrC16Array() |
|
756 /** Frees all resources owned by the object, prior to its destruction. */ |
|
757 {} |
|
758 |
|
759 EXPORT_C TInt CPtrC16Array::MdcaCount() const |
|
760 /** Returns the number of elements in the array. The function implements the pure |
|
761 virtual function MDesC16Array::MdcaCount(). |
|
762 |
|
763 @return The number of elements. */ |
|
764 { |
|
765 return(Count()); |
|
766 } |
|
767 |
|
768 EXPORT_C TPtrC16 CPtrC16Array::MdcaPoint(TInt aIndex) const |
|
769 /** Indexes into the descriptor array. The function implements the pure virtual |
|
770 function MDesC16Array::MdcaPoint(). |
|
771 |
|
772 @param aIndex The position of the descriptor element within the array. The |
|
773 position is relative to zero; i.e. zero implies the first descriptor element |
|
774 in the array. This value must be non-negative and must be less than the number |
|
775 of elements currently in the array otherwise the operator raises a E32USER-CBase |
|
776 21 panic. |
|
777 @return A non-modifiable pointer descriptor for the data represented by the |
|
778 element at position aIndex within the array. */ |
|
779 { |
|
780 return(At(aIndex)); |
|
781 } |
|
782 |
|
783 EXPORT_C void CPtrC16Array::CopyL(const MDesC16Array& aArray) |
|
784 /** Copies a descriptor array into this array, deleting any pre-existing elements. |
|
785 |
|
786 The function constructs TPtrC16 elements for each descriptor element in the |
|
787 specified descriptor array. |
|
788 |
|
789 @param aArray A reference to any descriptor array which satisfies the protocol |
|
790 defined by this mixin class. */ |
|
791 { |
|
792 Reset(); |
|
793 TInt count=aArray.MdcaCount(); |
|
794 for (TInt i=0;i<count;++i) |
|
795 AppendL(aArray.MdcaPoint(i)); |
|
796 } |