Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Location: s32buf.h
Link against: estor.lib

Class MStreamBuf

MStreamBuf

Support

Supported from 5.0

Description

A stream buffer that provides a generic I/O interface for streamed data.

A stream buffer:

A seekable stream buffer maintains independent read and write pointers, which can be manipulated separately. This is unlike the RFile interface which maintains a single current position in the file. For example, file streams and memory streams are seekable streams, but socket, serial-comms, and filtered streams are not.

Objects of this type are used by the stream interface classes derived from RReadStream and RWriteStream.

The class has no member data.

Derive from this class, if the stream has no intermediate buffering capabilities, otherwise derive from TStreamBuf.

Defined in MStreamBuf:
SeekL(), Close(), DoReadL(), DoRelease(), DoSeekL(), DoSynchL(), DoWriteL(), ERead, EWrite, PushL(), Read(), ReadL(), Release(), SeekL(), SizeL(), Synch(), SynchL(), TMark, TRead, TWrite, TellL(), Write(), WriteL()

Notes:

See also:


Read from the intermediate buffer


ReadL()

TInt ReadL(TAny* aPtr,TInt aMaxLength);
    

Description

Reads data from the stream buffer into the specified memory location.

The function calls the virtual function DoReadL(TAny*,TInt) to implement this behaviour.

Parameters

TAny* aPtr

A pointer to the target memory location for the data read from the stream buffer.

TInt aMaxLength

The maximum number of bytes to be read.

Return value

TInt

The number of bytes read.

See also:


ReadL()

TInt ReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
    

Description

Reads data, asynchronously, from the stream buffer into the specified descriptor.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour.

If the function leaves, then no read request will have been initiated.

Parameters

TDes8& aDes

The target descriptor for the data read from the stream buffer.

TInt aMaxLength

The maximum number of bytes to be read.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be read, as used in this request. This can be different to the value supplied in aMaxLength; this is dependent on the implementation.

See also:


ReadL()

TInt ReadL(TDes8& aDes,TRequestStatus& aStatus);

Description

Reads data, asynchronously, from the stream buffer into the specified descriptor.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be read is the maximum length of the descriptor.

If the function leaves, then no read request will have been initiated.

Parameters

TDes8& aDes

The target descriptor for the data read from the stream buffer.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be read, as used in this request. This value can be different to the maximum length of the descriptor; this is dependent on the implementation.

See also:


ReadL()

TStreamTransfer ReadL(MStreamInput& anInput,TStreamTransfer aTransfer);
    

Description

Reads data from the stream buffer into the specified data sink.

The function calls the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamInput& anInput

The data sink that is the target for the read operation.

TStreamTransfer aTransfer

Defines the amount of data available to be read.

Return value

TStreamTransfer

The amount of data that was not consumed.


ReadL()

TInt ReadL(MStreamInput& anInput,TInt aMaxLength);
    

Description

Reads data from the stream buffer into the specified data sink.

The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamInput& anInput

The data sink which is the target for the read operation.

TInt aMaxLength

The maximum amount of data available to be read.

Return value

TInt

The amount of data that was not consumed.


ReadL()

void ReadL(MStreamInput& anInput);

Description

Reads data from the stream buffer into the specified data sink.

The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) to implement this behaviour.

No explicit limit is placed on the amount of data that can be read.

Parameters

MStreamInput& anInput

The data sink that is the target for the read operation.


Read()

TInt Read(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
    

Description

Reads data, asynchronously, from the stream buffer into the specified descriptor; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour.

Parameters

TDes8& aDes

The target descriptor for the data read from the stream buffer.

TInt aMaxLength

The maximum number of bytes to be read.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be read, as used in this request. This can be different to the value supplied in aMaxLength; this is dependent on the implementation.

See also:


Read()

TInt Read(TDes8& aDes,TRequestStatus& aStatus);

Description

Reads data, asynchronously, from the stream buffer into the specified descriptor; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be read is the value of the maximum length of the descriptor.

Parameters

TDes8& aDes

The target descriptor for the data read from the stream buffer.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be read, as used in this request. This value can be different to the maximum length of the descriptor; this is dependent on the implementation.

See also:

[Top]


Write to the stream buffer


WriteL()

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

Description

Writes data from the specified memory location into the stream buffer.

The function calls the virtual function DoWriteL(TAny*,TInt) to implement this behaviour.

Parameters

const TAny* aPtr

A pointer to the memory location from which data is to be written to the stream buffer.

TInt aLength

The number of bytes to be written.

See also:


WriteL()

TInt WriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);

