CArrayVar Class Reference

class CArrayVar : public CArrayVarBase

A thin templated base class for variable length arrays.

The public functions provide standard array behaviour.

The class is always derived from and is never instantiated explicitly.

Inherits from

Constructor & Destructor Documentation

CArrayVar(TBufRep, TInt)

CArrayVar ( TBufRep aRep,
TInt aGranularity
) [inline]

Parameters

TBufRep aRep
TInt aGranularity

Member Functions Documentation

AppendL(const T &, TInt)

void AppendL ( const T & aRef,
TInt aLength
) [inline]

Appends an element of a specified length onto the array.

leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.
panic
E32USER-CBase 30, if aLength is negative.

Parameters

const T & aRef A reference to the <class T> element to be appended.
TInt aLength The length of the element to be appended.

Array()

const TArray < T > Array ( ) const [inline]

Constructs and returns a TArray<T> object.

At(TInt)

const T & At ( TInt anIndex ) const [inline]

Gets a reference to the const element located at the specified position within the array.

The compiler uses this variant of the function if the returned reference is used in an expression where it cannot be modified.

panic
E32USER-CBase 21, if anIndex is negative or greater than or equal to the number of objects currently within the array.

Parameters

TInt anIndex The position of the element within the array, relative to zero; i.e. zero implies the first element.

At(TInt)

T & At ( TInt anIndex ) [inline]

Gets a reference to the element located at the specified position within the array.

The compiler uses this variant of the function if the returned reference is used in an expression where it can be modified.

panic
E32USER-CBase 21, if anIndex is negative or greater than or equal to the number of objects currently within the array.

Parameters

TInt anIndex The position of the element within the array, relative to zero; i.e. zero implies the first element.

ExpandL(TInt, TInt)

T & ExpandL ( TInt anIndex,
TInt aLength
) [inline]

Expands the array by one element of specified length at the specified position.

It:

1. expands the array by one element position anIndex

2. constructs a new element of specified length at that position

3. returns a reference to the new element.

All existing elements from position anIndex to the end of the array are moved up, so that the element originally at position anIndex is now at position anIndex + 1 etc.

The new element of type <class T> and length aLength is constructed at position anIndex, using the default constructor of that class.

leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.
panic
E32USER-CBase 21, if anIndex is negative or is greater than the number of elements currently in the array.
panic
E32USER-CBase 30, if aLength is negative.

Parameters

TInt anIndex The position within the array where the array is to be expanded and the new <class T> object is to be constructed.
TInt aLength The length of the new element.

ExtendL(TInt)

T & ExtendL ( TInt aLength ) [inline]

Expands the array by one element of specified length at the end of the array.

It:

1. expands the array by one element at the end of the array, i.e. at position CArrayVarBase::Count()

2. constructs a new element of specified length at that position.

3. returns a reference to the new element.

The new element of type <class T> is constructed at the end of the array, using the default constructor of that class.

leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.
panic
E32USER-CBase 30, if aLength is negative.

Parameters

TInt aLength The length of the new element.

Find(const T &, TKeyArrayVar &, TInt &)

TInt Find ( const T & aRef,
TKeyArrayVar & aKey,
TInt & anIndex
) const [inline]

Finds the position of an element within the array, based on the matching of keys, using a sequential search.

The array is searched sequentially for an element whose key matches the key of the supplied object. The search starts with the first element in the array.

Note that where an array has elements with duplicate keys, the function only supplies the position of the first element in the array with that key.

Parameters

const T & aRef A reference to an object of type <class T> whose key is used for comparison.
TKeyArrayVar & aKey A reference to a key object defining the properties of the key.
TInt & anIndex A TInt supplied by the caller. On return, if the element is found, this is set to the position of that element within the array. The position is relative to zero, (i.e. the first element in the array is at position 0). If the element is not found or the array is empty, then this is undefined.

FindIsq(const T &, TKeyArrayVar &, TInt &)

TInt FindIsq ( const T & aRef,
TKeyArrayVar & aKey,
TInt & anIndex
) const [inline]

Finds the position of an element within the array, based on the matching of keys, using a binary search technique.

