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