author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
/* |
sl@0 | 2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
sl@0 | 3 |
* All rights reserved. |
sl@0 | 4 |
* This component and the accompanying materials are made available |
sl@0 | 5 |
* under the terms of the License "Eclipse Public License v1.0" |
sl@0 | 6 |
* which accompanies this distribution, and is available |
sl@0 | 7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
sl@0 | 8 |
* |
sl@0 | 9 |
* Initial Contributors: |
sl@0 | 10 |
* Nokia Corporation - initial contribution. |
sl@0 | 11 |
* |
sl@0 | 12 |
* Contributors: |
sl@0 | 13 |
* |
sl@0 | 14 |
* Description: |
sl@0 | 15 |
* |
sl@0 | 16 |
*/ |
sl@0 | 17 |
|
sl@0 | 18 |
/** |
sl@0 | 19 |
@file |
sl@0 | 20 |
@publishedAll |
sl@0 | 21 |
@released |
sl@0 | 22 |
*/ |
sl@0 | 23 |
|
sl@0 | 24 |
#ifndef STREAMABLEPTRARRAY_INL |
sl@0 | 25 |
#define STREAMABLEPTRARRAY_INL |
sl@0 | 26 |
|
sl@0 | 27 |
namespace ContentAccess |
sl@0 | 28 |
{ |
sl@0 | 29 |
template <class T> |
sl@0 | 30 |
inline RStreamablePtrArray<T>::RStreamablePtrArray() |
sl@0 | 31 |
{ |
sl@0 | 32 |
} |
sl@0 | 33 |
|
sl@0 | 34 |
template <class T> |
sl@0 | 35 |
inline void RStreamablePtrArray<T>::Close() |
sl@0 | 36 |
{ |
sl@0 | 37 |
iArray.ResetAndDestroy(); |
sl@0 | 38 |
} |
sl@0 | 39 |
|
sl@0 | 40 |
template <class T> |
sl@0 | 41 |
inline void RStreamablePtrArray<T>::AppendL(T* aElement) |
sl@0 | 42 |
{ |
sl@0 | 43 |
User::LeaveIfError(iArray.Append(aElement)); |
sl@0 | 44 |
} |
sl@0 | 45 |
|
sl@0 | 46 |
template <class T> |
sl@0 | 47 |
inline TInt RStreamablePtrArray<T>::Count() const |
sl@0 | 48 |
{ |
sl@0 | 49 |
return iArray.Count(); |
sl@0 | 50 |
} |
sl@0 | 51 |
|
sl@0 | 52 |
template <class T> |
sl@0 | 53 |
inline T* RStreamablePtrArray<T>::operator [] (TInt aIndex) const |
sl@0 | 54 |
{ |
sl@0 | 55 |
// case the value from the array back to its original type |
sl@0 | 56 |
return iArray[aIndex]; |
sl@0 | 57 |
} |
sl@0 | 58 |
|
sl@0 | 59 |
template <class T> |
sl@0 | 60 |
inline void RStreamablePtrArray<T>::ResetAndDestroy() |
sl@0 | 61 |
{ |
sl@0 | 62 |
iArray.ResetAndDestroy(); |
sl@0 | 63 |
} |
sl@0 | 64 |
|
sl@0 | 65 |
template <class T> |
sl@0 | 66 |
inline void RStreamablePtrArray<T>::InternalizeL(RReadStream& aStream) |
sl@0 | 67 |
{ |
sl@0 | 68 |
TInt i; |
sl@0 | 69 |
|
sl@0 | 70 |
// Read the number of CMetaData objects from the stream |
sl@0 | 71 |
TInt count = aStream.ReadInt32L(); |
sl@0 | 72 |
|
sl@0 | 73 |
// Read the objects from the stream and add them to the array |
sl@0 | 74 |
for(i = 0; i < count; i++) |
sl@0 | 75 |
{ |
sl@0 | 76 |
// create a new T object from the stream using the supplied factory function |
sl@0 | 77 |
T* element = T::NewL(aStream); |
sl@0 | 78 |
CleanupStack::PushL(element); |
sl@0 | 79 |
|
sl@0 | 80 |
AppendL(element); |
sl@0 | 81 |
|
sl@0 | 82 |
// Finished with cleanup stack, element now owned by the array so don't delete |
sl@0 | 83 |
CleanupStack::Pop(element); |
sl@0 | 84 |
} |
sl@0 | 85 |
} |
sl@0 | 86 |
|
sl@0 | 87 |
template <class T> |
sl@0 | 88 |
inline void RStreamablePtrArray<T>::ExternalizeL(RWriteStream& aStream) const |
sl@0 | 89 |
{ |
sl@0 | 90 |
TInt i; |
sl@0 | 91 |
// Write the total number of elements to the stream |
sl@0 | 92 |
aStream.WriteInt32L(iArray.Count()); |
sl@0 | 93 |
|
sl@0 | 94 |
// Ask the array elements to write themselves to the stream one by one |
sl@0 | 95 |
for(i = 0; i < iArray.Count();i++) |
sl@0 | 96 |
{ |
sl@0 | 97 |
iArray[i]->ExternalizeL(aStream); |
sl@0 | 98 |
} |
sl@0 | 99 |
} |
sl@0 | 100 |
|
sl@0 | 101 |
template <class T> |
sl@0 | 102 |
inline void RStreamablePtrArray<T>::RemoveL(TInt aIndex) |
sl@0 | 103 |
{ |
sl@0 | 104 |
if ( (aIndex >= iArray.Count()) || (aIndex < 0) ) |
sl@0 | 105 |
{ |
sl@0 | 106 |
User::Leave(KErrArgument); |
sl@0 | 107 |
} |
sl@0 | 108 |
iArray.Remove(aIndex); |
sl@0 | 109 |
} |
sl@0 | 110 |
} |
sl@0 | 111 |
|
sl@0 | 112 |
#endif // STREAMABLEPTRARRAY_INL |
sl@0 | 113 |