Eneboo - Documentación para desarrolladores
|
The QBuffer class is an I/O device that operates on a QByteArray. Más...
#include <qbuffer.h>
Métodos públicos | |
QBuffer () | |
QBuffer (QByteArray) | |
~QBuffer () | |
QByteArray | buffer () const |
bool | setBuffer (QByteArray) |
bool | open (int) |
void | close () |
void | flush () |
Offset | size () const |
Offset | at () const |
bool | at (Offset) |
Q_LONG | readBlock (char *p, Q_ULONG) |
Q_LONG | writeBlock (const char *p, Q_ULONG) |
Q_LONG | writeBlock (const QByteArray &data) |
Q_LONG | readLine (char *p, Q_ULONG) |
int | getch () |
int | putch (int) |
int | ungetch (int) |
QBuffer () | |
QBuffer (QByteArray) | |
~QBuffer () | |
QByteArray | buffer () const |
bool | setBuffer (QByteArray) |
bool | open (int) |
void | close () |
void | flush () |
Offset | size () const |
Offset | at () const |
bool | at (Offset) |
Q_LONG | readBlock (char *p, Q_ULONG) |
Q_LONG | writeBlock (const char *p, Q_ULONG) |
Q_LONG | writeBlock (const QByteArray &data) |
Q_LONG | readLine (char *p, Q_ULONG) |
int | getch () |
int | putch (int) |
int | ungetch (int) |
Atributos protegidos | |
QByteArray | a |
The QBuffer class is an I/O device that operates on a QByteArray.
QBuffer is used to read and write to a memory buffer. It is normally used 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 using an existing byte array. The byte array can also be set with setBuffer(). Writing to the QBuffer will modify the original byte array because 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().
A 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 | ( | ) |
Constructs an empty buffer.
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.
Example:
QCString str = "abc"; QBuffer 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
QBuffer::~QBuffer | ( | ) |
Destroys the buffer.
QBuffer::QBuffer | ( | ) |
QBuffer::QBuffer | ( | QByteArray | ) |
QBuffer::~QBuffer | ( | ) |
QIODevice::Offset QBuffer::at | ( | ) | const [inline, virtual] |
Reimplementado de QIODevice.
Offset QBuffer::at | ( | ) | const [virtual] |
QByteArray QBuffer::buffer | ( | ) | const |
QByteArray QBuffer::buffer | ( | ) | const [inline] |
Returns this buffer's byte array.
void QBuffer::close | ( | void | ) | [virtual] |
void QBuffer::close | ( | void | ) | [virtual] |
void QBuffer::flush | ( | ) | [virtual] |
Flushes an open I/O device.
This virtual function must be reimplemented by all subclasses.
Implementa QIODevice.
void QBuffer::flush | ( | ) | [virtual] |
int QBuffer::getch | ( | ) | [virtual] |
Opens the I/O device using the specified mode. Returns TRUE if the device was successfully opened; otherwise returns FALSE.
The mode parameter mode must be an OR'ed combination of the following flags. Mode flags Meaning IO_Raw
specifies raw (unbuffered) file access. IO_ReadOnly
opens a file in read-only mode. IO_WriteOnly
opens a file in write-only mode. IO_ReadWrite
opens a file in read/write mode. IO_Append
sets the file index to the end of the file. IO_Truncate
truncates the file. IO_Translate
enables carriage returns and linefeed translation for text files under MS-DOS, Windows and Macintosh. On Unix systems this flag has no effect. Use with caution as it will also transform every linefeed written to the file into a CRLF pair. This is likely to corrupt your file if you write write binary data. Cannot be combined with IO_Raw
.
This virtual function must be reimplemented by all subclasses.
Implementa QIODevice.
Opens the buffer in mode m. Returns TRUE if successful; otherwise returns FALSE. The buffer must be opened before use.
The mode parameter m must be a combination of the following flags. IO_ReadOnly
opens the buffer in read-only mode. IO_WriteOnly
opens the buffer in write-only mode. IO_ReadWrite
opens the buffer in read/write mode. IO_Append
sets the buffer index to the end of the buffer. IO_Truncate
truncates the buffer.
Implementa QIODevice.
Q_LONG QBuffer::readBlock | ( | char * | p, |
Q_ULONG | len | ||
) | [virtual] |
Implementa QIODevice.
Q_LONG QBuffer::readBlock | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [virtual] |
Reads at most maxlen bytes from the I/O device into data and returns the number of bytes actually read.
This function should return -1 if a fatal error occurs and should return 0 if there are no bytes to read.
The device must be opened for reading, and data must not be 0.
This virtual function must be reimplemented by all subclasses.
Implementa QIODevice.
Q_LONG QBuffer::readLine | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [virtual] |
Reads a line of text, (or up to maxlen bytes if a newline isn't encountered) plus a terminating '\0' into data. If there is a newline at the end if the line, it is not stripped.
Returns the number of bytes read including the terminating '\0', or -1 if an error occurred.
This virtual function can be reimplemented much more efficiently by the most subclasses.
Reimplementado de QIODevice.
Q_LONG QBuffer::readLine | ( | char * | p, |
Q_ULONG | maxlen | ||
) | [virtual] |
Reimplementado de QIODevice.
bool QBuffer::setBuffer | ( | QByteArray | 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 QByteArray is an explicitly shared class.
bool QBuffer::setBuffer | ( | QByteArray | ) |
Offset QBuffer::size | ( | ) | const [virtual] |
QIODevice::Offset QBuffer::size | ( | ) | const [inline, virtual] |
Implementa QIODevice.
Q_LONG QBuffer::writeBlock | ( | const QByteArray & | data | ) | [inline] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.
This convenience function is the same as calling {writeBlock( data.data(), data.size() )} with data.
Reimplementado de QIODevice.
Q_LONG QBuffer::writeBlock | ( | const char * | data, |
Q_ULONG | len | ||
) | [virtual] |
Writes len bytes from data to the I/O device and returns the number of bytes actually written.
This function should return -1 if a fatal error occurs.
This virtual function must be reimplemented by all subclasses.
Implementa QIODevice.
Q_LONG QBuffer::writeBlock | ( | const QByteArray & | data | ) | [inline] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. This convenience function is the same as calling writeBlock( data.data(), data.size() ).
Reimplementado de QIODevice.
Q_LONG QBuffer::writeBlock | ( | const char * | p, |
Q_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.
Implementa QIODevice.
QByteArray QBuffer::a [protected] |