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

QIOEngine Class Reference

The QIOEngine class provides an abstraction for block reading and writing. More...

#include <QIOEngine>

Inherited by QFileEngine.

Note: All the functions in this class are reentrant.

List of all members.

Public Types

Public Functions

Protected Functions


Detailed Description

The QIOEngine class provides an abstraction for block reading and writing.

The QIOEngine class is used to directly read and write to the backing store for a QIODevice. All read/write operations are based on simple characters, making operations completely platform independent.

I/O devices are opened with the open() function. They can be read using getch(), readLine(), readBlock() and readAll(). For devices that support random access isSequential() returns false and seek() can be used. The position in the file is given by at(), and if the position is at the end atEnd() returns true. Writable devices can be written to using putch() and writeBlock() (and ungetch()). Devices are closed with close() and if an error occurs errorStatus() and errorString() provide error information.


Member Type Documentation

enum QIOEngine::Type

This enum defines the type of device in use:

QIOEngine::FileThe device represents a file.
QIOEngine::ResourceThe device represents a resource.
QIOEngine::SocketThe device represents a socket.
QIOEngine::StringThe device represents a string.

User-defined devices must define types within the following range:

QIOEngine::UserFirst available user-defined device.
QIOEngine::MaxUserLast available user-defined device.

Member Function Documentation

QIOEngine::QIOEngine ()   [protected]

Constructs a QIOEngine.

QIOEngine::~QIOEngine ()   [virtual]

Destroys the QIOEngine.

QIODevice::Offset QIOEngine::at () const   [pure virtual]

Returns the current position of your IO destination.

This virtual function must be reimplemented by all subclasses.

bool QIOEngine::atEnd () const   [virtual]

Returns true if the end of file has been reached; otherwise returns false.

bool QIOEngine::close ()   [pure virtual]

Closes the device. Returns true if the device is closed successfully; otherwise returns false. QIOEngine::errorStatus is set if an error occurs.

This virtual function must be reimplemented by all subclasses.

QIODevice::Status QIOEngine::errorStatus () const   [virtual]

Returns the QIODevice::Status that resulted from the last failed operation. If QIOevice::UnspecifiedError is returned, QIODevice will use its own idea of the error status.

See also QIODeivce::Status and errorString.

QString QIOEngine::errorString () const   [virtual]

Returns the human-readable message appropriate to the current error reported by errorStatus(). If no suitable string is available, a null string is returned.

See also errorStatus() and QString::isNull().

void QIOEngine::flush ()   [pure virtual]

Flushes all pending reads and writes to the device.

This virtual function must be reimplemented by all subclasses.

int QIOEngine::getch ()   [virtual]

Reads and returns a single character from the QIODevice. If the end of the file is reached, EOF is returned.

The base implementation will simply read a single character.

See also readBlock.

bool QIOEngine::isSequential () const   [pure virtual]

Returns true if the engine can be used for sequential read/write access; otherwise returns false.

This virtual function must be reimplemented by all subclasses.

uchar * QIOEngine::map ( QIODevice::Offset offset, Q_LONG number )   [virtual]

Maps the file contents from offset for the given number of bytes, returning a pointer (uchar *) to the contents. If this fails, 0 is returned.

The default implementation falls back to block reading/writing if this function returns 0.

See also unmap.

bool QIOEngine::open ( int flags )   [pure virtual]

Opens the device for access in the way described by the flags given. Returns true if the device is opened; otherwise returns false and sets QIOEngine::errorStatus to an appropriate value.

flags is a selection of the values defined in QIODevice::OpenModes, combined using the OR operator.

This virtual function must be reimplemented by all subclasses.

See also errorStatus, QIODevice::OpenModes, and close.

int QIOEngine::putch ( int character )   [virtual]

Puts a single character into the device, returning the value given if successful; otherwise EOF is returned to indicate failure.

The base implementation will simply write a single character to the device.

See also writeBlock.

QByteArray QIOEngine::readAll ()   [virtual]

Reads all the remaining data from the source, and returns it in a QByteArray. This can be optimized in many subclasses but the base implementation will just read a block at a time.

See also readBlock.

Q_LONG QIOEngine::readBlock ( char * data, Q_LONG maximum )   [pure virtual]

Reads a number of characters from the device into data. At most, the maximum number of characters will be read. If successful, the number of bytes read from the device is returned; otherwise EOF is returned.

This virtual function must be reimplemented by all subclasses.

Q_LONG QIOEngine::readLine ( char * data, Q_LONG maximum )   [virtual]

Reads a single line (ending with \n) from the device into data. At most, the maximum number of bytes will be read. If successful, the number of characters read from the device is returned; otherwise EOF is returned.

Many QIOEngine subclasses can be optimized for this function. The base implementation will simply read a single character at a time.

See also readBlock.

bool QIOEngine::seek ( QIODevice::Offset offset )   [pure virtual]

Sets the current device position to the given offset relative to the beginning of the line. If the engine is a sequential device then offset will be relative to the current position.

This virtual function must be reimplemented by all subclasses.

See also at and isSequential.

QIODevice::Offset QIOEngine::size () const   [pure virtual]

Requests the size of your IO destination.

This virtual function must be reimplemented by all subclasses.

Type QIOEngine::type () const   [pure virtual]

Returns the I/O type. This can be used as simple RTTI information.

This virtual function must be reimplemented by all subclasses.

See also QIOEngine::Type.

int QIOEngine::ungetch ( int character )   [pure virtual]

Places the character back into the stream at the current position, returning the value given if successful; otherwise -1 is returned to indicate failure.

This virtual function must be reimplemented by all subclasses.

void QIOEngine::unmap ( uchar * data )   [virtual]

Unmap previously mapped file data from memory.

See also map.

Q_LONG QIOEngine::writeBlock ( const char * data, Q_LONG maximum )   [pure virtual]

Writes a number of characters from data to the device. At most, the maximum of characters will be written. If successful, the number of characters written is returned; otherwise EOF is returned.

This virtual function must be reimplemented by all subclasses.


Copyright © 2004 Trolltech. Trademarks
Qt 4.0.0-tp1