| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the QtCore module of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** No Commercial Usage |
| 11 |
** This file contains pre-release code and may not be distributed. |
| 12 |
** You may use this file in accordance with the terms and conditions |
| 13 |
** contained in the Technology Preview License Agreement accompanying |
| 14 |
** this package. |
| 15 |
** |
| 16 |
** GNU Lesser General Public License Usage |
| 17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
| 18 |
** General Public License version 2.1 as published by the Free Software |
| 19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
| 20 |
** packaging of this file. Please review the following information to |
| 21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
| 22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 23 |
** |
| 24 |
** In addition, as a special exception, Nokia gives you certain additional |
| 25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 27 |
** |
| 28 |
** If you have questions regarding the use of this file, please contact |
| 29 |
** Nokia at qt-info@nokia.com. |
| 30 |
** |
| 31 |
** |
| 32 |
** |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
#ifndef QIODEVICE_H |
| 43 |
#define QIODEVICE_H |
| 44 |
|
| 45 |
#ifndef QT_NO_QOBJECT |
| 46 |
#include <QtCore/qobject.h> |
| 47 |
#else |
| 48 |
#include <QtCore/qobjectdefs.h> |
| 49 |
#endif |
| 50 |
#include <QtCore/qstring.h> |
| 51 |
|
| 52 |
#ifdef open |
| 53 |
#error qiodevice.h must be included before any header file that defines open |
| 54 |
#endif |
| 55 |
|
| 56 |
QT_BEGIN_HEADER |
| 57 |
|
| 58 |
QT_BEGIN_NAMESPACE |
| 59 |
|
| 60 |
QT_MODULE(Core) |
| 61 |
|
| 62 |
class QByteArray; |
| 63 |
class QIODevicePrivate; |
| 64 |
|
| 65 |
class Q_CORE_EXPORT QIODevice |
| 66 |
#ifndef QT_NO_QOBJECT |
| 67 |
: public QObject |
| 68 |
#endif |
| 69 |
{ |
| 70 |
#ifndef QT_NO_QOBJECT |
| 71 |
Q_OBJECT |
| 72 |
#endif |
| 73 |
public: |
| 74 |
enum OpenModeFlag { |
| 75 |
NotOpen = 0x0000, |
| 76 |
ReadOnly = 0x0001, |
| 77 |
WriteOnly = 0x0002, |
| 78 |
ReadWrite = ReadOnly | WriteOnly, |
| 79 |
Append = 0x0004, |
| 80 |
Truncate = 0x0008, |
| 81 |
Text = 0x0010, |
| 82 |
Unbuffered = 0x0020 |
| 83 |
}; |
| 84 |
Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) |
| 85 |
|
| 86 |
QIODevice(); |
| 87 |
#ifndef QT_NO_QOBJECT |
| 88 |
explicit QIODevice(QObject *parent); |
| 89 |
#endif |
| 90 |
virtual ~QIODevice(); |
| 91 |
|
| 92 |
OpenMode openMode() const; |
| 93 |
|
| 94 |
void setTextModeEnabled(bool enabled); |
| 95 |
bool isTextModeEnabled() const; |
| 96 |
|
| 97 |
bool isOpen() const; |
| 98 |
bool isReadable() const; |
| 99 |
bool isWritable() const; |
| 100 |
virtual bool isSequential() const; |
| 101 |
|
| 102 |
virtual bool open(OpenMode mode); |
| 103 |
virtual void close(); |
| 104 |
|
| 105 |
// ### Qt 5: pos() and seek() should not be virtual, and |
| 106 |
// ### seek() should call a virtual seekData() function. |
| 107 |
virtual qint64 pos() const; |
| 108 |
virtual qint64 size() const; |
| 109 |
virtual bool seek(qint64 pos); |
| 110 |
virtual bool atEnd() const; |
| 111 |
virtual bool reset(); |
| 112 |
|
| 113 |
virtual qint64 bytesAvailable() const; |
| 114 |
virtual qint64 bytesToWrite() const; |
| 115 |
|
| 116 |
qint64 read(char *data, qint64 maxlen); |
| 117 |
QByteArray read(qint64 maxlen); |
| 118 |
QByteArray readAll(); |
| 119 |
qint64 readLine(char *data, qint64 maxlen); |
| 120 |
QByteArray readLine(qint64 maxlen = 0); |
| 121 |
virtual bool canReadLine() const; |
| 122 |
|
| 123 |
qint64 write(const char *data, qint64 len); |
| 124 |
qint64 write(const char *data); |
| 125 |
inline qint64 write(const QByteArray &data) |
| 126 |
{ return write(data.constData(), data.size()); } |
| 127 |
|
| 128 |
qint64 peek(char *data, qint64 maxlen); |
| 129 |
QByteArray peek(qint64 maxlen); |
| 130 |
|
| 131 |
virtual bool waitForReadyRead(int msecs); |
| 132 |
virtual bool waitForBytesWritten(int msecs); |
| 133 |
|
| 134 |
void ungetChar(char c); |
| 135 |
bool putChar(char c); |
| 136 |
bool getChar(char *c); |
| 137 |
|
| 138 |
QString errorString() const; |
| 139 |
|
| 140 |
#ifndef QT_NO_QOBJECT |
| 141 |
Q_SIGNALS: |
| 142 |
void readyRead(); |
| 143 |
void bytesWritten(qint64 bytes); |
| 144 |
void aboutToClose(); |
| 145 |
void readChannelFinished(); |
| 146 |
#endif |
| 147 |
|
| 148 |
protected: |
| 149 |
#ifdef QT_NO_QOBJECT |
| 150 |
QIODevice(QIODevicePrivate &dd); |
| 151 |
#else |
| 152 |
QIODevice(QIODevicePrivate &dd, QObject *parent = 0); |
| 153 |
#endif |
| 154 |
virtual qint64 readData(char *data, qint64 maxlen) = 0; |
| 155 |
virtual qint64 readLineData(char *data, qint64 maxlen); |
| 156 |
virtual qint64 writeData(const char *data, qint64 len) = 0; |
| 157 |
|
| 158 |
void setOpenMode(OpenMode openMode); |
| 159 |
|
| 160 |
void setErrorString(const QString &errorString); |
| 161 |
|
| 162 |
#ifdef QT_NO_QOBJECT |
| 163 |
QIODevicePrivate *d_ptr; |
| 164 |
#endif |
| 165 |
|
| 166 |
private: |
| 167 |
Q_DECLARE_PRIVATE(QIODevice) |
| 168 |
Q_DISABLE_COPY(QIODevice) |
| 169 |
|
| 170 |
#ifdef QT3_SUPPORT |
| 171 |
public: |
| 172 |
typedef qint64 Offset; |
| 173 |
|
| 174 |
inline QT3_SUPPORT int flags() const { return static_cast<int>(openMode()); } |
| 175 |
inline QT3_SUPPORT int mode() const { return static_cast<int>(openMode()); } |
| 176 |
inline QT3_SUPPORT int state() const; |
| 177 |
|
| 178 |
inline QT3_SUPPORT bool isDirectAccess() const { return !isSequential(); } |
| 179 |
inline QT3_SUPPORT bool isSequentialAccess() const { return isSequential(); } |
| 180 |
inline QT3_SUPPORT bool isCombinedAccess() const { return false; } |
| 181 |
inline QT3_SUPPORT bool isBuffered() const { return true; } |
| 182 |
inline QT3_SUPPORT bool isRaw() const { return false; } |
| 183 |
inline QT3_SUPPORT bool isSynchronous() const { return true; } |
| 184 |
inline QT3_SUPPORT bool isAsynchronous() const { return false; } |
| 185 |
inline QT3_SUPPORT bool isTranslated() const { return (openMode() & Text) != 0; } |
| 186 |
inline QT3_SUPPORT bool isInactive() const { return !isOpen(); } |
| 187 |
|
| 188 |
typedef int Status; |
| 189 |
QT3_SUPPORT Status status() const; |
| 190 |
QT3_SUPPORT void resetStatus(); |
| 191 |
|
| 192 |
inline QT3_SUPPORT Offset at() const { return pos(); } |
| 193 |
inline QT3_SUPPORT bool at(Offset offset) { return seek(offset); } |
| 194 |
|
| 195 |
inline QT3_SUPPORT qint64 readBlock(char *data, quint64 maxlen) { return read(data, maxlen); } |
| 196 |
inline QT3_SUPPORT qint64 writeBlock(const char *data, quint64 len) { return write(data, len); } |
| 197 |
inline QT3_SUPPORT qint64 writeBlock(const QByteArray &data) { return write(data); } |
| 198 |
|
| 199 |
inline QT3_SUPPORT int getch() { char c; return getChar(&c) ? int(uchar(c)) : -1; } |
| 200 |
inline QT3_SUPPORT int putch(int c) { return putChar(c) ? int(uchar(c)) : -1; } |
| 201 |
inline QT3_SUPPORT int ungetch(int c) { ungetChar(uchar(c)); return c; } |
| 202 |
#endif |
| 203 |
}; |
| 204 |
|
| 205 |
Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode) |
| 206 |
|
| 207 |
#ifdef QT3_SUPPORT |
| 208 |
static QT3_SUPPORT_VARIABLE const uint IO_Direct = 0x0100; |
| 209 |
static QT3_SUPPORT_VARIABLE const uint IO_Sequential = 0x0200; |
| 210 |
static QT3_SUPPORT_VARIABLE const uint IO_Combined = 0x0300; |
| 211 |
static QT3_SUPPORT_VARIABLE const uint IO_TypeMask = 0x0300; |
| 212 |
|
| 213 |
static QT3_SUPPORT_VARIABLE const uint IO_Raw = 0x0000; |
| 214 |
static QT3_SUPPORT_VARIABLE const uint IO_Async = 0x0000; |
| 215 |
|
| 216 |
#define IO_ReadOnly QIODevice::ReadOnly |
| 217 |
#define IO_WriteOnly QIODevice::WriteOnly |
| 218 |
#define IO_ReadWrite QIODevice::ReadWrite |
| 219 |
#define IO_Append QIODevice::Append |
| 220 |
#define IO_Truncate QIODevice::Truncate |
| 221 |
#define IO_Translate QIODevice::Text |
| 222 |
#define IO_ModeMask 0x00ff |
| 223 |
|
| 224 |
static QT3_SUPPORT_VARIABLE const uint IO_Open = 0x1000; |
| 225 |
static QT3_SUPPORT_VARIABLE const uint IO_StateMask = 0xf000; |
| 226 |
|
| 227 |
static QT3_SUPPORT_VARIABLE const uint IO_Ok = 0; |
| 228 |
static QT3_SUPPORT_VARIABLE const uint IO_ReadError = 1; |
| 229 |
static QT3_SUPPORT_VARIABLE const uint IO_WriteError = 2; |
| 230 |
static QT3_SUPPORT_VARIABLE const uint IO_FatalError = 3; |
| 231 |
static QT3_SUPPORT_VARIABLE const uint IO_ResourceError = 4; |
| 232 |
static QT3_SUPPORT_VARIABLE const uint IO_OpenError = 5; |
| 233 |
static QT3_SUPPORT_VARIABLE const uint IO_ConnectError = 5; |
| 234 |
static QT3_SUPPORT_VARIABLE const uint IO_AbortError = 6; |
| 235 |
static QT3_SUPPORT_VARIABLE const uint IO_TimeOutError = 7; |
| 236 |
static QT3_SUPPORT_VARIABLE const uint IO_UnspecifiedError = 8; |
| 237 |
|
| 238 |
inline QT3_SUPPORT int QIODevice::state() const |
| 239 |
{ |
| 240 |
return isOpen() ? 0x1000 : 0; |
| 241 |
} |
| 242 |
#endif |
| 243 |
|
| 244 |
#if !defined(QT_NO_DEBUG_STREAM) |
| 245 |
class QDebug; |
| 246 |
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes); |
| 247 |
#endif |
| 248 |
|
| 249 |
QT_END_NAMESPACE |
| 250 |
|
| 251 |
QT_END_HEADER |
| 252 |
|
| 253 |
#endif // QIODEVICE_H |