Symbian
Symbian Developer Library

SYMBIAN OS V9.4

Feedback

[Index] [Previous] [Next]

#include <e32base.h>
Link against: euser.lib

Class CBufBase

class CBufBase : public CBase;

Description

Defines the interface for dynamic buffers.

The basic functions, CBufBase::InsertL(TInt,const TDesC8 &), CBufBase::Read(TInt,TDes8 &)const, CBufBase::Write(TInt,const TDesC8 &), CBufBase::Delete(TInt,TInt), CBufBase::Reset() and CBufBase::Size()const, transfer data between the buffer and other places, and allow that data to be deleted

The CBufBase::ExpandL(TInt,TInt) and Resize() functions allow some operations to be carried out with greater efficiency

ACBufBase::Compress() function frees (back to the heap) any space which may have been allocated, but not used

CBufBase::Ptr(TInt) and CBufBase::BackPtr(TInt) allow look-up of contiguous data from any given position, forward or backward

Derivation

Members

Defined in CBufBase:

Inherited from CBase:


Construction and destruction


~CBufBase()

IMPORT_C ~CBufBase();

Description

Destructor

[Top]


Member functions


Size()const

inline TInt Size() const;

Description

Gets the number of data bytes in the buffer.

Note that 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 CBufBase::Compress() function to reduce the extra allocation as much as possible.

Return value

TInt

The number of data bytes in the buffer.


Reset()

IMPORT_C void Reset();

Description

Deletes all data in the buffer.

Its behaviour is the same as calling Delete(0,CBufBase::Size()const). The buffer is compressed before the function returns.


Read(TInt,TDes8 &)const

IMPORT_C void Read(TInt aPos, TDes8 &aDes) const;

Description

Reads data from the buffer into a descriptor.

Data, starting at the specified buffer position is written to the descriptor, filling the descriptor.

Parameters

TInt aPos

Buffer position from which data is read: must be in range zero to CBufBase::Size()const.

TDes8 &aDes

On return, contains the data read from the buffer; its MaxLength() specifies the amount of data to be read.


Read(TInt,TDes8 &,TInt)const

IMPORT_C void Read(TInt aPos, TDes8 &aDes, TInt aLength) const;

Description

Reads the specified number of bytes of data from the buffer into a descriptor.

Parameters

TInt aPos

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

TDes8 &aDes

On return, contains data read from the buffer.

TInt aLength

The length of the data to be read.


Read(TInt,TAny *,TInt)const

IMPORT_C void Read(TInt aPos, TAny *aPtr, TInt aLength) const;

Description

Reads the specified number of bytes of data from the buffer into a specified address.

Parameters

TInt aPos

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

TAny *aPtr

The address into which the data should be read.

TInt aLength

The length of the data to be read.


Write(TInt,const TDesC8 &)

IMPORT_C void Write(TInt aPos, const TDesC8 &aDes);

Description

Writes data from a descriptor to the buffer.

The data in the descriptor overwrites the data in the buffer from the insertion point onwards.

No new space is allocated; this function cannot fail (provided the parameters are specified within the bounds of the buffer and descriptor).

No shuffling occurs; new data is written to the memory locations occupied by the data it overwrites.

Parameters

TInt aPos

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

const TDesC8 &aDes

Contains the data to be written. The length of data to be written is the descriptor length.


Write(TInt,const TDesC8 &,TInt)

IMPORT_C void Write(TInt aPos, const TDesC8 &aDes, TInt aLength);

Description

Writes the specified number of bytes of data from a descriptor to the buffer.

The data in the descriptor overwrites the data in the buffer from the insertion point onwards.

No new space is allocated; this function cannot fail (provided the parameters are specified within the bounds of the buffer and descriptor).

No shuffling occurs; new data is written to the memory locations occupied by the data it overwrites.

Parameters

TInt aPos

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

const TDesC8 &aDes

Contains the data to be written.

TInt aLength

The length of the data to be written.


Write(TInt,const TAny *,TInt)

