Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32base.h
Link against: euser.lib

Class CArrayPak<TAny>

TEMPLATE_SPECIALIZATION class CArrayPak<TAny>
    : public CArrayPakBase

Support

Supported from 5.0

Description

A template specialisation base class for variable length, packed, arrays. The array buffer organisation is defined at construction.

The class is useful for constructing an array of variable length buffers, where the length is decided at run time.

This class is also useful as a data member of a base class in a thin template class/base class pair where the type of the array element is not known until the owning thin template class is instantiated.

Derivation

CArrayPak<TAny>A template specialisation base class for variable length, packed, arrays
CArrayPakBaseAn implementation base class for variable length, packed, arrays
CBaseBase class for all classes to be instantiated on the heap

Defined in CArrayPak:
AppendL(), At(), CArrayPak(), ExtendL(), ~CArrayPak()

Inherited from CArrayPakBase:
Compress(), Count(), Delete(), Length(), Reset(), SortL()

Inherited from CBase:
operator new()


Construction


CArrayPak()

CArrayPak(TBufRep aRep,TInt aGranularity);

Description

Constructs a variable array with the specified granularity and buffer organisation.

Notes

No memory is allocated to the array buffer by this C++ constructor.

Parameters

TBufRep aRep

A pointer to a function used to expand the array buffer. The organisation of the array buffer is implied by the choice of this function. For a flat array buffer, pass (TBufRep)CBufFlat::NewL. For a segmented array buffer, pass (TBufRep)CBufSeg::NewL.

TInt aGranularity

The granularity of the array. This value must be positive otherwise the constructor raises an E32USER-CBase 19 panic.

[Top]


Destruction


~CArrayPak()

~CArrayPak()

Description

The destructor is empty and is present only to cause the virtual function table to be defined in a unique module.

[Top]


Appending elements


AppendL()

void AppendL(const TAny* aPtr,TInt aLength);

Description

Appends the untyped element of the specified length onto the end of the array.

Parameters

const TAny* aPtr

A pointer to an untyped element to be appended.

TInt aLength

The length of the untyped element.

Leave codes

 

The function may attempt to expand the array buffer. If there is insufficient memory available, the function leaves. The leave code is one of the system wide error codes. If the function leaves, the array is left in the state it was in before the call.

[Top]


Expanding the array


ExtendL()

TAny* ExtendL(TInt aLength);

Description

Expands the array by one element of the specified length at the end of the array, i.e. at position CArrayPakBase::Count(), and returns a pointer to this new location.

As elements are untyped, no construction is possible and the content of the new location remains undefined.

Return value

TAny*

A pointer to the new element location at the end of the array.

Leave codes

 

The function may attempt to expand the array buffer. If there is insufficient memory available, the function leaves. The leave code is one of the system wide error codes. If the function leaves, the array is left in the state it was in before the call.

[Top]


Indexing into the array


At()

const TAny* At(TInt anIndex) const;
TAny* At(TInt anIndex);

Description

Returns a pointer to the untyped element located at the specified position within the array.

Two versions of the function are supplied. The compiler chooses the appropriate version based on the use made of the returned reference. If the returned reference is used in an expression where that reference can be modified, then the non-const version is chosen.

Parameters

TInt anIndex

The position of the element within the array. The position is relative to zero; i.e. zero implies the first element in the array. This value must be non-negative and less than the number of objects currently within the array otherwise the functions raise an E32USER-CBase 21 panic.

Return value

TAny*

A non-const pointer to the untyped element located at position anIndex within the array.

const Tany*

A const pointer to the untyped element located at position anIndex within the array.