authenticationservices/authenticationserver/source/common/arrayutils.inl
changeset 29 ece3df019add
equal deleted inserted replaced
19:cd501b96611d 29:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2003-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 * Utility functions for copying and streaming RArrays. 
       
    16 * RPointerArray utilities
       
    17 *
       
    18 */
       
    19 
       
    20 template <class T>
       
    21 void ExternalizePointerArrayL(const RPointerArray<T>& aArray, RWriteStream& aStream)
       
    22 	{
       
    23 	aStream.WriteInt32L(aArray.Count());
       
    24 	for (TInt i = 0; i < aArray.Count(); ++i)
       
    25 		{
       
    26 		TTraits<T>::WriteToStreamL(*aArray[i], aStream);
       
    27 		}
       
    28 	}
       
    29 
       
    30 template <class T>
       
    31 void InternalizePointerArrayL(RPointerArray<T>& aArray, RReadStream& aStream)
       
    32 	{
       
    33 	TInt count = aStream.ReadInt32L();
       
    34 	for (TInt i = 0; i < count; ++i)
       
    35 		{
       
    36 		T* item = TTraits<T>::ReadFromStreamLC(aStream);
       
    37 		User::LeaveIfError(aArray.Append(item));
       
    38 		CleanupStack::Pop();
       
    39 		}
       
    40 	}
       
    41 
       
    42 /////////////////////////////////////////////////////////////////////
       
    43 // RArray utilities
       
    44 /////////////////////////////////////////////////////////////////////
       
    45 template <class T>
       
    46 void ExternalizeArrayL(const RArray<T>& aArray, RWriteStream& aStream)
       
    47 	{
       
    48 	aStream.WriteInt32L(aArray.Count());
       
    49 	for (TInt i = 0; i < aArray.Count(); ++i)
       
    50 		{
       
    51 		aStream.WriteL(TPckgC<T>(aArray[i]));
       
    52 		}
       
    53 	}
       
    54 
       
    55 template <class T>
       
    56 void InternalizeArrayL(RArray<T>& aArray, RReadStream& aStream)
       
    57 	{
       
    58 	TInt count = aStream.ReadInt32L();
       
    59 	for (TInt i = 0; i < count; ++i)
       
    60 		{
       
    61 		T item;
       
    62 		TPckg<T> itemPckg(item);
       
    63 		aStream.ReadL(itemPckg);
       
    64 		User::LeaveIfError(aArray.Append(item));
       
    65 		}
       
    66 	}