Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQBuffer Class Reference

The TQBuffer class is an I/O device that operates on a TQByteArray. More...

All the functions in this class are reentrant when TQt is built with thread support.

#include <ntqbuffer.h>

Inherits TQIODevice.

List of all member functions.

Public Members


Detailed Description

The TQBuffer class is an I/O device that operates on a TQByteArray.

TQBuffer is used to read and write to a memory buffer. It is normally used with a TQTextStream or a TQDataStream. TQBuffer has an associated TQByteArray which holds the buffer data. The size() of the buffer is automatically adjusted as data is written.

The constructor TQBuffer(TQByteArray) creates a TQBuffer using an existing byte array. The byte array can also be set with setBuffer(). Writing to the TQBuffer will modify the original byte array because TQByteArray is explicitly shared.

Use open() to open the buffer before use and to set the mode (read-only, write-only, etc.). close() closes the buffer. The buffer must be closed before reopening or calling setBuffer().

A common way to use TQBuffer is through TQDataStream or TQTextStream, which have constructors that take a TQBuffer parameter. For convenience, there are also TQDataStream and TQTextStream constructors that take a TQByteArray parameter. These constructors create and open an internal TQBuffer.

Note that TQTextStream can also operate on a TQString (a Unicode string); a TQBuffer cannot.

You can also use TQBuffer directly through the standard TQIODevice functions readBlock(), writeBlock() readLine(), at(), getch(), putch() and ungetch().

See also TQFile, TQDataStream, TQTextStream, TQByteArray, Shared Classes, Collection Classes, and Input/Output and Networking.


Member Function Documentation

TQBuffer::TQBuffer ()

Constructs an empty buffer.

TQBuffer::TQBuffer ( TQByteArray buf )

Constructs a buffer that operates on buf.

If you open the buffer in write mode (IO_WriteOnly or IO_ReadWrite) and write something into the buffer, buf will be modified.

Example:

    TQCString str = "abc";
    TQBuffer b( str );
    b.open( IO_WriteOnly );
    b.at( 3 ); // position at the 4th character (the terminating \0)
    b.writeBlock( "def", 4 ); // write "def" including the terminating \0
    b.close();
    // Now, str == "abcdef" with a terminating \0
    

See also setBuffer().

TQBuffer::~TQBuffer ()

Destroys the buffer.

TQByteArray TQBuffer::buffer () const

Returns this buffer's byte array.

See also setBuffer().

bool TQBuffer::setBuffer ( TQByteArray buf )

Replaces the buffer's contents with buf and returns TRUE.

Does nothing (and returns FALSE) if isOpen() is TRUE.

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 TQByteArray is an explicitly shared class.

See also buffer(), open(), and close().

TQ_LONG TQBuffer::writeBlock ( const char * p, TQ_ULONG len ) [virtual]

Writes len bytes from p into the buffer at the current index position, overwriting any characters there and extending the buffer if necessary. Returns the number of bytes actually written.

Returns -1 if an error occurred.

See also readBlock().

Reimplemented from TQIODevice.

TQ_LONG TQBuffer::writeBlock ( const TQByteArray & data )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This convenience function is the same as calling writeBlock( data.data(), data.size() ) with data.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8