williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
3 |
* All rights reserved.
|
williamr@2
|
4 |
* This component and the accompanying materials are made available
|
williamr@2
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
williamr@2
|
6 |
* which accompanies this distribution, and is available
|
williamr@2
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Initial Contributors:
|
williamr@2
|
10 |
* Nokia Corporation - initial contribution.
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Contributors:
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
* Description:
|
williamr@2
|
15 |
*
|
williamr@2
|
16 |
*/
|
williamr@2
|
17 |
|
williamr@4
|
18 |
/**
|
williamr@4
|
19 |
@file
|
williamr@4
|
20 |
@publishedAll
|
williamr@4
|
21 |
@released
|
williamr@4
|
22 |
*/
|
williamr@4
|
23 |
|
williamr@4
|
24 |
#ifndef STREAMABLEPTRARRAY_INL
|
williamr@4
|
25 |
#define STREAMABLEPTRARRAY_INL
|
williamr@2
|
26 |
|
williamr@2
|
27 |
namespace ContentAccess
|
williamr@2
|
28 |
{
|
williamr@2
|
29 |
template <class T>
|
williamr@2
|
30 |
inline RStreamablePtrArray<T>::RStreamablePtrArray()
|
williamr@2
|
31 |
{
|
williamr@2
|
32 |
}
|
williamr@2
|
33 |
|
williamr@2
|
34 |
template <class T>
|
williamr@2
|
35 |
inline void RStreamablePtrArray<T>::Close()
|
williamr@2
|
36 |
{
|
williamr@2
|
37 |
iArray.ResetAndDestroy();
|
williamr@2
|
38 |
}
|
williamr@2
|
39 |
|
williamr@2
|
40 |
template <class T>
|
williamr@2
|
41 |
inline void RStreamablePtrArray<T>::AppendL(T* aElement)
|
williamr@2
|
42 |
{
|
williamr@2
|
43 |
User::LeaveIfError(iArray.Append(aElement));
|
williamr@2
|
44 |
}
|
williamr@2
|
45 |
|
williamr@2
|
46 |
template <class T>
|
williamr@2
|
47 |
inline TInt RStreamablePtrArray<T>::Count() const
|
williamr@2
|
48 |
{
|
williamr@2
|
49 |
return iArray.Count();
|
williamr@2
|
50 |
}
|
williamr@2
|
51 |
|
williamr@2
|
52 |
template <class T>
|
williamr@2
|
53 |
inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const
|
williamr@2
|
54 |
{
|
williamr@2
|
55 |
// case the value from the array back to its original type
|
williamr@2
|
56 |
return iArray[aIndex];
|
williamr@2
|
57 |
}
|
williamr@2
|
58 |
|
williamr@2
|
59 |
template <class T>
|
williamr@2
|
60 |
inline void RStreamablePtrArray<T>::ResetAndDestroy()
|
williamr@2
|
61 |
{
|
williamr@2
|
62 |
iArray.ResetAndDestroy();
|
williamr@2
|
63 |
}
|
williamr@2
|
64 |
|
williamr@2
|
65 |
template <class T>
|
williamr@2
|
66 |
inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream)
|
williamr@2
|
67 |
{
|
williamr@2
|
68 |
TInt i;
|
williamr@2
|
69 |
|
williamr@2
|
70 |
// Read the number of CMetaData objects from the stream
|
williamr@2
|
71 |
TInt count = aStream.ReadInt32L();
|
williamr@2
|
72 |
|
williamr@2
|
73 |
// Read the objects from the stream and add them to the array
|
williamr@2
|
74 |
for(i = 0; i < count; i++)
|
williamr@2
|
75 |
{
|
williamr@2
|
76 |
// create a new T object from the stream using the supplied factory function
|
williamr@2
|
77 |
T* element = T::NewL(aStream);
|
williamr@2
|
78 |
CleanupStack::PushL(element);
|
williamr@2
|
79 |
|
williamr@2
|
80 |
AppendL(element);
|
williamr@2
|
81 |
|
williamr@2
|
82 |
// Finished with cleanup stack, element now owned by the array so don't delete
|
williamr@2
|
83 |
CleanupStack::Pop(element);
|
williamr@2
|
84 |
}
|
williamr@2
|
85 |
}
|
williamr@2
|
86 |
|
williamr@2
|
87 |
template <class T>
|
williamr@2
|
88 |
inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const
|
williamr@2
|
89 |
{
|
williamr@2
|
90 |
TInt i;
|
williamr@2
|
91 |
// Write the total number of elements to the stream
|
williamr@2
|
92 |
aStream.WriteInt32L(iArray.Count());
|
williamr@2
|
93 |
|
williamr@2
|
94 |
// Ask the array elements to write themselves to the stream one by one
|
williamr@2
|
95 |
for(i = 0; i < iArray.Count();i++)
|
williamr@2
|
96 |
{
|
williamr@2
|
97 |
iArray[i]->ExternalizeL(aStream);
|
williamr@2
|
98 |
}
|
williamr@2
|
99 |
}
|
williamr@2
|
100 |
|
williamr@2
|
101 |
template <class T>
|
williamr@2
|
102 |
inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex)
|
williamr@2
|
103 |
{
|
williamr@2
|
104 |
if ( (aIndex >= iArray.Count()) || (aIndex < 0) )
|
williamr@2
|
105 |
{
|
williamr@2
|
106 |
User::Leave(KErrArgument);
|
williamr@2
|
107 |
}
|
williamr@2
|
108 |
iArray.Remove(aIndex);
|
williamr@2
|
109 |
}
|
williamr@2
|
110 |
}
|
williamr@4
|
111 |
|
williamr@4
|
112 |
#endif // STREAMABLEPTRARRAY_INL
|
williamr@4
|
113 |
|