Description

Writes data, asynchronously, from the specified descriptor into the stream buffer.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour.

If the function leaves, then no write request will have been initiated.

Parameters

const TDesC8& aDes

The source descriptor for the data to be written into the stream buffer.

TInt aMaxLength

The maximum number of bytes to be written.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be written, as used in this request. This can be different to the value supplied in aMaxLength; this is dependent on the implementation.

See also:


WriteL()

TInt WriteL(const TDesC8& aDes,TRequestStatus& aStatus);

Description

Writes data, asynchronously, from the specified descriptor into the stream buffer.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be written is the value of the maximum length of the descriptor.

If the function leaves, then no write request will have been initiated.

Parameters

const TDesC8& aDes

The source descriptor for the data to be written into the stream buffer.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be written, as used in this request. This can be different to the maximum length of the descriptor; this is dependent on the implementation.

See also:


WriteL()

TStreamTransfer WriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer);
    

Description

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamOutput& anOutput

The data source for the write operation.

TStreamTransfer aTransfer

Defines the amount of data to be pulled from the output stream object.

Return value

TStreamTransfer

A stream transfer object defining the amount of data that was not consumed.


WriteL()

TInt WriteL(MStreamOutput& anOutput,TInt aMaxLength);

Description

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

Parameters

MStreamOutput& anOutput

The data source for the write operation.

TInt aMaxLength

The maximum amount of data available to be written.

Return value

TInt

The amount of data that was not consumed.


WriteL()

void WriteL(MStreamOutput& anOutput);

Description

Writes data into the stream buffer from the specified data source.

The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) to implement this behaviour.

No explicit limit is placed on the amount of data that can be written.

Parameters

MStreamOutput& anOutput

The data source for the write operation.

TInt aMaxLength

The maximum amount of data available to be written.


Write()

TInt Write(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);

Description

Writes data, asynchronously, from the specified descriptor into the stream buffer; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour.

Parameters

MStreamOutput& anOutput

The output stream which is the source for the write operation.

Return value

TInt

The maximum number of bytes to be written, as used in this request. This can be different to the value supplied in aMaxLength; this is dependent on the implementation.

See also:


Write()

TInt Write(const TDesC8& aDes,TRequestStatus& aStatus);
    

Description

Writes data, asynchronously, from the specified descriptor into the stream buffer; request completion is guaranteed, even if request initiation fails.

The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) to implement this behaviour. The maximum number of bytes to be written is the value of the maximum length of the descriptor.

Parameters

const TDesC8& aDes

The source descriptor for the data to be written into the stream buffer.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be written, as used in this request. This can be different to the value supplied in aMaxLength; this is dependent on the implementation.

See also:

[Top]


Positioning read and write marks in the stream


SeekL()

void SeekL(TMark aMark,TStreamPos aPos);

Description

Moves the position of the read or write mark in the stream.

The new position is calculated by adding the specified value to the position of the beginning of the stream.

The function calls virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TMark aMark

The type of mark, i.e. read or write.

TStreamPos aLocation

A stream position value on which the calculation of the new position is based.

Notes:


SeekL()

TStreamPos SeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset=0);

Description

Moves the position of the read mark or the write mark in the stream.

The new position is calculated by adding the specified offset to one of:

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TMark aMark

The type of mark, i.e read or write.

TStreamLocation aLocation

The location in the stream on which the calculation of the new position is based.

TInt anOffset

The offset value.

Return value

TStreamPos

The new stream position of the read or write mark.

Notes:


SeekL()

TStreamPos SeekL(TRead,TStreamLocation aLocation,TInt anOffset=0);

Description

Moves the position of the read mark in the stream.

The new position is calculated by adding the specified offset to one of:

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TRead

(The enumerator value is not used)

TStreamLocation aLocation

The location in the stream on which the calculation of the new position is based.

TInt anOffset

The offset value.

Return value

TStreamPos

The new stream position of the read mark.

Notes:


SeekL()

TStreamPos SeekL(TWrite,TStreamLocation aLocation,TInt anOffset=0);

Description

Moves the position of the write mark in the stream.

The new position is calculated by adding the specified offset to one of:

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TWrite

