- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qiodevice.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtCore module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QIODEVICE_H
    00043 #define QIODEVICE_H
    00044
    00045 #ifndef QT_NO_QOBJECT
    00046 #include <QtCore/qobject.h>
    00047 #else
    00048 #include <QtCore/qobjectdefs.h>
    00049 #include <QtCore/qscopedpointer.h>
    00050 #endif
    00051 #include <QtCore/qstring.h>
    00052
    00053 #ifdef open
    00054 #error qiodevice.h must be included before any header file that defines open
    00055 #endif
    00056
    00057 QT_BEGIN_HEADER
    00058
    00059 QT_BEGIN_NAMESPACE
    00060
    00061 QT_MODULE(Core)
    00062
    00063 class QByteArray;
    00064 class QIODevicePrivate;
    00065
    00066 class Q_CORE_EXPORT QIODevice
    00067 #ifndef QT_NO_QOBJECT
    00068     : public QObject
    00069 #endif
    00070 {
    00071 #ifndef QT_NO_QOBJECT
    00072     Q_OBJECT
    00073 #endif
    00074 public:
    00075     enum OpenModeFlag {
    00076         NotOpen = 0x0000,
    00077         ReadOnly = 0x0001,
    00078         WriteOnly = 0x0002,
    00079         ReadWrite = ReadOnly | WriteOnly,
    00080         Append = 0x0004,
    00081         Truncate = 0x0008,
    00082         Text = 0x0010,
    00083         Unbuffered = 0x0020
    00084     };
    00085     Q_DECLARE_FLAGS(OpenMode, OpenModeFlag)
    00086
    00087     QIODevice();
    00088 #ifndef QT_NO_QOBJECT
    00089     explicit QIODevice(QObject *parent);
    00090 #endif
    00091     virtual ~QIODevice();
    00092
    00093     OpenMode openMode() const;
    00094
    00095     void setTextModeEnabled(bool enabled);
    00096     bool isTextModeEnabled() const;
    00097
    00098     bool isOpen() const;
    00099     bool isReadable() const;
    00100     bool isWritable() const;
    00101     virtual bool isSequential() const;
    00102
    00103     virtual bool open(OpenMode mode);
    00104     virtual void close();
    00105
    00106     // ### Qt 5: pos() and seek() should not be virtual, and
    00107     // ### seek() should call a virtual seekData() function.
    00108     virtual qint64 pos() const;
    00109     virtual qint64 size() const;
    00110     virtual bool seek(qint64 pos);
    00111     virtual bool atEnd() const;
    00112     virtual bool reset();
    00113
    00114     virtual qint64 bytesAvailable() const;
    00115     virtual qint64 bytesToWrite() const;
    00116
    00117     qint64 read(char *data, qint64 maxlen);
    00118     QByteArray read(qint64 maxlen);
    00119     QByteArray readAll();
    00120     qint64 readLine(char *data, qint64 maxlen);
    00121     QByteArray readLine(qint64 maxlen = 0);
    00122     virtual bool canReadLine() const;
    00123
    00124     qint64 write(const char *data, qint64 len);
    00125     qint64 write(const char *data);
    00126     inline qint64 write(const QByteArray &data)
    00127     { return write(data.constData(), data.size()); }
    00128
    00129     qint64 peek(char *data, qint64 maxlen);
    00130     QByteArray peek(qint64 maxlen);
    00131
    00132     virtual bool waitForReadyRead(int msecs);
    00133     virtual bool waitForBytesWritten(int msecs);
    00134
    00135     void ungetChar(char c);
    00136     bool putChar(char c);
    00137     bool getChar(char *c);
    00138
    00139     QString errorString() const;
    00140
    00141 #ifndef QT_NO_QOBJECT
    00142 Q_SIGNALS:
    00143     void readyRead();
    00144     void bytesWritten(qint64 bytes);
    00145     void aboutToClose();
    00146     void readChannelFinished();
    00147 #endif
    00148
    00149 protected:
    00150 #ifdef QT_NO_QOBJECT
    00151     QIODevice(QIODevicePrivate &dd);
    00152 #else
    00153     QIODevice(QIODevicePrivate &dd, QObject *parent = 0);
    00154 #endif
    00155     virtual qint64 readData(char *data, qint64 maxlen) = 0;
    00156     virtual qint64 readLineData(char *data, qint64 maxlen);
    00157     virtual qint64 writeData(const char *data, qint64 len) = 0;
    00158
    00159     void setOpenMode(OpenMode openMode);
    00160
    00161     void setErrorString(const QString &errorString);
    00162
    00163 #ifdef QT_NO_QOBJECT
    00164     QScopedPointer<QIODevicePrivate> d_ptr;
    00165 #endif
    00166
    00167 private:
    00168     Q_DECLARE_PRIVATE(QIODevice)
    00169     Q_DISABLE_COPY(QIODevice)
    00170
    00171 #ifdef QT3_SUPPORT
    00172 public:
    00173     typedef qint64 Offset;
    00174
    00175     inline QT3_SUPPORT int flags() const { return static_cast<int>(openMode()); }
    00176     inline QT3_SUPPORT int mode() const { return static_cast<int>(openMode()); }
    00177     inline QT3_SUPPORT int state() const;
    00178
    00179     inline QT3_SUPPORT bool isDirectAccess() const { return !isSequential(); }
    00180     inline QT3_SUPPORT bool isSequentialAccess() const { return isSequential(); }
    00181     inline QT3_SUPPORT bool isCombinedAccess() const { return false; }
    00182     inline QT3_SUPPORT bool isBuffered() const { return true; }
    00183     inline QT3_SUPPORT bool isRaw() const { return false; }
    00184     inline QT3_SUPPORT bool isSynchronous() const { return true; }
    00185     inline QT3_SUPPORT bool isAsynchronous() const { return false; }
    00186     inline QT3_SUPPORT bool isTranslated() const { return (openMode() & Text) != 0; }
    00187     inline QT3_SUPPORT bool isInactive() const { return !isOpen(); }
    00188
    00189     typedef int Status;
    00190     QT3_SUPPORT Status status() const;
    00191     QT3_SUPPORT void resetStatus();
    00192
    00193     inline QT3_SUPPORT Offset at() const { return pos(); }
    00194     inline QT3_SUPPORT bool at(Offset offset) { return seek(offset); }
    00195
    00196     inline QT3_SUPPORT qint64 readBlock(char *data, quint64 maxlen) { return read(data, maxlen); }
    00197     inline QT3_SUPPORT qint64 writeBlock(const char *data, quint64 len) { return write(data, len); }
    00198     inline QT3_SUPPORT qint64 writeBlock(const QByteArray &data) { return write(data); }
    00199
    00200     inline QT3_SUPPORT int getch() { char c; return getChar(&c) ? int(uchar(c)) : -1; }
    00201     inline QT3_SUPPORT int putch(int c) { return putChar(char(c)) ? int(uchar(c)) : -1; }
    00202     inline QT3_SUPPORT int ungetch(int c) { ungetChar(uchar(c)); return c; }
    00203 #endif
    00204 };
    00205
    00206 Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
    00207
    00208 #ifdef QT3_SUPPORT
    00209 static QT3_SUPPORT_VARIABLE const uint IO_Direct = 0x0100;
    00210 static QT3_SUPPORT_VARIABLE const uint IO_Sequential = 0x0200;
    00211 static QT3_SUPPORT_VARIABLE const uint IO_Combined = 0x0300;
    00212 static QT3_SUPPORT_VARIABLE const uint IO_TypeMask = 0x0300;
    00213
    00214 static QT3_SUPPORT_VARIABLE const uint IO_Raw = 0x0000;
    00215 static QT3_SUPPORT_VARIABLE const uint IO_Async = 0x0000;
    00216
    00217 #define IO_ReadOnly QIODevice::ReadOnly
    00218 #define IO_WriteOnly QIODevice::WriteOnly
    00219 #define IO_ReadWrite QIODevice::ReadWrite
    00220 #define IO_Append QIODevice::Append
    00221 #define IO_Truncate QIODevice::Truncate
    00222 #define IO_Translate QIODevice::Text
    00223 #define IO_ModeMask 0x00ff
    00224
    00225 static QT3_SUPPORT_VARIABLE const uint IO_Open = 0x1000;
    00226 static QT3_SUPPORT_VARIABLE const uint IO_StateMask = 0xf000;
    00227
    00228 static QT3_SUPPORT_VARIABLE const uint IO_Ok = 0;
    00229 static QT3_SUPPORT_VARIABLE const uint IO_ReadError = 1;
    00230 static QT3_SUPPORT_VARIABLE const uint IO_WriteError = 2;
    00231 static QT3_SUPPORT_VARIABLE const uint IO_FatalError = 3;
    00232 static QT3_SUPPORT_VARIABLE const uint IO_ResourceError = 4;
    00233 static QT3_SUPPORT_VARIABLE const uint IO_OpenError = 5;
    00234 static QT3_SUPPORT_VARIABLE const uint IO_ConnectError = 5;
    00235 static QT3_SUPPORT_VARIABLE const uint IO_AbortError = 6;
    00236 static QT3_SUPPORT_VARIABLE const uint IO_TimeOutError = 7;
    00237 static QT3_SUPPORT_VARIABLE const uint IO_UnspecifiedError  = 8;
    00238
    00239 inline QT3_SUPPORT int QIODevice::state() const
    00240 {
    00241     return isOpen() ? 0x1000 : 0;
    00242 }
    00243 #endif
    00244
    00245 #if !defined(QT_NO_DEBUG_STREAM)
    00246 class QDebug;
    00247 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
    00248 #endif
    00249
    00250 QT_END_NAMESPACE
    00251
    00252 QT_END_HEADER
    00253
    00254 #endif // QIODEVICE_H