os/security/contentmgmt/contentaccessfwfordrm/inc/StreamablePtrArray.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-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 *
    16 */
    17 
    18 /**
    19  @file
    20  @publishedAll
    21  @released
    22 */
    23 
    24 #ifndef STREAMABLEPTRARRAY_INL
    25 #define STREAMABLEPTRARRAY_INL
    26 
    27 namespace ContentAccess
    28 {
    29 template <class T>
    30 inline RStreamablePtrArray<T>::RStreamablePtrArray()
    31 	{
    32 	}
    33 
    34 template <class T>
    35 inline void RStreamablePtrArray<T>::Close()
    36 	{
    37 	iArray.ResetAndDestroy();
    38 	}
    39 
    40 template <class T>
    41 inline void RStreamablePtrArray<T>::AppendL(T* aElement)
    42 	{
    43 	User::LeaveIfError(iArray.Append(aElement));
    44 	}
    45 
    46 template <class T>
    47 inline TInt RStreamablePtrArray<T>::Count() const
    48 	{
    49 	return iArray.Count();
    50 	}
    51 
    52 template <class T>
    53 inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const
    54 	{
    55 	// case the value from the array back to its original type
    56 	return iArray[aIndex];
    57 	}
    58 
    59 template <class T>
    60 inline void RStreamablePtrArray<T>::ResetAndDestroy()
    61 	{
    62 	iArray.ResetAndDestroy();
    63 	}
    64 
    65 template <class T>		
    66 inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream)
    67 	{
    68 	TInt i;
    69 
    70 	// Read the number of CMetaData objects from the stream
    71 	TInt count = aStream.ReadInt32L();
    72 
    73 	// Read the objects from the stream and add them to the array
    74 	for(i = 0; i < count; i++)
    75 		{
    76 		// create a new T object from the stream using the supplied factory function
    77 		T* element = T::NewL(aStream);
    78 		CleanupStack::PushL(element);
    79 
    80 		AppendL(element);
    81 
    82 		// Finished with cleanup stack, element now owned by the array so don't delete
    83 		CleanupStack::Pop(element);
    84 		}
    85 	}
    86 
    87 template <class T>
    88 inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const
    89 	{	
    90 	TInt i;
    91 	// Write the total number of elements to the stream
    92 	aStream.WriteInt32L(iArray.Count());
    93 	
    94 	// Ask the array elements to write themselves to the stream one by one 
    95 	for(i = 0; i < iArray.Count();i++)
    96 		{
    97 		iArray[i]->ExternalizeL(aStream);
    98 		}
    99 	}
   100 
   101 template <class T>
   102 inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex)
   103 	{
   104 	if ( (aIndex >= iArray.Count()) || (aIndex < 0) )
   105 		{
   106 		User::Leave(KErrArgument);
   107 		}
   108 	iArray.Remove(aIndex);
   109 	}
   110 }
   111 
   112 #endif // STREAMABLEPTRARRAY_INL
   113