(The enumerator value is not used)

TStreamLocation aLocation

The location in the stream on which the calculation of the new position is based.

TInt anOffset

The offset value.

Return value

TStreamPos

The new stream position of the write mark.

Notes:


SeekL()

TStreamPos SeekL(TRead,TInt anOffset);

Description

Moves the position of the read mark in the stream by the specified offset.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TRead

(The enumerator value is not used)

TInt anOffset

The amount by which the position of the read mark is to be moved relative to the existing position of the read mark.

Return value

TStreamPos

The new stream position of the read mark.

Notes:


SeekL()

TStreamPos SeekL(TWrite,TInt anOffset);

Description

Moves the position of the write mark in the stream by the specified offset.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TWrite

(The enumerator value is not used)

TInt anOffset

The amount by which the position of the write mark is to be moved relative to the existing position of the write mark.

Return value

TStreamPos

The new stream position of the write mark.

Notes:

[Top]


Closing and cleanup related activities


Synch()

TInt Synch();

Description

Synchronises the stream buffer with the stream, returning any error.

In effect, this ensures that buffered data is delivered to the stream.

This function calls SynchL() inside a TRAPD harness and returns the leave code if a leave occurs.

Return value

TInt

KErrNone, if successful; otherwise one of the other system wide error codes.

See also:


SynchL()

void SynchL();

Description

Synchronises the stream buffer with the stream, leaving if any error occurs.

In effect, this ensures that buffered data is delivered to the stream.

The function calls the virtual function DoSynchL() to implement this behaviour.

See also:


Release()

void Release();

Description

Frees resources before abandoning the stream buffer.

The function calls the virtual function DoRelease() to implement this behaviour.

Release() is called by both RReadStream::Release() and RWriteStream::Release().

See also:


Close()

void Close();

Description

Closes the stream buffer.

This function attempts to synchronise buffered data with the stream before freeing any resources. All errors are ignored.

See also:


PushL()

void PushL();

Description

Puts a cleanup item for this object onto the cleanup stack.

This allows allocated resources to be cleaned up if a subsequent leave occurs.

[Top]


Accessors


TellL()

TStreamPos TellL(TRead) const;

Description

Gets the position of the read mark within the stream.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TRead

(The enumerator value is not used).

Return value

TStreamPos

The stream position.


TellL()

TStreamPos TellL(TWrite)
const;

Description

Gets the position of the write mark within the stream.

The function calls the virtual function DoSeekL(TMark,TStreamLocation,TInt) to implement this behaviour.

Parameters

TWrite

(The enumerator value is not used).

Return value

TStreamPos

The stream position.


SizeL()

TInt SizeL() const;

Description

Gets the size of the stream.

Return value

TInt

The size of the stream, in bytes.

[Top]


Virtual functions providing default behaviour


DoReadL()

private : virtual TInt DoReadL(TAny* aPtr,TInt aMaxLength);

Description

Reads data from the stream buffer into the specified memory location.

This is called by ReadL(TAny*,TInt).

This class does not provide buffering capabilities and, therefore, this implementation raises a STORE-Stream 10 panic. Buffering capabilities are supported by the derived class, TStreamBuf, which provides an implementation.

Parameters

TAny* aPtr

A pointer to the target memory location for the data read from this stream buffer.

TInt aMaxLength

The maximum number of bytes to be read.

Return value

TInt

The number of bytes read.

See also:


DoReadL()

private : virtual TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);

Description

Reads data from the stream buffer into the specified descriptor.

This function is called by ReadL(TDes8&,TInt,TRequestStatus&).

This implementation deals with the request synchronously, and completes the request with KErrNone. Other implementations may choose to deal with this in a true asynchronous manner.

In addition, the read operation itself uses the DoReadL(TAny*,TInt) variant.

Parameters

TDes8& aDes

The target descriptor for the data read from the stream buffer. On return, the length of the descriptor is set to the number of bytes read from the stream buffer.

TInt aMaxLength

The maximum number of bytes to be read. This value must not be greater than the maximum length of the descriptor, otherwise the function raises a STORE-Stream 2 panic.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be read, as used in this request. This implementation uses, and returns, the value supplied in aMaxLength. Other implementations may choose to use a different value.

See also:


DoReadL()

private : virtual TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer);

Description

Reads data from the stream into the specified data sink.

