epoc32/include/caf/streamableptrarray.inl
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
     1.1 --- a/epoc32/include/caf/streamableptrarray.inl	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/caf/streamableptrarray.inl	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,102 @@
     1.4 -streamableptrarray.inl
     1.5 +/*
     1.6 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.7 +* All rights reserved.
     1.8 +* This component and the accompanying materials are made available
     1.9 +* under the terms of the License "Eclipse Public License v1.0"
    1.10 +* which accompanies this distribution, and is available
    1.11 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.12 +*
    1.13 +* Initial Contributors:
    1.14 +* Nokia Corporation - initial contribution.
    1.15 +*
    1.16 +* Contributors:
    1.17 +*
    1.18 +* Description: 
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +namespace ContentAccess
    1.24 +{
    1.25 +template <class T>
    1.26 +inline RStreamablePtrArray<T>::RStreamablePtrArray()
    1.27 +	{
    1.28 +	}
    1.29 +
    1.30 +template <class T>
    1.31 +inline void RStreamablePtrArray<T>::Close()
    1.32 +	{
    1.33 +	iArray.ResetAndDestroy();
    1.34 +	}
    1.35 +
    1.36 +template <class T>
    1.37 +inline void RStreamablePtrArray<T>::AppendL(T* aElement)
    1.38 +	{
    1.39 +	User::LeaveIfError(iArray.Append(aElement));
    1.40 +	}
    1.41 +
    1.42 +template <class T>
    1.43 +inline TInt RStreamablePtrArray<T>::Count() const
    1.44 +	{
    1.45 +	return iArray.Count();
    1.46 +	}
    1.47 +
    1.48 +template <class T>
    1.49 +inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const
    1.50 +	{
    1.51 +	// case the value from the array back to its original type
    1.52 +	return iArray[aIndex];
    1.53 +	}
    1.54 +
    1.55 +template <class T>
    1.56 +inline void RStreamablePtrArray<T>::ResetAndDestroy()
    1.57 +	{
    1.58 +	iArray.ResetAndDestroy();
    1.59 +	}
    1.60 +
    1.61 +template <class T>		
    1.62 +inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream)
    1.63 +	{
    1.64 +	TInt i;
    1.65 +
    1.66 +	// Read the number of CMetaData objects from the stream
    1.67 +	TInt count = aStream.ReadInt32L();
    1.68 +
    1.69 +	// Read the objects from the stream and add them to the array
    1.70 +	for(i = 0; i < count; i++)
    1.71 +		{
    1.72 +		// create a new T object from the stream using the supplied factory function
    1.73 +		T* element = T::NewL(aStream);
    1.74 +		CleanupStack::PushL(element);
    1.75 +
    1.76 +		AppendL(element);
    1.77 +
    1.78 +		// Finished with cleanup stack, element now owned by the array so don't delete
    1.79 +		CleanupStack::Pop(element);
    1.80 +		}
    1.81 +	}
    1.82 +
    1.83 +template <class T>
    1.84 +inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const
    1.85 +	{	
    1.86 +	TInt i;
    1.87 +	// Write the total number of elements to the stream
    1.88 +	aStream.WriteInt32L(iArray.Count());
    1.89 +	
    1.90 +	// Ask the array elements to write themselves to the stream one by one 
    1.91 +	for(i = 0; i < iArray.Count();i++)
    1.92 +		{
    1.93 +		iArray[i]->ExternalizeL(aStream);
    1.94 +		}
    1.95 +	}
    1.96 +
    1.97 +template <class T>
    1.98 +inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex)
    1.99 +	{
   1.100 +	if ( (aIndex >= iArray.Count()) || (aIndex < 0) )
   1.101 +		{
   1.102 +		User::Leave(KErrArgument);
   1.103 +		}
   1.104 +	iArray.Remove(aIndex);
   1.105 +	}
   1.106 +}