IMPORT_C void Write(TInt aPos, const TAny *aPtr, TInt aLength);

Description

Writes the specified number of bytes of data from the specified address to the buffer.

The data in the buffer is overwritten from the insertion point onwards.

No new space is allocated; this function cannot fail (provided the parameters are specified within the bounds of the buffer and descriptor).

No shuffling occurs: new data is written to the memory locations occupied by the data it overwrites.

Parameters

TInt aPos

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

const TAny *aPtr

The address of the data to be written.

TInt aLength

The length of the data to be written.

Panic codes

E32USER-CBase

7, if aLength is not positive

E32USER-CBase

5, if aPos + aLength is greater than the number of data bytes in the buffer, i.e. if the target appears to be outside the buffer.


InsertL(TInt,const TDesC8 &)

IMPORT_C void InsertL(TInt aPos, const TDesC8 &aDes);

Description

Inserts data into the buffer.

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:

1. Insertion may require more buffer space to be allocated.

2. In the case of flat buffers, the buffer is extended by a ReAllocL() of the buffer's heap cell, to the smallest multiple of the granularity that will contain the data required. If this reallocation fails, the insertion is impossible and a leave occurs.

3. In the case of segmented buffers, a reallocation is performed if the segment containing the insertion position has insufficient space, and immediately-neighbouring segments cannot be used to contain the new data. As many new segments as are necessary to contain the inserted data are allocated. Each new segment's length is the buffer's granularity. If extension or new allocation fails, a leave occurs.

4. Insertion may also require data to be shuffled. In the case of flat buffers, data beyond the insertion point is shuffled up to create a gap; the new data is then inserted into this gap. In the case of segmented buffers, shuffling is minimised by inserting the new data into newly-allocated buffers, and shuffling only immediately-neighbouring buffers if possible. This may result in some wastage of space, but is much more time-efficient for large amounts of data.

Parameters

TInt aPos

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

const TDesC8 &aDes

The data to be inserted; the length of the data is the descriptor length.

Leave codes

KErrNoMemory

If the insertion requires a bigger buffer, and the necessary allocation or re-allocation fails.


InsertL(TInt,const TDesC8 &,TInt)

IMPORT_C void InsertL(TInt aPos, const TDesC8 &aDes, TInt aLength);

Description

Inserts the specified number of bytes of data from a descriptor into the buffer.

aLength bytes of data from aDes are inserted into the buffer at aPos. 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:

1. Insertion may require more buffer space to be allocated.

2. In the case of flat buffers, the buffer is extended by a ReAllocL() of the buffer's heap cell, to the smallest multiple of the granularity that will contain the data required. If this reallocation fails, the insertion is impossible and a leave occurs.

3. In the case of segmented buffers, a reallocation is performed if the segment containing the insertion position has insufficient space, and immediately-neighbouring segments cannot be used to contain the new data. As many new segments as are necessary to contain the inserted data are allocated. Each new segment's length is the buffer's granularity. If extension or new allocation fails, a leave occurs.

4. Insertion may also require data to be shuffled. In the case of flat buffers, data beyond the insertion point is shuffled up to create a gap: the new data is then inserted into this gap. In the case of segmented buffers, shuffling is minimised by inserting the new data into newly-allocated buffers, and shuffling only immediately-neighbouring buffers if possible. This may result in some wastage of space, but is much more time-efficient for large amounts of data.

Parameters

TInt aPos

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

const TDesC8 &aDes

The data to be inserted.

TInt aLength

The length of data to be inserted.

Leave codes

KErrNoMemory

If the insertion requires a bigger buffer, and the necessary allocation or re-allocation fails.


InsertL(TInt,const TAny *,TInt)

IMPORT_C void InsertL(TInt aPos, const TAny *aPtr, TInt aLength);

Description

Inserts bytes of data from the specified address into the buffer.

Inserts aLength bytes of data found at address aPtr into the buffer at aPos. 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:

1. Insertion may require more buffer space to be allocated.

