|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-0AF14EE0-D4FD-53EA-B7E5-10724E3FA0DF" xml:lang="en"><title>How |
|
13 to resize an array</title><shortdesc>For fixed flat and fixed segmented arrays, it is possible to resize |
|
14 the array. If the array is shortened, then the trailing elements are deleted. |
|
15 If the array is extended, then new blank elements are created using the default |
|
16 constructor.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
17 <p>In a <codeph>CArrayFixFlat<class T></codeph> or a <codeph>CArrayFixSeg<class T></codeph> array, |
|
18 the number of elements in an array can be changed, either decreased or increased, |
|
19 using the <codeph>ResizeL()</codeph> function.</p> |
|
20 <p>In the following code fragment, <codeph>ResizeL()</codeph> changes the |
|
21 size of an array so that it contains only one element. If the array originally |
|
22 had more than one element, then this call to <codeph>ResizeL()</codeph> deletes |
|
23 all elements from position one onwards, leaving only the element at position |
|
24 zero.</p> |
|
25 <codeblock id="GUID-EB765A8F-D630-50A1-8CF4-707DFAAC5862" xml:space="preserve">CArrayFixFlat<TElement>* fixflat; |
|
26 fixflat = new (ELeave) CArrayFixFlat<TElement>(3); |
|
27 ... |
|
28 fixflat->ResizeL(1);</codeblock> |
|
29 <p>Call <codeph>ResizeL()</codeph> again to change the size of the array to |
|
30 contain a greater number of elements, in this case three. If the array originally |
|
31 had only one element (for example), this call to <codeph>ResizeL()</codeph> constructs |
|
32 two new elements at positions one and two. In this example, the new elements |
|
33 inserted at positions one and two are <codeph>TElement</codeph> type objects, |
|
34 constructed using the <codeph>TElement</codeph> <i>default constructor</i>. |
|
35 It is therefore essential that a default constructor exists before using this |
|
36 function.</p> |
|
37 <codeblock id="GUID-BCE6F87D-D2EB-5A38-8CAF-675DBFE9E6B6" xml:space="preserve">fixflat->ResizeL(3);</codeblock> |
|
38 <p>There is an overloaded variant of <codeph>ResizeL()</codeph> which takes |
|
39 a reference to a <codeph>TElement</codeph> object. A bit-wise copy of this |
|
40 referenced object supplies the new elements. In the following code fragment |
|
41 the two extra elements are bit-wise copies of the <codeph>theElement</codeph> object.</p> |
|
42 <codeblock id="GUID-EA125434-F6B2-598B-8143-55BE1F2D2996" xml:space="preserve">_LIT(KTextXXX,"XXX"); |
|
43 theElement.iData = KTextXXX; |
|
44 fixflat->ResizeL(5,theElement);</codeblock> |
|
45 </conbody></concept> |