The QBuffer class is an I/O device that operates on a QByteArray. More...
#include <qbuffer.h>
Public Member Functions | |
QBuffer () | |
QBuffer (QByteArray) | |
~QBuffer () | |
QByteArray | buffer () const |
bool | setBuffer (QByteArray) |
bool | open (int) |
void | close () |
void | flush () |
uint | size () const |
int | at () const |
bool | at (int) |
int | readBlock (char *p, uint) |
int | writeBlock (const char *p, uint) |
int | readLine (char *p, uint) |
int | getch () |
int | putch (int) |
int | ungetch (int) |
Public Member Functions inherited from QIODevice | |
QIODevice () | |
virtual | ~QIODevice () |
int | flags () const |
int | mode () const |
int | state () const |
bool | isDirectAccess () const |
bool | isSequentialAccess () const |
bool | isCombinedAccess () const |
bool | isBuffered () const |
bool | isRaw () const |
bool | isSynchronous () const |
bool | isAsynchronous () const |
bool | isTranslated () const |
bool | isReadable () const |
bool | isWritable () const |
bool | isReadWrite () const |
bool | isInactive () const |
bool | isOpen () const |
int | status () const |
void | resetStatus () |
virtual bool | atEnd () const |
bool | reset () |
int | writeBlock (const QByteArray &data) |
QByteArray | readAll () |
Protected Attributes | |
QByteArray | a |
Protected Attributes inherited from QIODevice | |
int | ioIndex |
Private Member Functions | |
QBuffer (const QBuffer &) | |
QBuffer & | operator= (const QBuffer &) |
Private Attributes | |
uint | a_len |
uint | a_inc |
Additional Inherited Members | |
Protected Member Functions inherited from QIODevice | |
void | setFlags (int f) |
void | setType (int) |
void | setMode (int) |
void | setState (int) |
void | setStatus (int) |
The QBuffer class is an I/O device that operates on a QByteArray.
QBuffer allows reading and writing a memory buffer. It is normally used together with a QTextStream or a QDataStream. QBuffer has an associated QByteArray which holds the buffer data. The size() of the buffer is automatically adjusted as data is written.
The constructor QBuffer(QByteArray)
creates a QBuffer with an existing byte array. The byte array can also be set with setBuffer(). Writing to the QBuffer will modify the original byte array, since QByteArray 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().
The common way to use QBuffer is through QDataStream or QTextStream which have constructors that take a QBuffer parameter. For convenience, there are also QDataStream and QTextStream constructors that take a QByteArray parameter. These constructors create and open an internal QBuffer.
Note that QTextStream can also operate on a QString (a Unicode string); a QBuffer cannot.
You can also use QBuffer directly through the standard QIODevice functions readBlock(), writeBlock() readLine(), at(), getch(), putch() and ungetch().
QBuffer::QBuffer | ( | ) |
QBuffer::QBuffer | ( | QByteArray | 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.
Definition at line 114 of file qbuffer.cpp.
QBuffer::~QBuffer | ( | ) |
|
private |
|
inlinevirtual |
|
virtual |
|
inline |
|
virtual |
Closes an open buffer.
Implements QIODevice.
Definition at line 217 of file qbuffer.cpp.
|
virtual |
The flush function does nothing for a QBuffer.
Implements QIODevice.
Definition at line 231 of file qbuffer.cpp.
|
virtual |
|
virtual |
Opens the buffer in the mode m. Returns TRUE if successful, otherwise FALSE. The buffer must be opened before use.
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. Implements QIODevice.
Definition at line 187 of file qbuffer.cpp.
|
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.
Implements QIODevice.
Definition at line 417 of file qbuffer.cpp.
|
virtual |
|
virtual |
bool QBuffer::setBuffer | ( | QByteArray | buf | ) |
Replaces the buffer's contents with buf.
This may not be done when 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 QByteArray is an explicitly shared class.
Definition at line 145 of file qbuffer.cpp.
|
inlinevirtual |
|
virtual |
|
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.
Implements QIODevice.
Definition at line 312 of file qbuffer.cpp.
|
protected |