It is called by ReadL(MStreamInput&,TStreamTransfer).

This implementation calls the sink's ReadFromL() function, which performs the read (transfer) operation.

Parameters

MStreamInput& anInput

The target data sink.

TStreamTransfer aTransfer

A stream transfer object defining the amount of data available to be read.

Return value

TStreamTransfer

A stream transfer object defining the amount of data that was not consumed.

Notes:

See also:


DoWriteL()

private : virtual void DoWriteL(const TAny* aPtr,TInt aLength);

Description

Writes data from the specified memory location into the stream buffer.

This is called by WriteL(const TAny*,TInt).

This class does not provide buffering capabilities and, therefore, this implementation raises a STORE-Stream 11 panic. Buffering capabilities are supported by the derived class, TStreamBuf, which provides an implementation.

Parameters

const TAny* aPtr

A pointer to the source memory location for the data to be written to this stream buffer.

TInt aLength

The number of bytes to be written.

See also:


DoWriteL()

private : virtual TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);

Description

Writes data from the specified descriptor into this stream buffer.

This function is called by WriteL(const TDesC8&,TInt,TRequestStatus&).

This implementation deals with the request synchronously, and completes the request with KErrNone. Other implementations may choose to deal with this in a true asynchronous manner.

In addition, the write operation itself uses the DoWriteL(TAny*,TInt) variant.

Parameters

const TDesC8& aDes

The source descriptor for the data to be written into the stream buffer.

TInt aMaxLength

The number of bytes to be written. This value must not be greater than the maximum length of the descriptor, otherwise the function raises a STORE-Stream 6 panic.

TRequestStatus& aStatus

The request status that indicates the completion status of this asynchronous request.

Return value

TInt

The maximum number of bytes to be written, as used in this request. This implementation uses, and returns, the value supplied in aMaxLength. Other implementations may choose to use a different value.

See also:


DoWriteL()

private : virtual TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer);

Description

Writes data to the stream from the specified data source.

It is called by WriteL(MStreamOutput&,TStreamTransfer).

This implementation calls the target stream output object's WriteToL() function, which performs the write (transfer) operation.

Parameters

MStreamOutput& anInput

The data source.

TStreamTransfer aTransfer

A stream transfer object defining the amount of data available to be written.

Return value

TStreamTransfer

The amount of data that was not consumed.

Notes:


DoSeekL()

private : virtual TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);

Description

Moves the position of the read/write mark in the stream.

The new position is calculated by adding the specified offset to one of:

It is called by all variations of SeekL() and Seek().

Not all streams are seekable, and this default implementation raises a STORE-Stream 12 panic. Streams that are seekable must provide a suitable implementation.

Parameters

TMark aMark

The type of mark (read or write) whose position is to be set.

TStreamLocation aLocation

The location in the stream on which the calculation of the new position is based.

TInt anOffset

The offset from the specified location.

Return value

TStreamPos

The new stream position of the read/write mark.

See also:


DoRelease()

private : virtual void DoRelease();

Description

Frees resources before abandoning the stream buffer.

It is called by Release().

This implementation is empty, but classes derived from MStreamBuf can provide their own implementation, if necessary.

See also:


DoSynchL()

private : virtual void DoSynchL();

Description

Synchronises the stream buffer with the stream, leaving if any error occurs.

In effect, this ensures that buffered data is delivered to the stream.

It is called by SynchL().

This implementation is empty, but classes derived from MStreamBuf can provide their own implementation, if necessary.

See also:

[Top]


enumerations


Enum TRead

TRead

Description

Indicates that an operation applies to the read mark in a stream or to the read area in an stream buffer.

ERead

The flag bit used to indicate that an operation applies to the read mark in a stream or to the read area in an stream buffer.


Enum TWrite

TWrite

Description

Indicates that an operation applies to the write mark in a stream or to the write area in an stream buffer.

EWrite

The flag bit used to indicate that an operation applies to the write mark in a stream or to the write area in an stream buffer.

[Top]


Typedefs


Typedef TMark

typedef TInt TMark;

Description

Used to identify the type of mark in a stream.

The type is used by functions of this class and derived classes that perform seek operations to marks within a stream.

The type uses the ERead and EWrite enumeration values, as bit flags, to identify the read and write marks respectively.

ERead is an MStreamBuf::TRead enumerator. EWrite is an MStreamBuf::EWrite enumerator.

See also: