Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Location: e32base.h
Link against: euser.lib

Class CBufBase

CBufBase

Support

Supported from 5.0

Description

Specifies the interface for dynamic buffers. Functions are grouped into several categories:

In addition, important information is maintained in data members.

Derivation

CBaseBase class for all classes to be instantiated on the heap
CBufBaseSpecifies the interface for dynamic buffers

Defined in CBufBase:
BackPtr(), Compress(), Delete(), ExpandL(), InsertL(), Ptr(), Read(), Reset(), ResizeL(), Size(), Write()

Inherited from CBase:
operator new()


Basic functions


InsertL()

void InsertL(TInt aPos,const TDesC8& aDes);
void InsertL(TInt aPos,const TDesC8& aDes,TInt aLength);
void InsertL(TInt aPos,const TAny* aPtr,TInt aLength);

Description

Inserts data into the buffer — overloaded function. Data at and beyond the insertion position is moved to make way for the inserted data. Data before the insertion position remains in place.

Notes:

Parameters

TInt aPos

Buffer position before which the data will be inserted: must be in range zero to Size()

const TDesC8& aDes

If specified, contains data to insert and specifies the length of the data: the length in the descriptor is overridden if aLength is also specified

TInt aLength

If specified, the length of the data to insert

const TAny* aPtr

If specified, the address of the data to insert

Leave codes

 

If the insertion requires space beyond that already contained in the buffer, and the necessary allocation or re-allocation fails, then a leave occurs.


Write()

void Write(TInt aPos,const TDesC8& aDes);
void Write(TInt aPos,const TDesC8& aDes,TInt aLength);
void Write(TInt aPos,const TAny* aPtr,TInt aLength);

Description

Writes data from a descriptor to the buffer — overloaded function. The existing data from the insertion position, for as many bytes as there are data in the descriptor, is overwritten.

Notes:

Parameters

TInt aPos

Buffer position at which data will begin to be written: must be in range zero to Size() minus the length of the data to write

const TDesC8& aDes

If specified, contains data to write and specifies the length of the data: the length in the descriptor is overridden if aLength is also specified

TInt aLength

If specified, the length of the data to write

const TAny* aPtr

If specified, the address of the data to write


Read()

void Read(TInt aPos,TDes8& aDes) const;
void Read(TInt aPos,TDes8& aDes,TInt aLength) const;
void Read(TInt aPos,TAny* aPtr,TInt aLength) const;

Description

Reads data from the buffer into a descriptor — overloaded function. Data from the buffer position is transferred into the descriptor, for as many bytes as the maximum length of the descriptor, or the length argument specified in the call.

Parameters

TInt aPos

Buffer position from which data is read: must be in range zero to Size() minus the length of the data to read

TDes8& aDes

If specified, on return, contains data read from the buffer; on call, its MaxLength() specifies the amount of data to be read: this is overridden if aLength is also specified

TInt aLength

If specified, the length of the data to read

const TAny* aPtr

If specified, the address into which the data should be read


Size()

TInt Size() const;

Description

Returns the number of data bytes in the buffer.

Note:

The number of heap bytes used by the buffer may be greater than its size, because there is typically extra room to allow for expansion. Use the Compress() function to reduce the extra allocation as much as possible

Return value

TInt

The number of data bytes in the buffer


Delete()

virtual void Delete(TInt aPos,TInt aLength)=0;

Description

Deletes data from the buffer. Data before the buffer position is not affected. From the buffer position, the number of bytes specified are deleted. Bytes beyond the deleted region are moved back to the buffer position. The size of data in the buffer is thus reduced.

Parameters

TInt aPos

Buffer position where the deletion will begin: must be in the range zero to Size() minus the length of the data to be deleted.

TInt aLength

The number of bytes to delete: must be non-negative.


Reset()

void Reset();

Description

Deletes all data in the buffer. Its action is the same as Delete(0,Size()). The buffer is compressed before the function returns.

[Top]


Mass operation support


ExpandL()

void ExpandL(TInt aPos,TInt aLength);

Description

Inserts an uninitialised region into the buffer. Data at and beyond the insertion position is moved to make way for the inserted region. Data before the insertion position remains in place.

Note:

Parameters

TInt aPos

Buffer position before which the region will be inserted: must be in range zero to Size()

TInt aLength

The length of the region to insert

Leave codes

 

If the expansion requires space beyond that already contained in the buffer, and the necessary allocation or re-allocation fails, then a leave occurs.


ResizeL()

void ResizeL(TInt aSize);

Description

Re-sizes the buffer to the specified size. The new size can be larger or smaller than the existing size.

If the new size is larger than the existing size, the buffer is expanded by adding uninitialised data to the end of it.

If the new size is smaller than the existing size, the buffer is reduced; any data at the end of the buffer is lost.

Notes:

Parameters

TInt aSize

The new size of the buffer; this value must be greater than or equal to zero.

Leave codes

 

If the expansion requires space beyond that already contained in the buffer, and the necessary allocation or re-allocation fails, then a leave occurs.

[Top]


Compression


Compress()

virtual void Compress()=0;

Description

Compresses the buffer so as to occupy minimal space. Normally, you would do this when a buffer has reached its final size, or when you know it will not expand again for a while, or when an out-of-memory error has occurred and your program is taking measures to save space. Compression in these circumstances releases memory for other programs to use, but has no adverse effect on performance.

[Top]


Pointer access


Ptr()

virtual TPtr8 Ptr(TInt aPos)=0;

Description

Returns a pointer descriptor which refers to all from the specified data byte until the end of the contiguous region containing that byte. The descriptor will point to the end of the segment containing the byte.

Parameters

TInt aPos

Buffer position: must be in range zero to Size()

Return value

TPtr8

Descriptor whose address points to the byte at the buffer position, and whose length indicates the number of contiguous bytes stored in the buffer, forward from that point. The length will be non-zero unlessaPos==Size().


BackPtr()

virtual TPtr8 BackPtr(TInt aPos)=0;

Description

Returns a pointer descriptor which refers to data from just before the specified data byte backward until the beginning of the contiguous region containing that byte.

Parameters

TInt aPos

Buffer position: must be in range zero to Size()

Return value

TPtr8

Descriptor containing address and length of backward contiguous region. The address in the descriptor is the pointer to the bytes at the buffer position, unless the buffer position was at the beginning of a non-first segment in the buffer: in this case, the address is a pointer just beyond the last data byte in the previous segment. The length is the number of contiguous bytes from the address backwards to the beginning of the segment.