Eneboo - Documentación para desarrolladores
Métodos públicos | Atributos protegidos
Referencia de la Clase QBuffer

The QBuffer class is an I/O device that operates on a QByteArray. Más...

#include <qbuffer.h>

Diagrama de herencias de QBuffer
QIODevice QIODevice

Lista de todos los miembros.

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

Descripción detallada

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().

Ver también:
QFile, QDataStream, QTextStream, QByteArray, Shared Classes

Documentación del constructor y destructor

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
Ver también:
setBuffer()
QBuffer::~QBuffer ( )

Destroys the buffer.

QBuffer::QBuffer ( )
QBuffer::QBuffer ( QByteArray  )
QBuffer::~QBuffer ( )

Documentación de las funciones miembro

QIODevice::Offset QBuffer::at ( ) const [inline, virtual]

Reimplementado de QIODevice.

bool QBuffer::at ( Offset  pos) [virtual]

Reimplementado de QIODevice.

Offset QBuffer::at ( ) const [virtual]

Virtual function that returns the current I/O device position.

This is the position of the data read/write head of the I/O device.

Ver también:
size()

Reimplementado de QIODevice.

bool QBuffer::at ( Offset  pos) [virtual]

Virtual function that sets the I/O device position to pos. Returns TRUE if the position was successfully set, i.e. pos is within range and the seek was successful; otherwise returns FALSE.

Ver también:
size()

Reimplementado de QIODevice.

QByteArray QBuffer::buffer ( ) const
QByteArray QBuffer::buffer ( ) const [inline]

Returns this buffer's byte array.

Ver también:
setBuffer()
void QBuffer::close ( void  ) [virtual]

Closes an open buffer.

Ver también:
open()

Implementa QIODevice.

void QBuffer::close ( void  ) [virtual]

Closes the I/O device.

This virtual function must be reimplemented by all subclasses.

Ver también:
open()

Implementa QIODevice.

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]

The flush function does nothing for a QBuffer.

Implementa QIODevice.

int QBuffer::getch ( ) [virtual]

Implementa QIODevice.

int QBuffer::getch ( ) [virtual]

Reads a single byte/character from the I/O device.

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

This virtual function must be reimplemented by all subclasses.

Ver también:
putch(), ungetch()

Implementa QIODevice.

bool QBuffer::open ( int  mode) [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.

Ver también:
close()

Implementa QIODevice.

bool QBuffer::open ( int  m) [virtual]

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.

Ver también:
close(), isOpen()

Implementa QIODevice.

int QBuffer::putch ( int  ch) [virtual]

Writes the character ch into the buffer at the current index position, overwriting any existing character and extending the buffer if necessary.

Returns ch, or -1 if an error occurred.

Ver también:
getch(), ungetch()

Implementa QIODevice.

int QBuffer::putch ( int  ch) [virtual]

Writes the character ch to the I/O device.

Returns ch, or -1 if an error occurred.

This virtual function must be reimplemented by all subclasses.

Ver también:
getch(), ungetch()

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.

Ver también:
writeBlock() isOpen() isReadable()

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.

Ver también:
readBlock(), QTextStream::readLine()

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.

Ver también:
buffer(), open(), close()
bool QBuffer::setBuffer ( QByteArray  )
Offset QBuffer::size ( ) const [virtual]

Virtual function that returns the size of the I/O device.

Ver también:
at()

Implementa QIODevice.

QIODevice::Offset QBuffer::size ( ) const [inline, virtual]

Implementa QIODevice.

int QBuffer::ungetch ( int  ch) [virtual]

Puts the character ch back into the I/O device and decrements the index position if it is not zero.

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

Returns ch, or -1 if an error occurred.

This virtual function must be reimplemented by all subclasses.

Ver también:
getch(), putch()

Implementa QIODevice.

int QBuffer::ungetch ( int  ch) [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.

Ver también:
readBlock()

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.

Ver también:
readBlock()

Implementa QIODevice.


Documentación de los datos miembro

QByteArray QBuffer::a [protected]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'