williamr@2: // Copyright (c) 1994-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 "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.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: // e32\include\e32base.inl williamr@2: // williamr@2: // williamr@2: williamr@2: // Class CBase williamr@2: inline TAny* CBase::operator new(TUint aSize, TAny* aBase) __NO_THROW williamr@2: /** williamr@2: Initialises the object to binary zeroes. williamr@2: williamr@2: @param aSize The size of the derived class. This parameter is specified williamr@2: implicitly by C++ in all circumstances in which a derived williamr@2: class is allocated. williamr@2: @param aBase Indicates a base address which is returned as the object's williamr@2: address. williamr@2: williamr@2: @return A pointer to the base address. williamr@2: */ williamr@2: { Mem::FillZ(aBase, aSize); return aBase; } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny* CBase::operator new(TUint aSize) __NO_THROW williamr@2: /** williamr@2: Allocates the object from the heap and then initialises its contents williamr@2: to binary zeroes. williamr@2: williamr@2: @param aSize The size of the derived class. This parameter is specified williamr@2: implicitly by C++ in all circumstances in which a derived class williamr@2: is allocated. williamr@2: williamr@2: @return A pointer to the allocated object; NULL if memory could not williamr@2: be allocated. williamr@2: */ williamr@2: { return User::AllocZ(aSize); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny* CBase::operator new(TUint aSize, TLeave) williamr@2: /** williamr@2: Allocates the object from the heap and then initialises its contents williamr@2: to binary zeroes. williamr@2: williamr@2: @param aSize The size of the derived class. This parameter is specified williamr@2: implicitly by C++ in all circumstances in which a derived class williamr@2: is allocated. williamr@2: williamr@2: @return A pointer to the allocated object; the TLeave parameter indicates williamr@2: that the operation leaves if allocation fails with out-of-memory. williamr@2: */ williamr@2: { return User::AllocZL(aSize); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny* CBase::operator new(TUint aSize, TUint aExtraSize) __NO_THROW williamr@2: /** williamr@2: Allocates the object from the heap and then initialises its contents williamr@2: to binary zeroes. williamr@2: williamr@2: Use of this overload is rare. williamr@2: williamr@2: @param aSize The size of the derived class. This parameter is specified williamr@2: implicitly by C++ in all circumstances in which a derived class williamr@2: is allocated. williamr@2: williamr@2: @param aExtraSize Indicates additional size beyond the end of the base class. williamr@2: williamr@2: @return A pointer to the allocated object; NULL if memory could not williamr@2: be allocated. williamr@2: */ williamr@2: { return User::AllocZ(aSize + aExtraSize); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny* CBase::operator new(TUint aSize, TLeave, TUint aExtraSize) williamr@2: /** williamr@2: Allocates the object from the heap and then initialises its contents williamr@2: to binary zeroes. williamr@2: williamr@2: Use of this overload is rare. williamr@2: williamr@2: @param aSize The size of the derived class. This parameter is specified williamr@2: implicitly by C++ in all circumstances in which a derived class williamr@2: is allocated. williamr@2: williamr@2: @param aExtraSize Indicates additional size beyond the end of the base class. williamr@2: williamr@2: @return A pointer to the allocated object; the TLeave parameter indicates williamr@2: that the operation leaves if allocation fails with out-of-memory. williamr@2: */ williamr@2: { return User::AllocZL(aSize + aExtraSize); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CBufBase williamr@2: inline TInt CBufBase::Size() const williamr@2: /** williamr@2: Gets the number of data bytes in the buffer. williamr@2: williamr@2: Note that the number of heap bytes used by the buffer may be greater than its williamr@2: size, because there is typically extra room to allow for expansion. Use the williamr@2: Compress() function to reduce the extra allocation as much as possible. williamr@2: williamr@2: @return The number of data bytes in the buffer. williamr@2: */ williamr@2: {return(iSize);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CBufFlat williamr@2: inline TInt CBufFlat::Capacity() const williamr@2: /** williamr@2: Gets the size to which the buffer may expand without re-allocation. williamr@2: williamr@2: @return The size of the allocated cell associated with the buffer. This is williamr@2: the maximum size the buffer may be expanded to without re-allocation. williamr@2: */ williamr@2: {return(iMaxSize);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CArrayFixBase williamr@2: inline TInt CArrayFixBase::Count() const williamr@2: /** williamr@2: Gets the number of elements held in the array. williamr@2: williamr@2: @return The number of array elements williamr@2: */ williamr@2: {return(iCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CArrayFixBase::Length() const williamr@2: /** williamr@2: Gets the length of an element. williamr@2: williamr@2: @return The length of an element of type class T. williamr@2: */ williamr@2: {return(iLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayFix williamr@2: template williamr@2: inline CArrayFix::CArrayFix(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayFixBase(aRep,sizeof(T),aGranularity) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayFix::operator[](TInt anIndex) const williamr@2: /** williamr@2: Gets a const reference to the element located at the specified position williamr@2: within the array. williamr@2: williamr@2: Note that if a pointer to the returned referenced class T object is taken, williamr@2: be aware that the pointer value becomes invalid once elements have been added williamr@2: to, or removed from the array. Always refresh the pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A const reference to the required element. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayFixBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayFix::operator[](TInt anIndex) williamr@2: /** williamr@2: Gets a non-const reference to the element located at the specified position williamr@2: within the array. williamr@2: williamr@2: Note that if a pointer to the returned referenced class T object is taken, williamr@2: be aware that the pointer value becomes invalid once elements have been added williamr@2: to, or removed from the array. Always refresh the pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A non-const reference to the required element. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayFixBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayFix::At(TInt anIndex) const williamr@2: /** williamr@2: Gets a const reference to the element located at the specified position williamr@2: within the array. williamr@2: williamr@2: Note that if a pointer to the returned referenced class T object is taken, williamr@2: be aware that the pointer value becomes invalid once elements have been added williamr@2: to, or removed from the array. Always refresh the pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A const reference to the required element. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayFixBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T *CArrayFix::End(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the (const) first byte following the end of the williamr@2: contiguous region containing the element at the specified position within williamr@2: the array. williamr@2: williamr@2: For arrays implemented using flat buffers, the pointer always points to the williamr@2: first byte following the end of the buffer. williamr@2: williamr@2: For arrays implemented using segmented buffers, the pointer always points williamr@2: to the first byte following the end of the segment which contains the element. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element williamr@2: in the array. williamr@2: williamr@2: @return A pointer to the constant byte following the end of the contiguous williamr@2: region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return((const T *)CArrayFixBase::End(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T *CArrayFix::Back(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the (const) beginning of a contiguous region. williamr@2: williamr@2: For arrays implemented using flat buffers, the function always returns a williamr@2: pointer to the beginning of the buffer. williamr@2: williamr@2: For arrays implemented using segmented buffers, the function returns a pointer williamr@2: to the beginning of the segment for all elements in that segment except the williamr@2: first. If the element at position anIndex is the first in a segment, then williamr@2: the function returns a pointer the beginning of the previous segment. williamr@2: williamr@2: For the first element in the array, the function returns a NULL pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element williamr@2: in the array. williamr@2: williamr@2: @return A pointer to the (const) beginning of the contiguous region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return((const T *)CArrayFixBase::Back(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayFix::At(TInt anIndex) williamr@2: /** williamr@2: Gets a non-const reference to the element located at the specified position williamr@2: within the array. williamr@2: williamr@2: Note that if a pointer to the returned referenced class T object is taken, williamr@2: be aware that the pointer value becomes invalid once elements have been added williamr@2: to, or removed from the array. Always refresh the pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A non-const reference to the required element. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayFixBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T *CArrayFix::End(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the first byte following the end of the contiguous region williamr@2: containing the element at the specified position within the array. williamr@2: williamr@2: For arrays implemented using flat buffers, the pointer always points to the williamr@2: first byte following the end of the buffer. williamr@2: williamr@2: For arrays implemented using segmented buffers, the pointer always points williamr@2: to the first byte following the end of the segment which contains the element. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element williamr@2: in the array. williamr@2: williamr@2: @return A pointer to the byte following the end of the contiguous region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(((T *)CArrayFixBase::End(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T *CArrayFix::Back(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the beginning of a contiguous region. williamr@2: williamr@2: For arrays implemented using flat buffers, the function always returns a pointer williamr@2: to the beginning of the buffer. williamr@2: williamr@2: For arrays implemented using segmented buffers, the function returns a pointer williamr@2: to the beginning of the segment for all elements in that segment except the williamr@2: first. If the element at position anIndex is the first in a segment, then williamr@2: the function returns a pointer the beginning of the previous segment. williamr@2: williamr@2: For the first element in the array, the function returns a NULL pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element williamr@2: in the array. williamr@2: williamr@2: @return A pointer to the beginning of the contiguous region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(((T *)CArrayFixBase::Back(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::AppendL(const T &aRef) williamr@2: /** williamr@2: Appends a single element onto the end of the array. williamr@2: williamr@2: @param aRef A reference to the class T element to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(Count(),&aRef);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::AppendL(const T *aPtr,TInt aCount) williamr@2: /** williamr@2: Appends one or more elements onto the end of the array. williamr@2: williamr@2: @param aPtr A pointer to a contiguous set of type objects to be williamr@2: appended. williamr@2: @param aCount The number of contiguous objects of type located at williamr@2: aPtr to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 23, if aCount is negative. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(Count(),aPtr,aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::AppendL(const T &aRef,TInt aReplicas) williamr@2: /** williamr@2: Appends replicated copies of an element onto the end of the array. williamr@2: williamr@2: @param aRef A reference to the object to be replicated and appended. williamr@2: @param aReplicas The number of copies of the aRef element to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 28 if aReplicas is negative. williamr@2: */ williamr@2: {CArrayFixBase::InsertRepL(Count(),&aRef,aReplicas);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayFix::ExpandL(TInt anIndex) williamr@2: /** williamr@2: Expands the array by one element at the specified position. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element at the specified position williamr@2: williamr@2: 2. constructs a new element at that position williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: All existing elements from position anIndex to the end of the array are moved williamr@2: up, so that the element originally at position anIndex is now at position williamr@2: anIndex + 1 etc. williamr@2: williamr@2: The new element of type class T is constructed at position anIndex, using williamr@2: the default constructor of that class. williamr@2: williamr@2: @param anIndex The position within the array where the array is to be expanded williamr@2: and the new class T object is to be constructed. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @return A reference to the newly constructed class T object at position williamr@2: anIndex within the array. williamr@2: williamr@2: @panic E32USER-CBase 21 if anIndex is negative or greater than the number williamr@2: of elements currently in the array. williamr@2: */ williamr@2: {return(*new(CArrayFixBase::ExpandL(anIndex)) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayFix::ExtendL() williamr@2: /** williamr@2: Expands the array by one element at the end of the array. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element at the end of the array, i.e. at position williamr@2: CArrayFixBase::Count() williamr@2: williamr@2: 2. constructs a new element at that position williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: The new element of type class T is constructed at the end of the array, williamr@2: using the default constructor of that class. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @return A reference to the newly constructed class T object at the end of williamr@2: the array. williamr@2: williamr@2: @see CArrayFixBase::Count williamr@2: */ williamr@2: {return(*new(CArrayFixBase::ExpandL(Count())) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayFix::Find(const T &aRef,TKeyArrayFix &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a sequential search. williamr@2: williamr@2: The array is searched sequentially for an element whose key matches the key of the williamr@2: supplied class T object. The search starts with the first element in the array. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function only williamr@2: supplies the position of the first element in the array with that key. williamr@2: williamr@2: @param aRef A reference to an object of type class T whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A reference to a TInt supplied by the caller. On return, if the williamr@2: element is found, the reference is set to the position of that williamr@2: element within the array. The position is relative to zero, williamr@2: (i.e. the first element in the array is at position 0). williamr@2: If the element is not found and the array is not empty, then williamr@2: the value of the reference is set to the number of elements in williamr@2: the array. williamr@2: If the element is not found and the array is empty, then the williamr@2: reference is set to zero. williamr@2: williamr@2: @return Zero, if the element with the specified key is found. williamr@2: Non-zero, if the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayFixBase::Find(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayFix::FindIsq(const T &aRef,TKeyArrayFix &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a binary search technique. williamr@2: williamr@2: The array is searched, using a binary search technique, for an element whose williamr@2: key matches the key of the supplied class T object. williamr@2: williamr@2: The array must be in key order. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function cannot williamr@2: guarantee which element, with the given key value, it will return, except that williamr@2: it will find one of them. williamr@2: williamr@2: @param aRef A reference to an object of type class T whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A reference to a TInt supplied by the caller. On return, if the williamr@2: element is found, the reference is set to the position of that williamr@2: element within the array. The position is relative to zero, williamr@2: (i.e. the first element in the array is at position 0). williamr@2: If the element is not found and the array is not empty, then the williamr@2: reference is set to the position of the first element in the williamr@2: array with a key which is greater than the key of the williamr@2: object aRef. williamr@2: If the element is not found and the array is empty, then the williamr@2: reference is set to zero. williamr@2: williamr@2: @return Zero, if the element with the specified key is found. williamr@2: Non-zero, if the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayFixBase::FindIsq(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::InsertL(TInt anIndex,const T &aRef) williamr@2: /** williamr@2: Inserts an element into the array at the specified position. williamr@2: williamr@2: Note that passing a value of anIndex which is the same as the current number williamr@2: of elements in the array, has the effect of appending the element. williamr@2: williamr@2: @param anIndex The position within the array where the element is to be williamr@2: inserted. The position is relative to zero, i.e. zero implies williamr@2: that elements are inserted at the beginning of the array. williamr@2: williamr@2: @param aRef A reference to the class T object to be inserted into the array williamr@2: at position anIndex. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21 if anIndex is negative, or is greater than the number williamr@2: of elements currently in the array. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(anIndex,&aRef);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::InsertL(TInt anIndex,const T *aPtr,TInt aCount) williamr@2: /** williamr@2: Inserts one or more elements into the array at the specified position. williamr@2: williamr@2: The objects to be added must all be contiguous. williamr@2: williamr@2: Note that passing a value of anIndex which is the same as the current number williamr@2: of elements in the array, has the effect of appending the element. williamr@2: williamr@2: @param anIndex The position within the array where the elements are to be williamr@2: inserted. The position is relative to zero, i.e. zero implies williamr@2: that elements are inserted at the beginning of the array. williamr@2: williamr@2: @param aPtr A pointer to the first of the contiguous elements of type williamr@2: class T to be inserted into the array at position anIndex. williamr@2: williamr@2: @param aCount The number of contiguous elements of type class T located at williamr@2: aPtr to be inserted into the array. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21 if anIndex is negative or is greater than the number williamr@2: of elements currently in the array. williamr@2: @panic E32USER-CBase 23 if aCount is negative. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(anIndex,aPtr,aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::InsertL(TInt anIndex,const T &aRef,TInt aReplicas) williamr@2: /** williamr@2: Inserts replicated copies of an element into the array at the specified williamr@2: position. williamr@2: williamr@2: Note that passing a value of anIndex which is the same as the current number williamr@2: of elements in the array, has the effect of appending the element. williamr@2: williamr@2: williamr@2: @param anIndex The position within the array where elements are to be williamr@2: inserted. The position is relative to zero, i.e. zero implies williamr@2: that elements are inserted at the beginning of the array. williamr@2: williamr@2: @param aRef A reference to the class T object to be replicated and williamr@2: inserted into the array at position anIndex. williamr@2: williamr@2: @param aReplicas The number of copies of the aRef element to be inserted into williamr@2: the array. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or is greater than the number williamr@2: of elements currently in the array. williamr@2: @panic E32USER-CBase 28, if aReplicas is negative. williamr@2: */ williamr@2: {CArrayFixBase::InsertRepL(anIndex,&aRef,aReplicas);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayFix::InsertIsqL(const T &aRef,TKeyArrayFix &aKey) williamr@2: /** williamr@2: Inserts a single element into the array at a position determined by a key. williamr@2: williamr@2: The array MUST already be in key sequence (as defined by the key), otherwise williamr@2: the position of the new element is unpredictable, or duplicates may occur. williamr@2: williamr@2: Elements with duplicate keys are not permitted. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted into williamr@2: the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrAlreadyExists An element with the same key already exists within williamr@2: the array. NB the array MUST already be in key sequence, otherwise williamr@2: the function may insert a duplicate and fail to leave with williamr@2: this value. williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: */ williamr@2: {return(CArrayFixBase::InsertIsqL(&aRef,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayFix::InsertIsqAllowDuplicatesL(const T &aRef,TKeyArrayFix &aKey) williamr@2: /** williamr@2: Inserts a single element into the array at a position determined by a key, williamr@2: allowing duplicates. williamr@2: williamr@2: The array MUST already be in key sequence (as defined by the key), otherwise williamr@2: the position of the new element is unpredictable. williamr@2: williamr@2: If the new element's key is a duplicate of an existing element's key, then williamr@2: the new element is positioned after the existing element. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted into williamr@2: the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: */ williamr@2: {return(CArrayFixBase::InsertIsqAllowDuplicatesL(&aRef,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::ResizeL(TInt aCount) williamr@2: /** williamr@2: Changes the size of the array so that it contains the specified number williamr@2: of elements. williamr@2: williamr@2: The following describes the effects of calling this function: williamr@2: williamr@2: 1. If aCount is less than the current number of elements in the array, then the williamr@2: array is shrunk. The elements at positions aCount and above are discarded. williamr@2: The array buffer is not compressed. williamr@2: williamr@2: 2. If aCount is greater than the current number of elements in the array, then williamr@2: the array is extended. williamr@2: williamr@2: 3. New elements are replicated copies of an object of type , williamr@2: constructed using the default constructor of that class. williamr@2: williamr@2: The new elements are positioned after the existing elements in the array. williamr@2: williamr@2: The function may attempt to expand the array buffer. If there is insufficient williamr@2: memory available, the function leaves. The leave code is one of the system williamr@2: wide error codes. If the function leaves, the array is left in the state it williamr@2: was in before the call. williamr@2: williamr@2: @param aCount The number of elements the array is to contain after the resizing williamr@2: operation. williamr@2: williamr@2: @panic E32USER-CBase 24, if aCount is negative. williamr@2: */ williamr@2: {TUint8 b[sizeof(T)]; new(&b[0]) T; CArrayFixBase::ResizeL(aCount,&b[0]);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFix::ResizeL(TInt aCount,const T &aRef) williamr@2: /** williamr@2: Changes the size of the array so that it contains the specified number williamr@2: of elements. williamr@2: williamr@2: The following describes the effects of calling this function: williamr@2: williamr@2: 1. If aCount is less than the current number of elements in the array, then the williamr@2: array is shrunk. The elements at positions aCount and above are discarded. williamr@2: The array buffer is not compressed. williamr@2: williamr@2: 2. If aCount is greater than the current number of elements in the array, then williamr@2: the array is extended. williamr@2: williamr@2: 3. New elements are replicated copies of aRef. williamr@2: williamr@2: The new elements are positioned after the existing elements in the array. williamr@2: williamr@2: The function may attempt to expand the array buffer. If there is insufficient williamr@2: memory available, the function leaves. The leave code is one of the system williamr@2: wide error codes. If the function leaves, the array is left in the state it williamr@2: was in before the call. williamr@2: williamr@2: @param aCount The number of elements the array is to contain after the resizing williamr@2: operation. williamr@2: williamr@2: @param aRef A reference to an object of type , copies of which are williamr@2: used as the new elements of the array, if the array is extended. williamr@2: williamr@2: @panic E32USER-CBase 24, if aCount is negative. williamr@2: */ williamr@2: {CArrayFixBase::ResizeL(aCount,&aRef);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const TArray CArrayFix::Array() const williamr@2: /** williamr@2: Constructs and returns a TArray object. williamr@2: williamr@2: @return A TArray object representing this array. williamr@2: */ williamr@2: {return(TArray(CountR,AtR,this));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CArrayFix::CArrayFix(TBufRep aRep,TInt aRecordLength,TInt aGranularity) williamr@2: : CArrayFixBase(aRep,aRecordLength,aGranularity) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline const TAny *CArrayFix::At(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in the williamr@2: array. williamr@2: williamr@2: @return A pointer to the untyped element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32User-CBase 21, if anIndex is negative or is greater than or equal williamr@2: to the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline const TAny *CArrayFix::End(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the first byte following the end of the contiguous region williamr@2: containing the element at the specfied position within the array. williamr@2: williamr@2: For flat buffers, the pointer always points to the first byte following the williamr@2: end of the buffer. williamr@2: williamr@2: For segmented buffers, the pointer always points to the first byte following williamr@2: the end of the segment which contains the element. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A pointer to the byte following the end of the contiguous region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::End(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline const TAny *CArrayFix::Back(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the beginning of a contiguous region. williamr@2: williamr@2: For flat buffers, the function always returns a pointer to the beginning of williamr@2: the buffer. williamr@2: williamr@2: For segmented buffers, the function returns a pointer to the beginning of williamr@2: the segment for all elements in that segment except the first. If the element williamr@2: at the specified position is the first in a segment, then the function returns williamr@2: a pointer the beginning of the previous segment. williamr@2: williamr@2: For the first element in the array, the function returns a NULL pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in the array. williamr@2: williamr@2: @return A pointer to the beginning of the contiguous region. williamr@2: williamr@2: @panic E32User-CBase 21, if anIndex is negative or is greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::Back(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayFix::At(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in the williamr@2: array. williamr@2: williamr@2: @return A pointer to the untyped element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32User-CBase 21, if anIndex is negative or is greater than or equal williamr@2: to the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayFix::End(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the first byte following the end of the contiguous region williamr@2: containing the element at the specfied position within the array. williamr@2: williamr@2: For flat buffers, the pointer always points to the first byte following the williamr@2: end of the buffer. williamr@2: williamr@2: For segmented buffers, the pointer always points to the first byte following williamr@2: the end of the segment which contains the element. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A pointer to the byte following the end of the contiguous region. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::End(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayFix::Back(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the beginning of a contiguous region. williamr@2: williamr@2: For flat buffers, the function always returns a pointer to the beginning of williamr@2: the buffer. williamr@2: williamr@2: For segmented buffers, the function returns a pointer to the beginning of williamr@2: the segment for all elements in that segment except the first. If the element williamr@2: at the specified position is the first in a segment, then the function returns williamr@2: a pointer the beginning of the previous segment. williamr@2: williamr@2: For the first element in the array, the function returns a NULL pointer. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in the array. williamr@2: williamr@2: @return A pointer to the beginning of the contiguous region. williamr@2: williamr@2: @panic E32User-CBase 21, if anIndex is negative or is greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayFixBase::Back(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayFix::AppendL(const TAny *aPtr) williamr@2: /** williamr@2: Appends the specified untyped element onto the end of the array. williamr@2: williamr@2: @param aPtr A pointer to an untyped element to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(Count(),aPtr);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayFix::AppendL(const TAny *aPtr,TInt aCount) williamr@2: /** williamr@2: Appends one or more untyped elements onto the end of the array. williamr@2: williamr@2: @param aPtr A pointer to the first of the contiguous untyped elements to be williamr@2: appended. williamr@2: @param aCount The number of contiguous elements located at aPtr to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: @panic E32USER-CBase 23, if aCount is negative. williamr@2: */ williamr@2: {CArrayFixBase::InsertL(Count(),aPtr,aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayFix::ExtendL() williamr@2: /** williamr@2: Expands the array by the length of one element at the end of the array and williamr@2: returns a pointer to this new location. williamr@2: williamr@2: As elements are untyped, no construction is possible and the content of the williamr@2: new location remains undefined. williamr@2: williamr@2: @return A pointer to the new element location at the end of the array. williamr@2: williamr@2: @leave KErrNoMemory The function may attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case the array is left in the state it was in before the call. williamr@2: */ williamr@2: {return(CArrayFixBase::ExpandL(Count()));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayFixFlat williamr@2: template williamr@2: inline CArrayFixFlat::CArrayFixFlat(TInt aGranularity) williamr@2: : CArrayFix((TBufRep)CBufFlat::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a flat array of fixed length objects with the specified granularity. williamr@2: williamr@2: The length of all array elements is the length of the class passed as the williamr@2: template parameter. The length must be non-zero. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 17, if the length of the class implied by the template parameter is zero. williamr@2: williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayFixFlat::SetReserveL(TInt aCount) williamr@2: /** williamr@2: Reserves space in the array buffer. williamr@2: williamr@2: If necessary, the array buffer is allocated or re-allocated so that it can williamr@2: accommodate the specified number of elements. williamr@2: williamr@2: After a successful call to this function, elements can be added to the array williamr@2: and the process is guaranteed not to fail for lack of memory - provided the williamr@2: total number of elements does not exceed the number specified in this function. williamr@2: williamr@2: This function does not increase the number of elements in the array; i.e. williamr@2: the member function CArrayFixBase::Count() returns the same value both before williamr@2: and after a call to CArrayFixFlat::SetReserveL(). williamr@2: williamr@2: @param aCount The total number of elements for which space is to be reserved. williamr@2: williamr@2: @panic E32USER-CBase 27, if aCount is less than the current number of elements williamr@2: in the array. williamr@2: */ williamr@2: {this->SetReserveFlatL(aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CArrayFixFlat::CArrayFixFlat(TInt aRecordLength,TInt aGranularity) williamr@2: : CArrayFix((TBufRep)CBufFlat::NewL,aRecordLength,aGranularity) williamr@2: /** williamr@2: Constructs a flat array of fixed length objects with the specified granularity williamr@2: to contain elements of the specified length. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aRecordLength The length of the elements of this fixed length array. williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 17, if aRecordLength is not positive. williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayFixFlat::SetReserveL(TInt aCount) williamr@2: /** williamr@2: Reserves space in the array buffer. williamr@2: williamr@2: If necessary, the array buffer is allocated or re-allocated so that it can williamr@2: accommodate the specified number of elements. williamr@2: williamr@2: After a successful call to this function, elements can be added to the array williamr@2: and the process is guaranteed not to fail for lack of memory - provided the williamr@2: total number of elements does not exceed the specified number. williamr@2: williamr@2: This function does not increase the number of elements in the array; i.e. williamr@2: the member function CArrayFixBase::Count() returns the same value both before williamr@2: and after a call to this function. williamr@2: williamr@2: @param aCount The total number of elements for which space is to be reserved. williamr@2: williamr@2: @panic E32USER-CBase 27, if aCount is less than the current number of elements williamr@2: in the array. williamr@2: */ williamr@2: {SetReserveFlatL(aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayFixFlat::SetReserveL(TInt aCount) williamr@2: /** williamr@2: Reserves space in the array buffer. williamr@2: williamr@2: If necessary, the array buffer is allocated or re-allocated so that it can williamr@2: accommodate the specified number of TInt elements. williamr@2: williamr@2: After a successful call to this function, elements can be added to the array williamr@2: and the process is guaranteed not to fail for lack of memory - provided the williamr@2: total number of elements does not exceed the specified number. williamr@2: williamr@2: This function does not increase the number of elements in the array; i.e. williamr@2: the member function CArrayFixBase::Count() returns the same value both before williamr@2: and after a call to this function. williamr@2: williamr@2: @param aCount The total number of elements for which space is to be reserved. williamr@2: williamr@2: @panic E32USER-CBase 27, if aCount is less than the current number of elements williamr@2: in the array. williamr@2: */ williamr@2: {SetReserveFlatL(aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayFixFlat::SetReserveL(TInt aCount) williamr@2: /** williamr@2: Reserves space in the array buffer. williamr@2: williamr@2: If necessary, the array buffer is allocated or re-allocated so that it can williamr@2: accommodate the specified number of TUid elements. williamr@2: williamr@2: After a successful call to this function, elements can be added to the array williamr@2: and the process is guaranteed not to fail for lack of memory - provided the williamr@2: total number of elements does not exceed the specified number. williamr@2: williamr@2: This function does not increase the number of elements in the array; i.e. williamr@2: the member function CArrayFixBase::Count() returns the same value both before williamr@2: and after a call to this function. williamr@2: williamr@2: @param aCount The total number of elements for which space is to be reserved. williamr@2: williamr@2: @panic E32USER-CBase 27, if aCount is less than the current number of elements williamr@2: in the array. williamr@2: */ williamr@2: {SetReserveFlatL(aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayFixSeg williamr@2: template williamr@2: inline CArrayFixSeg::CArrayFixSeg(TInt aGranularity) williamr@2: : CArrayFix((TBufRep)CBufSeg::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a segmented array of fixed length objects with the specified williamr@2: granularity. williamr@2: williamr@2: The length of all array elements is the length of the class passed as the williamr@2: template parameter. The length must be non-zero. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 17, if the length of the class implied by the template williamr@2: parameter is zero. williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CArrayFixSeg::CArrayFixSeg(TInt aRecordLength,TInt aGranularity) williamr@2: : CArrayFix((TBufRep)CBufSeg::NewL,aRecordLength,aGranularity) williamr@2: /** williamr@2: Constructs a segmented array of fixed length objects with the specified williamr@2: granularity to contain elements of the specified length. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aRecordLength The length of the elements of this array. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 17, if aRecordLength is not positive. williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayPtr williamr@2: template williamr@2: inline CArrayPtr::CArrayPtr(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayFix(aRep,aGranularity) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void CArrayPtr::ResetAndDestroy() williamr@2: /** williamr@2: Destroys all objects whose pointers form the elements of the array, before williamr@2: resetting the array. williamr@2: williamr@2: The destructor of each class T object is called before the objects themselves williamr@2: are destroyed. williamr@2: williamr@2: If the array is not empty, this member function must be called before the williamr@2: array is deleted to prevent the CBase derived objects from being orphaned williamr@2: on the heap. williamr@2: williamr@2: Note that each call to this function results in a small, but non-trivial, williamr@2: amount of code being generated. williamr@2: */ williamr@2: { williamr@2: for (TInt i=0;iCount();++i) williamr@2: delete this->At(i); williamr@2: this->Reset(); williamr@2: } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayPtrFlat williamr@2: template williamr@2: inline CArrayPtrFlat::CArrayPtrFlat(TInt aGranularity) williamr@2: : CArrayPtr((TBufRep)CBufFlat::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a flat array of pointers with specified granularity. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayPtrFlat::SetReserveL(TInt aCount) williamr@2: /** williamr@2: Reserves space in the array buffer. williamr@2: williamr@2: If necessary, the array buffer is allocated or re-allocated so that it can williamr@2: accommodate the specified number of elements. williamr@2: williamr@2: After a successful call to this function, elements can be added to the array williamr@2: and the process is guaranteed not to fail for lack of memory - provided the williamr@2: total number of elements does not exceed the specified number. williamr@2: williamr@2: This function does not increase the number of elements in the array; i.e. williamr@2: the member function CArrayFixBase::Count() returns the same value both before williamr@2: and after a call to this function. williamr@2: williamr@2: @param aCount The total number of elements for which space is to be reserved. williamr@2: williamr@2: @panic E32USER-CBase 27, if aCount is less than the current number of elements williamr@2: in the array. williamr@2: */ williamr@2: {this->SetReserveFlatL(aCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayPtrSeg williamr@2: template williamr@2: inline CArrayPtrSeg::CArrayPtrSeg(TInt aGranularity) williamr@2: : CArrayPtr((TBufRep)CBufSeg::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a segmented array of pointers with specified granularity. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 18, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CArrayVarBase williamr@2: inline TInt CArrayVarBase::Count() const williamr@2: /** williamr@2: Gets the number of elements held in the array. williamr@2: williamr@2: @return The number of array elements. williamr@2: */ williamr@2: {return(iCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayVar williamr@2: template williamr@2: inline CArrayVar::CArrayVar(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayVarBase(aRep,aGranularity) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayVar::operator[](TInt anIndex) const williamr@2: /** williamr@2: Gets a reference to the const element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where it cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayVarBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayVar::operator[](TInt anIndex) williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within williamr@2: the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where it can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: williamr@2: @return A reference to the non-const element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayVarBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayVar::At(TInt anIndex) const williamr@2: /** williamr@2: Gets a reference to the const element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where it cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayVarBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayVar::At(TInt anIndex) williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within williamr@2: the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where it can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A reference to the non-const element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayVarBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayVar::AppendL(const T &aRef,TInt aLength) williamr@2: /** williamr@2: Appends an element of a specified length onto the array. williamr@2: williamr@2: @param aRef A reference to the element to be appended. williamr@2: @param aLength The length of the element to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to williamr@2: contain the new element and may also attempt to expand the array buffer. williamr@2: If there is insufficient memory available, the function leaves, in which williamr@2: case, the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {CArrayVarBase::InsertL(Count(),&aRef,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayVar::ExpandL(TInt anIndex,TInt aLength) williamr@2: /** williamr@2: Expands the array by one element of specified length at the specified position. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element position anIndex williamr@2: williamr@2: 2. constructs a new element of specified length at that position williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: All existing elements from position anIndex to the end of the array are moved williamr@2: up, so that the element originally at position anIndex is now at position williamr@2: anIndex + 1 etc. williamr@2: williamr@2: The new element of type and length aLength is constructed at position williamr@2: anIndex, using the default constructor of that class. williamr@2: williamr@2: @param anIndex The position within the array where the array is to be expanded williamr@2: and the new object is to be constructed. williamr@2: williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A reference to the newly constructed object at position williamr@2: anIndex within the array. williamr@2: williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to contain williamr@2: the new element and may also attempt to expand the array buffer. If there williamr@2: is insufficient memory available, the function leaves, in which case, the williamr@2: array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or is greater than the number williamr@2: of elements currently in the array. williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {return(*new(CArrayVarBase::ExpandL(anIndex,aLength)) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayVar::ExtendL(TInt aLength) williamr@2: /** williamr@2: Expands the array by one element of specified length at the end of the array. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element at the end of the array, i.e. at position williamr@2: CArrayVarBase::Count() williamr@2: williamr@2: 2. constructs a new element of specified length at that position. williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: The new element of type is constructed at the end of the array, williamr@2: using the default constructor of that class. williamr@2: williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A reference to the newly constructed object at the end of williamr@2: the array. williamr@2: williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to contain williamr@2: the new element and may also attempt to expand the array buffer. If there williamr@2: is insufficient memory available, the function leaves, in which case, the williamr@2: array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {return(*new(CArrayVarBase::ExpandL(Count(),aLength)) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayVar::Find(const T &aRef,TKeyArrayVar &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a sequential search. williamr@2: williamr@2: The array is searched sequentially for an element whose key matches the key williamr@2: of the supplied object. The search starts with the first element in the array. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function only williamr@2: supplies the position of the first element in the array with that key. williamr@2: williamr@2: @param aRef A reference to an object of type whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A TInt supplied by the caller. On return, if the element is williamr@2: found, this is set to the position of that element williamr@2: within the array. The position is relative to zero, (i.e. williamr@2: the first element in the array is at position 0). williamr@2: If the element is not found or the array is empty, then williamr@2: this is undefined. williamr@2: williamr@2: @return Zero, if the element with the specified key is found. Non-zero, if williamr@2: the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayVarBase::Find(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayVar::FindIsq(const T &aRef,TKeyArrayVar &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a binary search technique. williamr@2: williamr@2: The array is searched, using a binary search technique, for an element whose williamr@2: key matches the key of the supplied object. williamr@2: williamr@2: The array must be in key order. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function cannot williamr@2: guarantee which element, with the given key value, it will return, except that williamr@2: it will find one of them. williamr@2: williamr@2: @param aRef A reference to an object of type whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A TInt supplied by the caller. On return, if the element is williamr@2: found, this is set to the position of that element within williamr@2: the array. The position is relative to zero, (i.e. williamr@2: the first element in the array is at position zero). williamr@2: If the element is not found and the array is not empty, then williamr@2: this is set to the position of the first element in the array williamr@2: with a key which is greater than the key of the object aRef. williamr@2: If the element is not found and the array is empty, then williamr@2: this is undefined. williamr@2: williamr@2: @return Zero, if the element with the specified key is found or the array is williamr@2: empty. Non-zero, if the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayVarBase::FindIsq(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayVar::InsertL(TInt anIndex,const T &aRef,TInt aLength) williamr@2: /** williamr@2: Inserts an element of a specified length into the array at the specified williamr@2: position. williamr@2: williamr@2: Note that passing a value of anIndex which is the same as the current number williamr@2: of elements in the array, has the effect of appending that element. williamr@2: williamr@2: @param anIndex The position within the array where the element is to be williamr@2: inserted. The position is relative to zero, i.e. zero implies williamr@2: that elements are inserted at the beginning of the array. williamr@2: @param aRef A reference to the object to be inserted into williamr@2: the array. williamr@2: @param aLength The length of the element to be inserted into the array. williamr@2: williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to contain williamr@2: the new element and may also attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case, the array is left in the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or is greater than the number williamr@2: of objects currently in the array. williamr@2: @panic E32USER-CBase 30, if aLength is is negative. williamr@2: */ williamr@2: {CArrayVarBase::InsertL(anIndex,&aRef,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayVar::InsertIsqL(const T &aRef,TInt aLength,TKeyArrayVar &aKey) williamr@2: /** williamr@2: Inserts a single element of a specified length into the array at a position williamr@2: determined by a key. williamr@2: williamr@2: The array MUST already be in key sequence (as defined by the key), otherwise williamr@2: the position of the new element is unpredictable, or duplicates may occur. williamr@2: williamr@2: Elements with duplicate keys are not permitted. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted into williamr@2: the array. williamr@2: @param aLength The length of the new element of type to be inserted williamr@2: into the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrAlreadyExists An element with the same key already exists within williamr@2: the array. NB the array MUST already be in key sequence, otherwise williamr@2: the function may insert a duplicate and fail to leave with williamr@2: this value. williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to contain williamr@2: the new element and may also attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case, the array is left in the state it was in before the call. williamr@2: */ williamr@2: {return(CArrayVarBase::InsertIsqL(&aRef,aLength,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayVar::InsertIsqAllowDuplicatesL(const T &aRef,TInt aLength,TKeyArrayVar &aKey) williamr@2: /** williamr@2: Inserts a single element of a specified length into the array at a position williamr@2: determined by a key, allowing duplicates. williamr@2: williamr@2: The array MUST already be in key sequence, otherwise the position of the williamr@2: new element is unpredictable. williamr@2: williamr@2: Elements with duplicate keys are permitted. If the new element's key is a williamr@2: duplicate of an existing element's key, then the new element is positioned williamr@2: after the existing element. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted williamr@2: into the array. williamr@2: @param aLength The length of the new element to be inserted into the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrNoMemory The function always attempts to allocate a cell to contain williamr@2: the new element and may also attempt to expand the array buffer. If williamr@2: there is insufficient memory available, the function leaves, in which williamr@2: case, the array is left in the state it was in before the call. williamr@2: */ williamr@2: {return(CArrayVarBase::InsertIsqAllowDuplicatesL(&aRef,aLength,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const TArray CArrayVar::Array() const williamr@2: /** williamr@2: Constructs and returns a TArray object. williamr@2: williamr@2: @return A TArray object for this array. williamr@2: */ williamr@2: {return(TArray(CountR,AtR,this));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline const TAny *CArrayVar::At(TInt anIndex) const williamr@2: /** williamr@2: Returns a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned pointer is williamr@2: used in an expression where it cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A pointer to the const element located at position anIndex within the williamr@2: array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayVarBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CArrayVar::CArrayVar(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayVarBase(aRep,aGranularity) williamr@2: /** williamr@2: Constructs a variable array with the specified granularity and buffer williamr@2: organization. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aRep A pointer to a function used to expand the array buffer. williamr@2: The organisation of the array buffer is implied by the williamr@2: choice of this function. williamr@2: For a flat array buffer, pass (TBufRep)CBufFlat::NewL. williamr@2: For a segmented array buffer, pass (TBufRep)CBufSeg::NewL. williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 19, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayVar::At(TInt anIndex) williamr@2: /** williamr@2: Returns a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned pointer is williamr@2: used in an expression where it can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A pointer to the non-const element located at position anIndex within the williamr@2: array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to the williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayVarBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayVar::AppendL(const TAny *aPtr,TInt aLength) williamr@2: /** williamr@2: Appends an untyped element of specified length onto the end of the array. williamr@2: williamr@2: @param aPtr A pointer to an untyped element to be appended. williamr@2: @param aLength The length of the untyped element. williamr@2: */ williamr@2: {CArrayVarBase::InsertL(Count(),aPtr,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayVar::ExtendL(TInt aLength) williamr@2: /** williamr@2: Extends the array by one element of specified length at the end of the array, williamr@2: i.e. at position CArrayVarBase::Count(), and returns a pointer to the new williamr@2: element location. williamr@2: williamr@2: As elements are untyped, no construction is possible and the content of the williamr@2: new location remains undefined. williamr@2: williamr@2: Note that the function always attempts to allocate a cell to contain the new williamr@2: element and may also attempt to expand the array buffer. If there is williamr@2: insufficient memory available, the function leaves. williamr@2: The leave code is one of the system wide error codes. williamr@2: If the function leaves, the array is left in the state it was in before williamr@2: the call. williamr@2: williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A pointer to the new element location at the end of the array. williamr@2: */ williamr@2: {return(CArrayVarBase::ExpandL(Count(),aLength));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayVarFlat williamr@2: template williamr@2: inline CArrayVarFlat::CArrayVarFlat(TInt aGranularity) williamr@2: : CArrayVar((TBufRep)CBufFlat::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a variable flat array with specified granularity. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 19, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayVarSeg williamr@2: template williamr@2: inline CArrayVarSeg::CArrayVarSeg(TInt aGranularity) williamr@2: : CArrayVar((TBufRep)CBufSeg::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a variable segmented array with specified granularity. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 19, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CArrayPakBase williamr@2: inline TInt CArrayPakBase::Count() const williamr@2: /** williamr@2: Gets the number of elements held in the array. williamr@2: williamr@2: @return The number of array elements. williamr@2: */ williamr@2: {return(iCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayPak williamr@2: template williamr@2: inline CArrayPak::CArrayPak(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayPakBase(aRep,aGranularity) williamr@2: /** williamr@2: @internalComponent williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayPak::operator[](TInt anIndex) const williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within the williamr@2: array. williamr@2: williamr@2: The compiler uses this variant of the function when the returned reference williamr@2: is used in an expression where it cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayPakBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayPak::operator[](TInt anIndex) williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within the williamr@2: array. williamr@2: williamr@2: The compiler uses this variant of the function when the returned reference williamr@2: is used in an expression where it can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A non-const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayPakBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const T &CArrayPak::At(TInt anIndex) const williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within the williamr@2: array. williamr@2: williamr@2: The compiler uses this variant of the function when the returned reference williamr@2: is used in an expression where it cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((const T *)CArrayPakBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayPak::At(TInt anIndex) williamr@2: /** williamr@2: Gets a reference to the element located at the specified position within the williamr@2: array. williamr@2: williamr@2: The compiler uses this variant of the function when the returned reference williamr@2: is used in an expression where it can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array. The position williamr@2: is relative to zero; i.e. zero implies the first element in williamr@2: the array. williamr@2: williamr@2: @return A non-const reference to the element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: number of objects currently within the array. williamr@2: */ williamr@2: {return(*((T *)CArrayPakBase::At(anIndex)));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayPak::AppendL(const T &aRef,TInt aLength) williamr@2: /** williamr@2: Appends an element of a specified length onto the array. williamr@2: williamr@2: @param aRef A reference to the class T element to be appended. williamr@2: @param aLength The length of the element to be appended. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to allocate from the heap and there williamr@2: is insufficient memory available. In this case, the array is left in williamr@2: the state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {CArrayPakBase::InsertL(Count(),&aRef,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayPak::ExpandL(TInt anIndex,TInt aLength) williamr@2: /** williamr@2: Expands the array by one element of specified length at the specified position. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element at the specified position. williamr@2: williamr@2: 2. constructs a new element of specified length at that position. williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: All existing elements from position anIndex to the end of the array are moved williamr@2: up, so that the element originally at position anIndex is now at position williamr@2: anIndex + 1 etc. williamr@2: williamr@2: The new element of type and length aLength is constructed at position williamr@2: anIndex, using the default constructor of that class. williamr@2: williamr@2: @param anIndex The position within the array where the array is to be expanded williamr@2: and the new object is to be constructed. williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A reference to the newly constructed object at position williamr@2: anIndex within the array. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to allocate from the heap and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than the number of williamr@2: elements currently in the array. williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {return(*new(CArrayPakBase::ExpandL(anIndex,aLength)) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline T &CArrayPak::ExtendL(TInt aLength) williamr@2: /** williamr@2: Expands the array by one element of specified length at the end of the array. williamr@2: williamr@2: It: williamr@2: williamr@2: 1. expands the array by one element at the end of the array, i.e. at position williamr@2: CArrayPakbase::Count(). williamr@2: williamr@2: 2. constructs a new element of length aLength at that position. williamr@2: williamr@2: 3. returns a reference to the new element. williamr@2: williamr@2: The new element of type is constructed at the end of the array, williamr@2: using the default constructor of that class. williamr@2: williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A reference to the newly constructed object at the end of williamr@2: the array. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to allocate from the heap and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {return(*new(CArrayPakBase::ExpandL(Count(),aLength)) T);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayPak::Find(const T &aRef,TKeyArrayPak &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a sequential search. williamr@2: williamr@2: The array is searched sequentially for an element whose key matches the key williamr@2: of the supplied object. The search starts with the first element williamr@2: in the array. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function only williamr@2: supplies the position of the first element in the array with that key. williamr@2: williamr@2: @param aRef A reference to an object of type whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A reference to a TInt supplied by the caller. On return, if the williamr@2: element is found, this is set to the position williamr@2: of that element within the array. The position is relative to zero, (i.e. williamr@2: the first element in the array is at position 0). williamr@2: If the element is not found or the array is empty, then this is undefined. williamr@2: williamr@2: @return Zero, if the element with the specified key is found. Non-zero, if williamr@2: the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayPakBase::Find(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayPak::FindIsq(const T &aRef,TKeyArrayPak &aKey,TInt &anIndex) const williamr@2: /** williamr@2: Finds the position of an element within the array, based on the matching of williamr@2: keys, using a binary search technique. williamr@2: williamr@2: The array is searched, using a binary search technique, for an element whose williamr@2: key matches the key of the supplied object. williamr@2: williamr@2: The array must be in key order. williamr@2: williamr@2: Note that where an array has elements with duplicate keys, the function cannot williamr@2: guarantee which element, with the given key value, it will return, except that it williamr@2: will find one of them. williamr@2: williamr@2: @param aRef A reference to an object of type whose key is used williamr@2: for comparison. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: @param anIndex A reference to a TInt supplied by the caller. On return, if the williamr@2: element is found, this is set to the position of that element williamr@2: within the array. The position is relative to zero, (i.e. williamr@2: the first element in the array is at position 0). williamr@2: If the element is not found and the array is not empty, then williamr@2: this is set to the position of the first element in the array williamr@2: with a key which is greater than the key of the object aRef. williamr@2: If the element is not found and the array is empty, then this williamr@2: is undefined. williamr@2: williamr@2: @return Zero, if the element with the specified key is found or the array is williamr@2: empty. williamr@2: Non-zero, if the element with the specified key is not found. williamr@2: */ williamr@2: {return(CArrayPakBase::FindIsq(&aRef,aKey,anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void CArrayPak::InsertL(TInt anIndex,const T &aRef,TInt aLength) williamr@2: /** williamr@2: Inserts an element of a specified length into the array at the specified williamr@2: position. williamr@2: williamr@2: @param anIndex The position within the array where the element is to be williamr@2: inserted. The position is relative to zero, i.e. zero implies williamr@2: that elements are inserted at the beginning of the array. williamr@2: @param aRef A reference to the class T object to be inserted into williamr@2: the array. williamr@2: @param aLength The length of the element to be inserted into the array. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to expand the array buffer and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than the number of williamr@2: objects currently in the array. williamr@2: @panic E32USER-CBase 30, if aLength is negative. williamr@2: */ williamr@2: {CArrayPakBase::InsertL(anIndex,&aRef,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayPak::InsertIsqL(const T &aRef,TInt aLength,TKeyArrayPak &aKey) williamr@2: /** williamr@2: Inserts a single element of a specified length into the array at a position williamr@2: determined by a key. williamr@2: williamr@2: The array MUST already be in key sequence (as defined by the key), otherwise williamr@2: the position of the new element is unpredictable, or duplicates may occur. williamr@2: williamr@2: Elements with duplicate keys are not permitted. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted into williamr@2: the array. williamr@2: @param aLength The length of the new element of type to be inserted williamr@2: into the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrAlreadyExists An element with the same key already exists within williamr@2: the array. NB the array MUST already be in key sequence, otherwise williamr@2: the function may insert a duplicate and fail to leave with williamr@2: this value. williamr@2: @leave KErrNoMemory The function attempted to expand the array buffer and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: */ williamr@2: {return(CArrayPakBase::InsertIsqL(&aRef,aLength,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CArrayPak::InsertIsqAllowDuplicatesL(const T &aRef,TInt aLength,TKeyArrayPak &aKey) williamr@2: /** williamr@2: Inserts a single element of a specified length into the array at a position williamr@2: determined by a key, allowing duplicates. williamr@2: williamr@2: The array MUST already be in key sequence, otherwise the position of the williamr@2: new element is unpredictable. williamr@2: williamr@2: Elements with duplicate keys are permitted. If the new element's key is a williamr@2: duplicate of an existing element's key, then the new element is positioned williamr@2: after the existing element. williamr@2: williamr@2: @param aRef A reference to the element of type to be inserted into williamr@2: the array. williamr@2: @param aLength The length of the new element to be inserted into the array. williamr@2: @param aKey A reference to a key object defining the properties of the key. williamr@2: williamr@2: @return The position within the array of the newly inserted element. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to expand the array buffer and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: */ williamr@2: {return(CArrayPakBase::InsertIsqAllowDuplicatesL(&aRef,aLength,aKey));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline const TArray CArrayPak::Array() const williamr@2: /** williamr@2: Constructs and returns a TArray object. williamr@2: williamr@2: @return A Tarray object for this array. williamr@2: */ williamr@2: {return(TArray(CountR,AtR,this));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CArrayPak::CArrayPak(TBufRep aRep,TInt aGranularity) williamr@2: : CArrayPakBase(aRep,aGranularity) williamr@2: /** williamr@2: Constructs a variable array with the specified granularity and williamr@2: buffer organisation. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aRep A pointer to a function used to expand the array buffer. williamr@2: The organisation of the array buffer is implied by the williamr@2: choice of this function. williamr@2: For a flat array buffer, pass (TBufRep)CBufFlat::NewL. williamr@2: For a segmented array buffer, pass (TBufRep)CBufSeg::NewL. williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 19, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline const TAny *CArrayPak::At(TInt anIndex) const williamr@2: /** williamr@2: Gets a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where that reference cannot be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A pointer to the const element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayPakBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayPak::At(TInt anIndex) williamr@2: /** williamr@2: Gets a pointer to the untyped element located at the specified position williamr@2: within the array. williamr@2: williamr@2: The compiler uses this variant of the function if the returned reference is williamr@2: used in an expression where that reference can be modified. williamr@2: williamr@2: @param anIndex The position of the element within the array, relative to zero; williamr@2: i.e. zero implies the first element. williamr@2: williamr@2: @return A pointer to the non-const element located at position anIndex within williamr@2: the array. williamr@2: williamr@2: @panic E32USER-CBase 21, if anIndex is negative or greater than or equal to williamr@2: the number of objects currently within the array. williamr@2: */ williamr@2: {return(CArrayPakBase::At(anIndex));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CArrayPak::AppendL(const TAny *aPtr,TInt aLength) williamr@2: /** williamr@2: Appends the untyped element of the specified length onto the end of the array. williamr@2: williamr@2: @param aPtr A pointer to an untyped element to be appended. williamr@2: @param aLength The length of the untyped element. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to expand the array buffer and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: */ williamr@2: {CArrayPakBase::InsertL(Count(),aPtr,aLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TAny *CArrayPak::ExtendL(TInt aLength) williamr@2: /** williamr@2: Expands the array by one element of the specified length at the end of williamr@2: the array, and returns a pointer to this new location. williamr@2: williamr@2: As elements are untyped, no construction is possible and the content of williamr@2: the new location remains undefined. williamr@2: williamr@2: @param aLength The length of the new element. williamr@2: williamr@2: @return A pointer to the new element location at the end of the array. williamr@2: williamr@2: @leave KErrNoMemory The function attempted to expand the array buffer and there williamr@2: is insufficient memory available. In this case, the array is left in the williamr@2: state it was in before the call. williamr@2: */ williamr@2: {return(CArrayPakBase::ExpandL(Count(),aLength));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CArrayPakFlat williamr@2: template williamr@2: inline CArrayPakFlat::CArrayPakFlat(TInt aGranularity) williamr@2: : CArrayPak((TBufRep)CBufFlat::NewL,aGranularity) williamr@2: /** williamr@2: Constructs a packed flat array with specified granularity. williamr@2: williamr@2: Note that no memory is allocated to the array buffer by this constructor. williamr@2: williamr@2: @param aGranularity The granularity of the array. williamr@2: williamr@2: @panic E32USER-CBase 20, if aGranularity is not positive. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CObject williamr@2: inline TInt CObject::UniqueID() const williamr@2: /** williamr@2: Gets this reference counting object's unique ID. williamr@2: williamr@2: The unique ID is an integer which is a property of the object container. It williamr@2: forms part of the identity of all reference counting objects and is the same williamr@2: value for all reference counting objects held within the same object container. williamr@2: williamr@2: @return This reference counting object's unique ID. williamr@2: williamr@2: @see CObjectCon williamr@2: */ williamr@2: {return(iContainer->UniqueID());} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CObject::AccessCount() const williamr@2: /** williamr@2: Gets the number of open references to this reference counting object. williamr@2: williamr@2: @return The number of open references. williamr@2: */ williamr@2: {return(iAccessCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CObject::Inc() williamr@2: /** williamr@2: Adds one to the reference count. williamr@2: williamr@2: This function is called by the default implementation of the Open() member williamr@2: function of this class. williamr@2: williamr@2: @see CObject::Open williamr@2: */ williamr@2: {iAccessCount++;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CObject::Dec() williamr@2: /** williamr@2: Subtracts one from the reference count. williamr@2: williamr@2: This function is called by the default implementation of the Close() member williamr@2: function of this class. williamr@2: williamr@2: @see CObject::Close williamr@2: */ williamr@2: {iAccessCount--;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline CObject * CObject::Owner() const williamr@2: /** williamr@2: Gets a pointer to the reference counting object which owns this williamr@2: reference counting object. williamr@2: williamr@2: @return A pointer to the owning reference counting object. This is NULL, if williamr@2: there is no owner. williamr@2: */ williamr@2: {return(iOwner);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CObject::SetOwner(CObject *anOwner) williamr@2: /** williamr@2: Sets the owner of this reference counting object. williamr@2: williamr@2: If this reference counting object already has an owner, then all knowledge williamr@2: of that owner is lost. williamr@2: williamr@2: @param anOwner A pointer to the reference counting object which is to be the williamr@2: new owner of this reference counting object. williamr@2: */ williamr@2: {iOwner=anOwner;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // class CObjectIx williamr@2: inline TInt CObjectIx::Count() const williamr@2: /** williamr@2: Gets the number greater then the last slot number used to hold valid CObject pointer. williamr@2: The input argument of CObject* CObjectIx::operator[]() must be less then the number returned by this method. williamr@2: williamr@2: @return The number greater then the last used slot. williamr@2: williamr@2: @see CObjectIx::ActiveCount williamr@2: @see CObjectIx::operator[] williamr@2: */ williamr@2: {return iHighWaterMark;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CObjectIx::ActiveCount() const williamr@2: /** williamr@2: Gets the current number of reference counting objects held by this williamr@2: object index. williamr@2: williamr@2: @return The current number. williamr@2: */ williamr@2: {return iNumEntries;} williamr@2: williamr@2: williamr@2: williamr@2: // class CObjectCon williamr@2: inline TInt CObjectCon::UniqueID() const williamr@2: /** williamr@2: Gets this object container's unique ID. williamr@2: williamr@2: @return The unique ID value. williamr@2: */ williamr@2: {return iUniqueID;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CObjectCon::Count() const williamr@2: /** williamr@2: Gets the number of reference counting objects in this object container. williamr@2: williamr@2: @return The number of objects. williamr@2: */ williamr@2: {return iCount;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // class CCirBufBase williamr@2: inline TInt CCirBufBase::Count() const williamr@2: /** williamr@2: Gets the current number of objects in this circular buffer. williamr@2: williamr@2: @return The number of objects in this circular buffer. williamr@2: This value can never be greater than the maximum capacity. williamr@2: */ williamr@2: {return(iCount);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CCirBufBase::Length() const williamr@2: /** williamr@2: Gets the maximum capacity of this circular buffer. williamr@2: williamr@2: The capacity is the maximum number of elements that the buffer can hold. williamr@2: williamr@2: Use SetLengthL() to change the capacity of the circular buffer. williamr@2: williamr@2: @return The maximum capacity of this circular buffer. williamr@2: williamr@2: @see CCirBufBase::SetLengthL williamr@2: */ williamr@2: {return(iLength);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CCirBuf williamr@2: template williamr@2: inline CCirBuf::CCirBuf() williamr@2: : CCirBufBase(sizeof(T)) williamr@2: /** williamr@2: Default C++ constructor. williamr@2: williamr@2: The size of each object in the buffer is fixed and is the length of the class williamr@2: passed as the template parameter. williamr@2: williamr@2: @panic E32USER-CBase 72, if the length of the template class is zero. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CCirBuf::Add(const T *aPtr) williamr@2: /** williamr@2: Adds a single object to the circular buffer. williamr@2: williamr@2: The object is of type class T and is only added if there is space available. williamr@2: williamr@2: @param aPtr A pointer to the object of type class T to be added to the circular williamr@2: buffer. williamr@2: williamr@2: @return 1 if the object is successfully added. 0 if the object cannot be added williamr@2: because the circular buffer is full. williamr@2: williamr@2: @panic E32USER-CBase 74, if a call to CCirBufBase::SetLengthL() has not been williamr@2: made before calling this function. williamr@2: williamr@2: @see CCirBufBase::SetLengthL williamr@2: */ williamr@2: {return(DoAdd((const TUint8 *)aPtr));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CCirBuf::Add(const T *aPtr,TInt aCount) williamr@2: /** williamr@2: Adds multiple objects to the circular buffer. williamr@2: williamr@2: The function attempts to add aCount objects of type class T. The objects are williamr@2: only added if there is space available. williamr@2: williamr@2: @param aPtr A pointer to a set of contiguous objects of type class T to be williamr@2: added to the circular buffer. williamr@2: williamr@2: @param aCount The number of objects to be added to the circular buffer. williamr@2: williamr@2: @return The number of objects successfully added to the buffer. This value williamr@2: may be less than the number requested and can range from 0 to aCount. williamr@2: williamr@2: @panic E32USER-CBase 74, if a call to CCirBufBase::SetLengthL() has not been williamr@2: made before calling this function. williamr@2: @panic E32USER-CBase 75, if aCount is not a positive value. williamr@2: williamr@2: @see CCirBufBase::SetLengthL williamr@2: */ williamr@2: {return(DoAdd((const TUint8 *)aPtr,aCount));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CCirBuf::Remove(T *aPtr) williamr@2: /** williamr@2: Removes a single object from the circular buffer. williamr@2: williamr@2: An object can only be removed if there are objects in the buffer. williamr@2: williamr@2: A binary copy of the object is made to aPtr. williamr@2: williamr@2: @param aPtr A pointer to an object of type class T supplied by the caller. williamr@2: williamr@2: @return 1 if an object is successfully removed. 0 if an object cannot be removed williamr@2: because the circular buffer is empty. williamr@2: */ williamr@2: {return(DoRemove((TUint8 *)aPtr));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline TInt CCirBuf::Remove(T *aPtr,TInt aCount) williamr@2: /** williamr@2: Removes multiple objects from the circular buffer. williamr@2: williamr@2: The function attempts to remove aCount objects of type class T. williamr@2: Objects can only be removed if there are objects in the buffer williamr@2: williamr@2: A binary copy of the objects is made to aPtr. williamr@2: williamr@2: @param aPtr A pointer to contiguous memory able to hold aCount class T objects, williamr@2: supplied by the caller. williamr@2: williamr@2: @param aCount The number of objects to be removed from the circular buffer. williamr@2: williamr@2: @return The number of objects successfully removed from the buffer. This value williamr@2: may be less than the number requested, and can range from 0 to aCount. williamr@2: williamr@2: @panic E32USER-CBase 76, if aCount is not a positive value. williamr@2: */ williamr@2: {return(DoRemove((TUint8 *)aPtr,aCount));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CActive williamr@2: inline TBool CActive::IsActive() const williamr@2: /** williamr@2: Determines whether the active object has a request outstanding. williamr@2: williamr@2: A request is outstanding when: williamr@2: williamr@2: 1. it has been issued williamr@2: williamr@2: 2. it has not been cancelled williamr@2: williamr@2: 3. it servicing has not yet begun. williamr@2: williamr@2: @return True, if a request is outstanding; false, otherwise. williamr@2: */ williamr@2: {return(iStatus.iFlags&TRequestStatus::EActive);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TBool CActive::IsAdded() const williamr@2: /** williamr@2: Determines whether the active object has been added to the active scheduler's williamr@2: list of active objects. williamr@2: williamr@2: If the active object has not been added to a scheduler, it cannot handle the williamr@2: completion of any request. No request should be issued until the active object williamr@2: has been added to a scheduler because completion of that request generates williamr@2: what appears to be a stray signal. williamr@2: williamr@2: Use the active object function Deque() to remove the active object from the williamr@2: scheduler. williamr@2: williamr@2: @return True, if the active object has been added to an active scheduler; williamr@2: false, otherwise. williamr@2: williamr@2: @see CActive::Deque williamr@2: */ williamr@2: {return(iLink.iNext!=NULL);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TInt CActive::Priority() const williamr@2: /** williamr@2: Gets the priority of the active object. williamr@2: williamr@2: @return The active object's priority value. williamr@2: */ williamr@2: {return iLink.iPriority;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // class CDeltaTimer williamr@2: inline TDeltaTimerEntry::TDeltaTimerEntry(TCallBack& aCallback) williamr@2: /** williamr@2: Constructor specifying a general callback. williamr@2: williamr@2: @param aCallback The callback to be called when this timed event entry expires. williamr@2: */ williamr@2: {iCallBack=aCallback;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TDeltaTimerEntry::TDeltaTimerEntry() williamr@2: /** williamr@2: Default constructor. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void TDeltaTimerEntry::Set(TCallBack& aCallback) williamr@2: /** williamr@2: Sets the specified callback. williamr@2: williamr@2: @param aCallback The callback to be called when this timed event entry expires. williamr@2: */ williamr@2: {iCallBack=aCallback;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: Gets a reference to the server's current message. williamr@2: williamr@2: @return The current message that contains the client request details. williamr@2: */ williamr@2: inline const RMessage2 &CServer2::Message() const williamr@2: {return iMessage;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: Gets the server active object that handles messages for this session. williamr@2: williamr@2: This is the instance of the CServer2 derived class that created williamr@2: this session object. williamr@2: williamr@2: @return The server active object. williamr@2: */ williamr@2: inline const CServer2 *CSession2::Server() const williamr@2: {return iServer;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CAsyncOneShot williamr@2: inline RThread& CAsyncOneShot::Thread() williamr@2: /** williamr@2: Gets a handle to the current thread. williamr@2: williamr@2: @return The handle to the current thread. williamr@2: */ williamr@2: { return iThread; } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CActiveScheduler williamr@2: inline TInt CActiveScheduler::Level() const williamr@2: /** williamr@2: @deprecated Use the StackDepth() function instead. williamr@2: williamr@2: Gets the scheduler's level of nestedness. williamr@2: williamr@2: @return The level of nestedness. williamr@2: williamr@2: @see StackDepth() williamr@2: */ williamr@2: {return StackDepth();} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CActiveSchedulerWait williamr@2: inline TBool CActiveSchedulerWait::IsStarted() const williamr@2: /** williamr@2: Reports whether this CActiveSchedulerWait object is currently started. williamr@2: williamr@2: Note: a CActiveSchedulerWait object itself becomes "stopped" as williamr@2: soon as AsyncStop() is called, and can be started again immediately if williamr@2: required (but this would start a new nested level of the scheduler). williamr@2: williamr@2: @return True if the scheduling loop is active; false, otherwise. williamr@2: williamr@2: @see CActiveSchedulerWait::Start williamr@2: @see CActiveSchedulerWait::AsyncStop williamr@2: */ williamr@2: {return iLoop != NULL;} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class CleanupStack williamr@2: #ifdef _DEBUG williamr@2: inline void CleanupStack::Pop(TAny* aExpectedItem) williamr@2: /** williamr@2: Pops an object from the top of the cleanup stack. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function checks that the specified item is at the top williamr@2: of the cleanup stack before attempting to pop it; an E32USER-CBase 90 panic williamr@2: is raised if the check fails. williamr@2: williamr@2: 2 In a release build, the function just pops the object which is at the top williamr@2: of the cleanup stack; no checking is done. williamr@2: williamr@2: @param aExpectedItem A pointer to the item expected to be at the top of the williamr@2: cleanup stack. In a release build, this parameter williamr@2: is not used. williamr@2: */ williamr@2: { CleanupStack::Check(aExpectedItem); CleanupStack::Pop(); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::Pop(TInt aCount, TAny* aLastExpectedItem) williamr@2: /** williamr@2: Pops the specified number of objects from the top of the cleanup stack. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function pops (aCount-1) items from the cleanup stack, williamr@2: and then checks that the specified item is the next one on the cleanup stack williamr@2: before attempting to pop it; an E32USER-CBase 90 panic is raised if the williamr@2: check fails. williamr@2: williamr@2: 2. In a release build, the function just pops aCount items from the cleanup stack; williamr@2: no checking is done. williamr@2: williamr@2: @param aCount The number of items top be popped from williamr@2: the cleanup stack. williamr@2: @param aLastExpectedItem A pointer to the item expected to be at the top of williamr@2: the cleanup stack, after (aCount-1) items have been williamr@2: popped. In a release build, this parameter is williamr@2: not used. williamr@2: */ williamr@2: { williamr@2: if (--aCount) williamr@2: CleanupStack::Pop(aCount); williamr@2: CleanupStack::Check(aLastExpectedItem); williamr@2: CleanupStack::Pop(); williamr@2: } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::PopAndDestroy(TAny* aExpectedItem) williamr@2: /** williamr@2: Pops an object from the top of the cleanup stack, and cleans it up. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function checks that the specified item is at the top williamr@2: of the cleanup stack before attempting to pop and clean it up; williamr@2: an E32USER-CBase 90 panic is raised if the check fails. williamr@2: williamr@2: 2. In a release build, the function just pops and cleans up the object at williamr@2: the top of the cleanup stack; no checking is done. williamr@2: williamr@2: @param aExpectedItem A pointer to the item expected to be at the top of the williamr@2: cleanup stack. In a release build, this parameter is williamr@2: not used. williamr@2: */ williamr@2: { CleanupStack::Check(aExpectedItem); CleanupStack::PopAndDestroy(); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::PopAndDestroy(TInt aCount, TAny* aLastExpectedItem) williamr@2: /** williamr@2: Pops the specified number of objects from the top of the cleanup stack, and williamr@2: cleans them up. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function pops and cleans up (aCount-1) items from the williamr@2: cleanup stack, and then checks that the specified item is the next one on williamr@2: the cleanup stack before attempting to pop it and clean it up; williamr@2: an E32USER-CBase 90 panic is raised if the check fails. williamr@2: williamr@2: 2. In a release build, the function just pops and cleans up aCount items from williamr@2: the cleanup stack; no checking is done. williamr@2: williamr@2: @param aCount The number of items top be popped from the williamr@2: cleanup stack, and cleaned up. williamr@2: @param aLastExpectedItem A pointer to the item expected to be at the top of williamr@2: the cleanup stack, after (aCount-1) items have been williamr@2: popped and cleaned up. In a release build, this williamr@2: parameter is not used. williamr@2: */ williamr@2: { williamr@2: if (--aCount) williamr@2: CleanupStack::PopAndDestroy(aCount); williamr@2: CleanupStack::Check(aLastExpectedItem); williamr@2: CleanupStack::PopAndDestroy(); williamr@2: } williamr@2: #else williamr@2: inline void CleanupStack::Pop(TAny*) williamr@2: /** williamr@2: Pops an object from the top of the cleanup stack. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function checks that the specified item is at the top williamr@2: of the cleanup stack before attempting to pop it; an E32USER-CBase 90 panic williamr@2: is raised if the check fails. williamr@2: williamr@2: 2 In a release build, the function just pops the object which is at the top williamr@2: of the cleanup stack; no checking is done. williamr@2: williamr@2: @param aExpectedItem A pointer to the item expected to be at the top of the williamr@2: cleanup stack. In a release build, this parameter williamr@2: is not used. williamr@2: */ williamr@2: { CleanupStack::Pop(); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::Pop(TInt aCount, TAny*) williamr@2: /** williamr@2: Pops the specified number of objects from the top of the cleanup stack. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function pops (aCount-1) items from the cleanup stack, williamr@2: and then checks that the specified item is the next one on the cleanup stack williamr@2: before attempting to pop it; an E32USER-CBase 90 panic is raised if the williamr@2: check fails. williamr@2: williamr@2: 2. In a release build, the function just pops aCount items from the cleanup stack; williamr@2: no checking is done. williamr@2: williamr@2: @param aCount The number of items top be popped from williamr@2: the cleanup stack. williamr@2: @param aLastExpectedItem A pointer to the item expected to be at the top of williamr@2: the cleanup stack, after (aCount-1) items have been williamr@2: popped. In a release build, this parameter is williamr@2: not used. williamr@2: */ williamr@2: { CleanupStack::Pop(aCount); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::PopAndDestroy(TAny*) williamr@2: /** williamr@2: Pops an object from the top of the cleanup stack, and cleans it up. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function checks that the specified item is at the top williamr@2: of the cleanup stack before attempting to pop and clean it up; williamr@2: an E32USER-CBase 90 panic is raised if the check fails. williamr@2: williamr@2: 2. In a release build, the function just pops and cleans up the object at williamr@2: the top of the cleanup stack; no checking is done. williamr@2: williamr@2: @param aExpectedItem A pointer to the item expected to be at the top of the williamr@2: cleanup stack. In a release build, this parameter is williamr@2: not used. williamr@2: */ williamr@2: { CleanupStack::PopAndDestroy(); } williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline void CleanupStack::PopAndDestroy(TInt aCount, TAny*) williamr@2: /** williamr@2: Pops the specified number of objects from the top of the cleanup stack, and williamr@2: cleans them up. williamr@2: williamr@2: The function has two modes of operation, depending on whether it is part of williamr@2: a debug build or a release build. williamr@2: williamr@2: 1. In a debug build, the function pops and cleans up (aCount-1) items from the williamr@2: cleanup stack, and then checks that the specified item is the next one on williamr@2: the cleanup stack before attempting to pop it and clean it up; williamr@2: an E32USER-CBase 90 panic is raised if the check fails. williamr@2: williamr@2: 2. In a release build, the function just pops and cleans up aCount items from williamr@2: the cleanup stack; no checking is done. williamr@2: williamr@2: @param aCount The number of items top be popped from the williamr@2: cleanup stack, and cleaned up. williamr@2: @param aLastExpectedItem A pointer to the item expected to be at the top of williamr@2: the cleanup stack, after (aCount-1) items have been williamr@2: popped and cleaned up. In a release build, this williamr@2: parameter is not used. williamr@2: */ williamr@2: { CleanupStack::PopAndDestroy(aCount); } williamr@2: #endif williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class TCleanupItem williamr@2: inline TCleanupItem::TCleanupItem(TCleanupOperation anOperation) williamr@2: : iOperation(anOperation) williamr@2: /** williamr@2: Constructs the object with a cleanup operation. williamr@2: williamr@2: @param anOperation A cleanup operation which will be invoked by the pop and williamr@2: destroy action resulting from a subsequent call to williamr@2: CleanupStack::PopAndDestroy(). williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: inline TCleanupItem::TCleanupItem(TCleanupOperation anOperation,TAny *aPtr) williamr@2: : iOperation(anOperation), iPtr(aPtr) williamr@2: /** williamr@2: Constructs the object with a cleanup operation and a pointer to the object williamr@2: to be cleaned up. williamr@2: williamr@2: @param anOperation A cleanup operation which will be invoked by the pop williamr@2: and destroy action resulting from a subsequent call to williamr@2: CleanupStack::PopAndDestroy(). williamr@2: williamr@2: @param aPtr A pointer to an object which is the target of the williamr@2: cleanup operation. williamr@2: */ williamr@2: {} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Class TCleanupTrapHandler williamr@2: inline CCleanup &TCleanupTrapHandler::Cleanup() williamr@2: {return(*iCleanup);} williamr@2: williamr@2: // Class TAutoClose williamr@2: template williamr@2: inline TAutoClose::~TAutoClose() williamr@2: /** williamr@2: Destructor. williamr@2: williamr@2: The implementation calls Close() on iObj, the instance of the template class. williamr@2: */ williamr@2: #ifdef __LEAVE_EQUALS_THROW__ williamr@2: {if (!std::uncaught_exception()) iObj.Close();} williamr@2: #else williamr@2: {iObj.Close();} williamr@2: #endif williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void TAutoClose::PushL() williamr@2: /** williamr@2: Pushes a cleanup item onto the cleanup stack, so that Close() is called on the williamr@2: templated class object, iObj, if a leave occurs. williamr@2: */ williamr@2: {CleanupStack::PushL(TCleanupItem(Close, (TAny *)&iObj));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: inline void TAutoClose::Pop() williamr@2: /** williamr@2: Pops a single cleanup item from the cleanup stack. williamr@2: */ williamr@2: {CleanupStack::Pop();} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void TAutoClose::Close(TAny *aObj) williamr@2: {((T *)aObj)->Close();} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CleanupDelete williamr@2: template williamr@2: inline void CleanupDelete::PushL(T* aPtr) williamr@2: /** williamr@2: Creates a TCleanupItem for the specified object. williamr@2: williamr@2: The cleanup operation is the private static function Delete() of this class, which williamr@2: deletes the specified object. williamr@2: williamr@2: @param aPtr The object for which a TCleanupItem is to be constructed. williamr@2: */ williamr@2: {CleanupStack::PushL(TCleanupItem(&Delete,aPtr));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void CleanupDelete::Delete(TAny *aPtr) williamr@2: /** williamr@2: The cleanup operation to be performed. williamr@2: williamr@2: @param aPtr A pointer to the object for which clean up is to be performed. williamr@2: The implementation deletes this object. williamr@2: */ williamr@2: {delete STATIC_CAST(T*,aPtr);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // See header file e32base.h for in-source comment. williamr@2: template williamr@2: inline void CleanupDeletePushL(T* aPtr) williamr@2: {CleanupDelete::PushL(aPtr);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CleanupArrayDelete williamr@2: template williamr@2: inline void CleanupArrayDelete::PushL(T* aPtr) williamr@2: /** williamr@2: Creates a TCleanupItem for the specified array. williamr@2: williamr@2: The cleanup operation is the private static function ArrayDelete() of williamr@2: this class, which deletes the specified array. williamr@2: williamr@2: @param aPtr The array of class T type objects for which a TCleanupItem is williamr@2: to be constructed. williamr@2: */ williamr@2: {CleanupStack::PushL(TCleanupItem(&ArrayDelete,aPtr));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void CleanupArrayDelete::ArrayDelete(TAny *aPtr) williamr@2: /** williamr@2: The cleanup operation to be performed. williamr@2: williamr@2: @param aPtr A pointer to the array for which clean up is to be performed. williamr@2: The implementation deletes this array. williamr@2: */ williamr@2: {delete [] STATIC_CAST(T*,aPtr);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // See header file e32base.h for in-source comment. williamr@2: template williamr@2: inline void CleanupArrayDeletePushL(T* aPtr) williamr@2: {CleanupArrayDelete::PushL(aPtr);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CleanupClose williamr@2: template williamr@2: inline void CleanupClose::PushL(T& aRef) williamr@2: /** williamr@2: Creates a TCleanupItem for the specified object. williamr@2: williamr@2: The cleanup operation is the private static function Close() of this class. williamr@2: williamr@2: @param aRef The object for which a TCleanupItem is to be constructed. williamr@2: */ williamr@2: {CleanupStack::PushL(TCleanupItem(&Close,&aRef));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void CleanupClose::Close(TAny *aPtr) williamr@2: /** williamr@2: The cleanup operation to be performed. williamr@2: williamr@2: @param aPtr A pointer to the object for which clean up is to be performed. williamr@2: The implementation calls Close() on this object. williamr@2: */ williamr@2: {(STATIC_CAST(T*,aPtr))->Close();} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // See header file e32base.h for in-source comment. williamr@2: template williamr@2: inline void CleanupClosePushL(T& aRef) williamr@2: {CleanupClose::PushL(aRef);} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // Template class CleanupRelease williamr@2: template williamr@2: inline void CleanupRelease::PushL(T& aRef) williamr@2: /** williamr@2: Creates a TCleanupItem for the specified object. williamr@2: williamr@2: The cleanup operation is the private static function Release() of this class. williamr@2: williamr@2: @param aRef The object for which a TCleanupItem is to be constructed. williamr@2: */ williamr@2: {CleanupStack::PushL(TCleanupItem(&Release,&aRef));} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: template williamr@2: void CleanupRelease::Release(TAny *aPtr) williamr@2: /** williamr@2: The cleanup operation to be performed. williamr@2: williamr@2: @param aPtr A pointer to the object for which clean up is to be performed. williamr@2: The implementation calls Release() on this object. williamr@2: */ williamr@2: {(STATIC_CAST(T*,aPtr))->Release();} williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: // See header file e32base.h for in-source comment. williamr@2: template williamr@2: inline void CleanupReleasePushL(T& aRef) williamr@2: {CleanupRelease::PushL(aRef);}