2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 namespace ContentAccess
22 inline RStreamablePtrArray<T>::RStreamablePtrArray()
27 inline void RStreamablePtrArray<T>::Close()
29 iArray.ResetAndDestroy();
33 inline void RStreamablePtrArray<T>::AppendL(T* aElement)
35 User::LeaveIfError(iArray.Append(aElement));
39 inline TInt RStreamablePtrArray<T>::Count() const
41 return iArray.Count();
45 inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const
47 // case the value from the array back to its original type
48 return iArray[aIndex];
52 inline void RStreamablePtrArray<T>::ResetAndDestroy()
54 iArray.ResetAndDestroy();
58 inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream)
62 // Read the number of CMetaData objects from the stream
63 TInt count = aStream.ReadInt32L();
65 // Read the objects from the stream and add them to the array
66 for(i = 0; i < count; i++)
68 // create a new T object from the stream using the supplied factory function
69 T* element = T::NewL(aStream);
70 CleanupStack::PushL(element);
74 // Finished with cleanup stack, element now owned by the array so don't delete
75 CleanupStack::Pop(element);
80 inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const
83 // Write the total number of elements to the stream
84 aStream.WriteInt32L(iArray.Count());
86 // Ask the array elements to write themselves to the stream one by one
87 for(i = 0; i < iArray.Count();i++)
89 iArray[i]->ExternalizeL(aStream);
94 inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex)
96 if ( (aIndex >= iArray.Count()) || (aIndex < 0) )
98 User::Leave(KErrArgument);
100 iArray.Remove(aIndex);