2. In the case of flat buffers, the buffer is extended by a ReAllocL() of the buffer's heap cell, to the smallest multiple of the granularity that will contain the data required. If this reallocation fails, the insertion is impossible and a leave occurs.

2. In the case of segmented buffers, a reallocation is performed if the segment containing the insertion position has insufficient space, and immediately-neighbouring segments cannot be used to contain the new data. As many new segments as are necessary to contain the inserted data are allocated. Each new segment's length is the buffer's granularity. If extension or new allocation fails, a leave occurs.

4. Insertion may also require data to be shuffled. In the case of flat buffers, data beyond the insertion point is shuffled up to create a gap: the new data is then inserted into this gap. In the case of segmented buffers, shuffling is minimised by inserting the new data into newly-allocated buffers, and shuffling only immediately-neighbouring buffers if possible. This may result in some wastage of space, but is much more time-efficient for large amounts of data.

Parameters

TInt aPos

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

const TAny *aPtr

The address of the data to be inserted.

TInt aLength

The length of the data to be inserted.

Leave codes

KErrNoMemory

If the insertion requires a bigger buffer, and the necessary allocation or re-allocation fails.


ExpandL(TInt,TInt)

IMPORT_C 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:

1. The inserted region is not initialised. After using CBufBase::ExpandL(TInt,TInt), you should then use a series of CBufBase::Write(TInt,const TDesC8 &)s to fill this region with data.

2. Use CBufBase::ExpandL(TInt,TInt) followed by a series of CBufBase::Write(TInt,const TDesC8 &)s when you know the amount of data to be inserted, in advance. It is more efficient than a series of CBufBase::InsertL(TInt,const TDesC8 &)s. In addition, once the result of the CBufBase::ExpandL(TInt,TInt) has been checked, it is guaranteed that the CBufBase::Write(TInt,const TDesC8 &)s do not leave, which can sometimes be useful.

Parameters

TInt aPos

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

TInt aLength

The length of the region to be inserted.


ResizeL(TInt)

IMPORT_C 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:

1. If the new size is larger than the existing size, the function is equivalent to Delete(aSize,CBufBase::Size()const-aSize).

2. If the new size is smaller than the existing size, the function is equivalent to ExpandL((CBufBase::Size()const,aSize-Size()).

3. The motivations for using CBufBase::ResizeL(TInt) are the same as those for using CBufBase::Delete(TInt,TInt) and CBufBase::ExpandL(TInt,TInt).

Parameters

TInt aSize

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


Compress()

virtual void Compress()=0;

Description

Compresses the buffer so as to occupy minimal space.

Normally, you would call 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.

Derived classes provide the implementation.

See also:


Delete(TInt,TInt)

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

Description

Deletes data from the buffer.

Derived classes provide the implementation.

Parameters

TInt aPos

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

TInt aLength

The number of bytes to be deleted; must be non-negative.

See also:


Ptr(TInt)

virtual TPtr8 Ptr(TInt aPos)=0;

Description

Gets a pointer descriptor to represent the data from the specified position to the end of the contiguous region containing that byte.

Derived classes provide the implementation.

Parameters

TInt aPos

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

Return value

TPtr8

Descriptor representing the data starting at aPos, and whose length indicates the number of contiguous bytes stored in the buffer, forward from that point. The length will be non-zero unless aPos==Size().

See also:


BackPtr(TInt)

virtual TPtr8 BackPtr(TInt aPos)=0;

Description

Gets a pointer descriptor to represent data from just before the specified data byte backward to the beginning of the contiguous region containing that byte.

Derived classes provide the implementation.

Parameters

TInt aPos

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

Return value

TPtr8

Descriptor representing the back 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.

See also:


DoInsertL(TInt,const TAny *,TInt)

private: virtual void DoInsertL(TInt aPos, const TAny *aPtr, TInt aLength)=0;

Description

Parameters

TInt aPos

const TAny *aPtr

TInt aLength

[Top]


Member data


iSize

protected: TInt iSize;

Description


iExpandSize

protected: TInt iExpandSize;

Description