1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.core.iodevice;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.bytearray;
19 import qt.core.flags;
20 import qt.core.global;
21 import qt.core.object;
22 import qt.core.string;
23 import qt.helpers;
24 
25 /+ #ifndef QT_NO_QOBJECT
26 #else
27 #endif
28 #ifdef open
29 #error qiodevice.h must be included before any header file that defines open
30 #endif
31 
32 
33 
34 class QByteArray; +/
35 extern(C++, class) struct QIODevicePrivate;
36 
37 class /+ Q_CORE_EXPORT +/ QIODevice
38 /+ #ifndef QT_NO_QOBJECT +/
39     : QObject
40 /+ #endif +/
41 {
42 /+ #ifndef QT_NO_QOBJECT +/
43     mixin(Q_OBJECT);
44 /+ #endif +/
45 public:
46     enum OpenModeFlag {
47         NotOpen = 0x0000,
48         ReadOnly = 0x0001,
49         WriteOnly = 0x0002,
50         ReadWrite = OpenModeFlag.ReadOnly | OpenModeFlag.WriteOnly,
51         Append = 0x0004,
52         Truncate = 0x0008,
53         Text = 0x0010,
54         Unbuffered = 0x0020,
55         NewOnly = 0x0040,
56         ExistingOnly = 0x0080
57     }
58     /+ Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) +/
59 alias OpenMode = QFlags!(OpenModeFlag);
60     this();
61 /+ #ifndef QT_NO_QOBJECT +/
62     /+ explicit +/this(QObject parent);
63 /+ #endif +/
64     /+ virtual +/~this();
65 
66     final OpenMode openMode() const;
67 
68     final void setTextModeEnabled(bool enabled);
69     final bool isTextModeEnabled() const;
70 
71     final bool isOpen() const;
72     final bool isReadable() const;
73     final bool isWritable() const;
74     /+ virtual +/ bool isSequential() const;
75 
76     final int readChannelCount() const;
77     final int writeChannelCount() const;
78     final int currentReadChannel() const;
79     final void setCurrentReadChannel(int channel);
80     final int currentWriteChannel() const;
81     final void setCurrentWriteChannel(int channel);
82 
83     /+ virtual +/ bool open(OpenMode mode);
84     /+ virtual +/ void close();
85 
86     // ### Qt 6: pos() and seek() should not be virtual, and
87     // ### seek() should call a virtual seekData() function.
88     /+ virtual +/ qint64 pos() const;
89     /+ virtual +/ qint64 size() const;
90     /+ virtual +/ bool seek(qint64 pos);
91     /+ virtual +/ bool atEnd() const;
92     /+ virtual +/ bool reset();
93 
94     /+ virtual +/ qint64 bytesAvailable() const;
95     /+ virtual +/ qint64 bytesToWrite() const;
96 
97     final qint64 read(char* data, qint64 maxlen);
98     final QByteArray read(qint64 maxlen);
99     final QByteArray readAll();
100     final qint64 readLine(char* data, qint64 maxlen);
101     final QByteArray readLine(qint64 maxlen = 0);
102     /+ virtual +/ bool canReadLine() const;
103 
104     final void startTransaction();
105     final void commitTransaction();
106     final void rollbackTransaction();
107     final bool isTransactionStarted() const;
108 
109     final qint64 write(const(char)* data, qint64 len);
110     final qint64 write(const(char)* data);
111     pragma(inline, true) final qint64 write(ref const(QByteArray) data)
112     { return write(data.constData(), data.size()); }
113 
114     final qint64 peek(char* data, qint64 maxlen);
115     final QByteArray peek(qint64 maxlen);
116     final qint64 skip(qint64 maxSize);
117 
118     /+ virtual +/ bool waitForReadyRead(int msecs);
119     /+ virtual +/ bool waitForBytesWritten(int msecs);
120 
121     final void ungetChar(char c);
122     final bool putChar(char c);
123     final bool getChar(char* c);
124 
125     final QString errorString() const;
126 
127 /+ #ifndef QT_NO_QOBJECT +/
128 /+ Q_SIGNALS +/public:
129     @QSignal final void readyRead();
130     @QSignal final void channelReadyRead(int channel);
131     @QSignal final void bytesWritten(qint64 bytes);
132     @QSignal final void channelBytesWritten(int channel, qint64 bytes);
133     @QSignal final void aboutToClose();
134     @QSignal final void readChannelFinished();
135 /+ #endif +/
136 
137 protected:
138 /+ #ifdef QT_NO_QOBJECT
139     QIODevice(QIODevicePrivate &dd);
140 #else +/
141     this(ref QIODevicePrivate dd, QObject parent = null);
142 /+ #endif +/
143     /+ virtual +/ abstract qint64 readData(char* data, qint64 maxlen);
144     /+ virtual +/ qint64 readLineData(char* data, qint64 maxlen);
145     /+ virtual +/ abstract qint64 writeData(const(char)* data, qint64 len);
146 
147     final void setOpenMode(OpenMode openMode);
148 
149     final void setErrorString(ref const(QString) errorString);
150 
151 /+ #ifdef QT_NO_QOBJECT
152     QScopedPointer<QIODevicePrivate> d_ptr;
153 #endif +/
154 
155 private:
156     /+ Q_DECLARE_PRIVATE(QIODevice) +/
157     /+ Q_DISABLE_COPY(QIODevice) +/
158 }
159 /+pragma(inline, true) QFlags!(QIODevice.OpenMode.enum_type) operator |(QIODevice.OpenMode.enum_type f1, QIODevice.OpenMode.enum_type f2)/+noexcept+/{return QFlags!(QIODevice.OpenMode.enum_type)(f1)|f2;}+/
160 /+pragma(inline, true) QFlags!(QIODevice.OpenMode.enum_type) operator |(QIODevice.OpenMode.enum_type f1, QFlags!(QIODevice.OpenMode.enum_type) f2)/+noexcept+/{return f2|f1;}+/
161 /+pragma(inline, true) QIncompatibleFlag operator |(QIODevice.OpenMode.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
162 
163 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
164 #if !defined(QT_NO_DEBUG_STREAM)
165 class QDebug;
166 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
167 #endif +/
168