|
1 /* |
|
2 * Copyright (c) 2004-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 namespace ContentAccess |
|
20 { |
|
21 template <class T> |
|
22 inline RStreamablePtrArray<T>::RStreamablePtrArray() |
|
23 { |
|
24 } |
|
25 |
|
26 template <class T> |
|
27 inline void RStreamablePtrArray<T>::Close() |
|
28 { |
|
29 iArray.ResetAndDestroy(); |
|
30 } |
|
31 |
|
32 template <class T> |
|
33 inline void RStreamablePtrArray<T>::AppendL(T* aElement) |
|
34 { |
|
35 User::LeaveIfError(iArray.Append(aElement)); |
|
36 } |
|
37 |
|
38 template <class T> |
|
39 inline TInt RStreamablePtrArray<T>::Count() const |
|
40 { |
|
41 return iArray.Count(); |
|
42 } |
|
43 |
|
44 template <class T> |
|
45 inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const |
|
46 { |
|
47 // case the value from the array back to its original type |
|
48 return iArray[aIndex]; |
|
49 } |
|
50 |
|
51 template <class T> |
|
52 inline void RStreamablePtrArray<T>::ResetAndDestroy() |
|
53 { |
|
54 iArray.ResetAndDestroy(); |
|
55 } |
|
56 |
|
57 template <class T> |
|
58 inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream) |
|
59 { |
|
60 TInt i; |
|
61 |
|
62 // Read the number of CMetaData objects from the stream |
|
63 TInt count = aStream.ReadInt32L(); |
|
64 |
|
65 // Read the objects from the stream and add them to the array |
|
66 for(i = 0; i < count; i++) |
|
67 { |
|
68 // create a new T object from the stream using the supplied factory function |
|
69 T* element = T::NewL(aStream); |
|
70 CleanupStack::PushL(element); |
|
71 |
|
72 AppendL(element); |
|
73 |
|
74 // Finished with cleanup stack, element now owned by the array so don't delete |
|
75 CleanupStack::Pop(element); |
|
76 } |
|
77 } |
|
78 |
|
79 template <class T> |
|
80 inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const |
|
81 { |
|
82 TInt i; |
|
83 // Write the total number of elements to the stream |
|
84 aStream.WriteInt32L(iArray.Count()); |
|
85 |
|
86 // Ask the array elements to write themselves to the stream one by one |
|
87 for(i = 0; i < iArray.Count();i++) |
|
88 { |
|
89 iArray[i]->ExternalizeL(aStream); |
|
90 } |
|
91 } |
|
92 |
|
93 template <class T> |
|
94 inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex) |
|
95 { |
|
96 if ( (aIndex >= iArray.Count()) || (aIndex < 0) ) |
|
97 { |
|
98 User::Leave(KErrArgument); |
|
99 } |
|
100 iArray.Remove(aIndex); |
|
101 } |
|
102 } |