Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
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.
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.
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().
Returns this buffer's byte array.
See also setBuffer().
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().
Returns -1 if an error occurred.
See also readBlock().
Reimplemented from TQIODevice.
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 Trolltech | Trademarks | TQt 3.3.8
|