QBuffer(3qt)

NAME
QBuffer - I/O device that operates on a QByteArray

SYNOPSIS

#include <qbuffer.h>

Inherits QIODevice.

  Public Members
QBuffer ()
QBuffer ( QByteArray )
~QBuffer ()
QByteArray buffer () const
bool setBuffer ( QByteArray )
virtual bool open ( int )
virtual void close ()
virtual void flush ()
virtual uint size () const
virtual int at () const
virtual bool at ( int )
virtual int readBlock ( char * p, uint )
virtual int writeBlock ( const char * p, uint )
virtual int readLine ( char * p, uint )
virtual int getch ()
virtual int putch ( int )
virtual int ungetch ( int )

DESCRIPTION
The QBuffer class is an I/O device that operates on a QByteArray

QBuffer is an I/O device for reading and writing a memory buffer. A QBuffer may be used directly (readBlock() and writeBlock()) or more conveniently via QDataStream or QTextStream. Most of its behavior is inherited from QIODevice.

A QBuffer has an associated QByteArray which holds the buffer data. Writing data at the end (i.e. size()) of the buffer expands the byte array.

For convenience, the byte stream classes QDataStream and QTextStream can operate on a QByteArray (or a QString) via an internal QBuffer:

    QString str;
    QTextStream ts( str, IO_WriteOnly );
    ts << "pi = " << 3.14;                      // str == "pi = 3.14"

See also: QFile, QDataStream and QTextStream.

Examples: grapher/grapher.cpp

MEMBER FUNCTION DOCUMENTATION

QBuffer::QBuffer ()
Constructs an empty buffer.

QBuffer::QBuffer ( QByteArray buf )
Constructs a buffer and sets the buffer contents to buf.

See also: setBuffer().

QBuffer::~QBuffer ()
Destroys the buffer.

bool QBuffer::at ( int pos ) [virtual]
Sets the buffer index to pos. Returns TRUE if successful, otherwise FALSE.

See also: size().

Reimplemented from QIODevice.

int QBuffer::at () const [virtual]
Returns the buffer index.

See also: size().

Reimplemented from QIODevice.

QByteArray QBuffer::buffer () const
Returns the buffer most recently set by setBuffer(), or at construction.

void QBuffer::close () [virtual]
Closes an open buffer.

See also: open().

Examples: grapher/grapher.cpp

Reimplemented from QIODevice.

void QBuffer::flush () [virtual]
The flush function does nothing.

Reimplemented from QIODevice.

int QBuffer::getch () [virtual]
Reads a single byte/character from the buffer.

Returns the byte/character read, or -1 if the end of the buffer has been reached.

See also: putch() and ungetch().

Reimplemented from QIODevice.

bool QBuffer::open ( int m ) [virtual]
Opens the file specified by the file name currently set, using the mode m. Returns TRUE if successful, otherwise FALSE.

The mode parameter m must be a combination of the following flags.

IO_ReadOnly opens a buffer in read-only mode.

IO_WriteOnly opens a buffer in write-only mode.

IO_ReadWrite opens a buffer in read/write mode.

IO_Append sets the buffer index to the end of the buffer.

IO_Truncate truncates the buffer.

See also: close() and isOpen().

Examples: grapher/grapher.cpp

Reimplemented from QIODevice.

int QBuffer::putch ( int ch ) [virtual]
Writes the character ch into the buffer, overwriting the character at the current index, extending the buffer if necessary.

Returns ch, or -1 if some error occurred.

See also: getch() and ungetch().

Examples: grapher/grapher.cpp

Reimplemented from QIODevice.

int QBuffer::readBlock ( char * p, uint len ) [virtual]
Reads at most len bytes from the buffer into p and returns the number of bytes actually read.

Returns -1 if a serious error occurred.

See also: writeBlock().

Reimplemented from QIODevice.

int QBuffer::readLine ( char * p, uint maxlen ) [virtual]
Reads a line of text.

Reads bytes from the buffer until end-of-line is reached, or up to maxlen bytes.

See also: readBlock().

Reimplemented from QIODevice.

bool QBuffer::setBuffer ( QByteArray buf )
Replaces the buffer's contents with buf.

This may not be done while the buffer is open.

Note that if you open the buffer in write mode (IO_WriteOnly or IO_ReadWrite) and write something into the buffer, buf is also modified because QByteArray is an explicitly shared class.

Example:

    QString str = "abc";
    QBuffer b( str );
    b.open( IO_WriteOnly );
    b.at( 3 );                                  // position at \0
    b.writeBlock( "def", 4 );                   // write including \0
    b.close();
      // Now, str == "abcdef"

See also: open and Shared Classes

uint QBuffer::size () const [virtual]
Returns the number of bytes in the buffer.

See also: at().

Reimplemented from QIODevice.

int QBuffer::ungetch ( int ch ) [virtual]
Puts the character ch back into the buffer and decrements the index if it is not zero.

This function is normally called to "undo" a getch() operation.

Returns ch, or -1 if some error occurred.

See also: getch() and putch().

Reimplemented from QIODevice.

int QBuffer::writeBlock ( const char * p, uint len ) [virtual]
Writes len bytes from p into the buffer at the current index, overwriting any characters there and extending the buffer if necessary. Returns the number of bytes actually written.

Returns -1 if a serious error occurred.

See also: readBlock().

Reimplemented from QIODevice.

SEE ALSO
http://www.troll.no/qt/qbuffer.html

COPYRIGHT
Copyright 1992-1997 Troll Tech AS. See the LICENSE file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.