|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Utility functions for copying and streaming RArrays. |
|
16 * RPointerArray utilities |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 template <class T> |
|
22 void CopyPointerArrayL(RPointerArray<T>& aNew, const RPointerArray<T>& aOld) |
|
23 { |
|
24 for (TInt i = 0; i < aOld.Count(); ++i) |
|
25 { |
|
26 T* item = TTraits<T>::CopyLC(*aOld[i]); |
|
27 User::LeaveIfError(aNew.Append(item)); |
|
28 CleanupStack::Pop(item); |
|
29 } |
|
30 } |
|
31 |
|
32 template <class T> |
|
33 void ExternalizePointerArrayL(const RPointerArray<T>& aArray, RWriteStream& aStream) |
|
34 { |
|
35 aStream.WriteInt32L(aArray.Count()); |
|
36 for (TInt i = 0; i < aArray.Count(); ++i) |
|
37 { |
|
38 TTraits<T>::WriteToStreamL(*aArray[i], aStream); |
|
39 } |
|
40 } |
|
41 |
|
42 template <class T> |
|
43 void InternalizePointerArrayL(RPointerArray<T>& aArray, RReadStream& aStream) |
|
44 { |
|
45 TInt count = aStream.ReadInt32L(); |
|
46 for (TInt i = 0; i < count; ++i) |
|
47 { |
|
48 T* item = TTraits<T>::ReadFromStreamLC(aStream); |
|
49 User::LeaveIfError(aArray.Append(item)); |
|
50 CleanupStack::Pop(item); |
|
51 } |
|
52 } |
|
53 |
|
54 ///////////////////////////////////////////////////////////////////// |
|
55 // RArray utilities |
|
56 ///////////////////////////////////////////////////////////////////// |
|
57 |
|
58 template <class T> |
|
59 void CopyArrayL(RArray<T>& aNew, const RArray<T>& aOld) |
|
60 { |
|
61 for (TInt i = 0; i < aOld.Count(); ++i) |
|
62 { |
|
63 User::LeaveIfError(aNew.Append(aOld[i])); |
|
64 } |
|
65 } |
|
66 |
|
67 template <class T> |
|
68 void ExternalizeArrayL(const RArray<T>& aArray, RWriteStream& aStream) |
|
69 { |
|
70 aStream.WriteInt32L(aArray.Count()); |
|
71 for (TInt i = 0; i < aArray.Count(); ++i) |
|
72 { |
|
73 aStream.WriteL(TPckgC<T>(aArray[i])); |
|
74 } |
|
75 } |
|
76 |
|
77 template <class T> |
|
78 void InternalizeArrayL(RArray<T>& aArray, RReadStream& aStream) |
|
79 { |
|
80 TInt count = aStream.ReadInt32L(); |
|
81 for (TInt i = 0; i < count; ++i) |
|
82 { |
|
83 T item; |
|
84 TPckg<T> itemPckg(item); |
|
85 aStream.ReadL(itemPckg); |
|
86 User::LeaveIfError(aArray.Append(item)); |
|
87 } |
|
88 } |