williamr@2: /* williamr@2: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@4: @publishedAll williamr@2: @released williamr@2: */ williamr@2: williamr@2: williamr@2: #ifndef __STREAMABLEPTRARRAY_H__ williamr@2: #define __STREAMABLEPTRARRAY_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: namespace ContentAccess williamr@2: { williamr@2: /** Template class used to store an array of pointers that can also write itself to a stream williamr@2: williamr@2: The RStreamablePtrArray owns all the elements contained within it. The close williamr@2: function must be called before the RStreamablePtrArray goes out of scope. williamr@2: williamr@2: The close function frees all resources and deletes all array elements williamr@2: williamr@2: The array can be streamed using the InternalizeL() and ExternalizeL() functions williamr@2: williamr@4: */ williamr@2: template williamr@2: class RStreamablePtrArray williamr@2: { williamr@2: public: williamr@2: /** Constructor */ williamr@2: inline RStreamablePtrArray(); williamr@2: williamr@2: /** Free all resources held by the array williamr@2: williamr@2: Calls ResetAndDestroy(); williamr@2: */ williamr@2: inline void Close(); williamr@2: williamr@2: /** Append an element to the array williamr@2: williamr@2: Ownership of the pointer is transferred to the array williamr@2: @param aElement The item to add to the array williamr@2: */ williamr@2: inline void AppendL(T* aElement); williamr@2: williamr@2: /** Count the number of objects in the array */ williamr@2: inline TInt Count() const; williamr@2: williamr@2: /** Return a pointer to an element at a given index in the array williamr@2: williamr@2: @param aIndex The zero based index in the array, must be less than Count() williamr@2: @return A pointer to the object stored in the array williamr@2: */ williamr@2: inline T* operator [] (TInt aIndex) const; williamr@2: williamr@2: /** Delete all elements in the array*/ williamr@2: inline void ResetAndDestroy(); williamr@2: williamr@2: /** Add array elements from a stream */ williamr@2: inline void InternalizeL(RReadStream& aStream); williamr@2: williamr@2: /** Write the entire array to a stream */ williamr@2: inline void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: /** Remove an element from the array. williamr@2: Note that the function does not delete the pointer. williamr@2: */ williamr@2: inline void RemoveL(TInt aIndex); williamr@2: williamr@2: private: williamr@2: RPointerArray iArray; williamr@2: }; williamr@2: } williamr@2: williamr@2: // include inline function definitions williamr@2: #include williamr@2: williamr@2: #endif