The array is searched, using a binary search technique, for an element whose key matches the key of the supplied <class T> object.

The array must be in key order.

Note that where an array has elements with duplicate keys, the function cannot guarantee which element, with the given key value, it will return, except that it will find one of them.

Parameters

const T & aRef A reference to an object of type <class T> whose key is used for comparison.
TKeyArrayVar & aKey A reference to a key object defining the properties of the key.
TInt & anIndex A TInt supplied by the caller. On return, if the element is found, this is set to the position of that element within the array. The position is relative to zero, (i.e. the first element in the array is at position zero). If the element is not found and the array is not empty, then this is set to the position of the first element in the array with a key which is greater than the key of the object aRef. If the element is not found and the array is empty, then this is undefined.

InsertIsqAllowDuplicatesL(const T &, TInt, TKeyArrayVar &)

TInt InsertIsqAllowDuplicatesL ( const T & aRef,
TInt aLength,
TKeyArrayVar & aKey
) [inline]

Inserts a single element of a specified length into the array at a position determined by a key, allowing duplicates.

The array MUST already be in key sequence, otherwise the position of the new element is unpredictable.

Elements with duplicate keys are permitted. If the new element's key is a duplicate of an existing element's key, then the new element is positioned after the existing element.

leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.

Parameters

const T & aRef A reference to the element of type <class T> to be inserted into the array.
TInt aLength The length of the new element to be inserted into the array.
TKeyArrayVar & aKey A reference to a key object defining the properties of the key.

InsertIsqL(const T &, TInt, TKeyArrayVar &)

TInt InsertIsqL ( const T & aRef,
TInt aLength,
TKeyArrayVar & aKey
) [inline]

Inserts a single element of a specified length into the array at a position determined by a key.

The array MUST already be in key sequence (as defined by the key), otherwise the position of the new element is unpredictable, or duplicates may occur.

Elements with duplicate keys are not permitted.

leave
KErrAlreadyExists An element with the same key already exists within the array. NB the array MUST already be in key sequence, otherwise the function may insert a duplicate and fail to leave with this value.
leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.

Parameters

const T & aRef A reference to the element of type <class T> to be inserted into the array.
TInt aLength The length of the new element of type <class T> to be inserted into the array.
TKeyArrayVar & aKey A reference to a key object defining the properties of the key.

InsertL(TInt, const T &, TInt)

void InsertL ( TInt anIndex,
const T & aRef,
TInt aLength
) [inline]

Inserts an element of a specified length into the array at the specified position.

Note that passing a value of anIndex which is the same as the current number of elements in the array, has the effect of appending that element.

leave
KErrNoMemory The function always attempts to allocate a cell to contain the new element and may also attempt to expand the array buffer. If there is insufficient memory available, the function leaves, in which case, the array is left in the state it was in before the call.
panic
E32USER-CBase 21, if anIndex is negative or is greater than the number of objects currently in the array.
panic
E32USER-CBase 30, if aLength is is negative.

Parameters

TInt anIndex The position within the array where the element is to be inserted. The position is relative to zero, i.e. zero implies that elements are inserted at the beginning of the array.
const T & aRef A reference to the <class T> object to be inserted into the array.
TInt aLength The length of the element to be inserted into the array.

operator[](TInt)

const T & operator[] ( TInt anIndex ) const [inline]

Gets a reference to the const element located at the specified position within the array.

The compiler uses this variant of the function if the returned reference is used in an expression where it cannot be modified.

panic
E32USER-CBase 21, if anIndex is negative or greater than or equal to the number of objects currently within the array.

Parameters

TInt anIndex The position of the element within the array, relative to zero; i.e. zero implies the first element.

operator[](TInt)

T & operator[] ( TInt anIndex ) [inline]

Gets a reference to the element located at the specified position within the array.

The compiler uses this variant of the function if the returned reference is used in an expression where it can be modified.

panic
E32USER-CBase 21, if anIndex is negative or greater than or equal to the number of objects currently within the array.

Parameters

TInt anIndex The position of the element within the array, relative to zero; i.e. zero implies the first element.