1// qiodevice.sip generated by MetaSIP
2//
3// This file is part of the QtCore Python extension module.
4//
5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
6//
7// This file is part of PyQt5.
8//
9// This file may be used under the terms of the GNU General Public License
10// version 3.0 as published by the Free Software Foundation and appearing in
11// the file LICENSE included in the packaging of this file.  Please review the
12// following information to ensure the GNU General Public License version 3.0
13// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
14//
15// If you do not wish to use this file under the terms of the GPL version 3.0
16// then you may purchase a commercial license.  For more information contact
17// info@riverbankcomputing.com.
18//
19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
22
23class QIODevice : QObject
24{
25%TypeHeaderCode
26#include <qiodevice.h>
27%End
28
29public:
30    enum OpenModeFlag
31    {
32        NotOpen,
33        ReadOnly,
34        WriteOnly,
35        ReadWrite,
36        Append,
37        Truncate,
38        Text,
39        Unbuffered,
40%If (Qt_5_11_0 -)
41        NewOnly,
42%End
43%If (Qt_5_11_0 -)
44        ExistingOnly,
45%End
46    };
47
48    typedef QFlags<QIODevice::OpenModeFlag> OpenMode;
49    QIODevice();
50    explicit QIODevice(QObject *parent /TransferThis/);
51    virtual ~QIODevice();
52    QIODevice::OpenMode openMode() const;
53    void setTextModeEnabled(bool enabled);
54    bool isTextModeEnabled() const;
55    bool isOpen() const;
56    bool isReadable() const;
57    bool isWritable() const;
58    virtual bool isSequential() const;
59    virtual bool open(QIODevice::OpenMode mode) /ReleaseGIL/;
60    virtual void close() /ReleaseGIL/;
61    virtual qint64 pos() const;
62    virtual qint64 size() const;
63    virtual bool seek(qint64 pos) /ReleaseGIL/;
64    virtual bool atEnd() const;
65    virtual bool reset();
66    virtual qint64 bytesAvailable() const;
67    virtual qint64 bytesToWrite() const;
68    SIP_PYOBJECT read(qint64 maxlen) /TypeHint="Py_v3:bytes;str",ReleaseGIL/;
69%MethodCode
70        // Return the data read or None if there was an error.
71        if (a0 < 0)
72        {
73            PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
74            sipIsErr = 1;
75        }
76        else
77        {
78            char *s = new char[a0];
79            qint64 len;
80
81            Py_BEGIN_ALLOW_THREADS
82            len = sipCpp->read(s, a0);
83            Py_END_ALLOW_THREADS
84
85            if (len < 0)
86            {
87                Py_INCREF(Py_None);
88                sipRes = Py_None;
89            }
90            else
91            {
92                sipRes = SIPBytes_FromStringAndSize(s, len);
93
94                if (!sipRes)
95                    sipIsErr = 1;
96            }
97
98            delete[] s;
99        }
100%End
101
102    QByteArray readAll() /ReleaseGIL/;
103    SIP_PYOBJECT readLine(qint64 maxlen=0) /TypeHint="Py_v3:bytes;str",ReleaseGIL/;
104%MethodCode
105        // The two C++ overloads would have the same Python signature so we get most of
106        // the combined functionality by treating an argument of 0 (the default) as
107        // meaning return a QByteArray of any length.  Otherwise it is treated as a
108        // maximum buffer size and a Python string is returned.
109        if (a0 < 0)
110        {
111            PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
112            sipIsErr = 1;
113        }
114        else if (a0 == 0)
115        {
116            QByteArray *ba;
117
118            Py_BEGIN_ALLOW_THREADS
119            ba = new QByteArray(sipCpp->readLine(a0));
120            Py_END_ALLOW_THREADS
121
122            sipRes = sipBuildResult(&sipIsErr, "N", ba, sipType_QByteArray, 0);
123        }
124        else
125        {
126            char *s = new char[a0];
127            qint64 len;
128
129            Py_BEGIN_ALLOW_THREADS
130            len = sipCpp->readLine(s, a0);
131            Py_END_ALLOW_THREADS
132
133            if (len < 0)
134            {
135                Py_INCREF(Py_None);
136                sipRes = Py_None;
137            }
138            else
139            {
140                sipRes = SIPBytes_FromStringAndSize(s, len);
141
142                if (!sipRes)
143                    sipIsErr = 1;
144            }
145
146            delete[] s;
147        }
148%End
149
150    virtual bool canReadLine() const;
151    QByteArray peek(qint64 maxlen) /ReleaseGIL/;
152    qint64 write(const QByteArray &data) /ReleaseGIL/;
153    virtual bool waitForReadyRead(int msecs) /ReleaseGIL/;
154    virtual bool waitForBytesWritten(int msecs) /ReleaseGIL/;
155    void ungetChar(char c);
156    bool putChar(char c);
157    bool getChar(char *c /Encoding="None",Out/);
158    QString errorString() const;
159
160signals:
161    void readyRead();
162    void bytesWritten(qint64 bytes);
163    void aboutToClose();
164    void readChannelFinished();
165
166protected:
167    virtual SIP_PYOBJECT readData(qint64 maxlen) = 0 /TypeHint="Py_v3:bytes;str",ReleaseGIL/ [qint64 (char *data, qint64 maxlen)];
168%MethodCode
169        // Return the data read or None if there was an error.
170        if (a0 < 0)
171        {
172            PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
173            sipIsErr = 1;
174        }
175        else
176        {
177            char *s = new char[a0];
178            qint64 len;
179
180            Py_BEGIN_ALLOW_THREADS
181        #if defined(SIP_PROTECTED_IS_PUBLIC)
182            len = sipCpp->readData(s, a0);
183        #else
184            len = sipCpp->sipProtect_readData(s, a0);
185        #endif
186            Py_END_ALLOW_THREADS
187
188            if (len < 0)
189            {
190                Py_INCREF(Py_None);
191                sipRes = Py_None;
192            }
193            else
194            {
195                sipRes = SIPBytes_FromStringAndSize(s, len);
196
197                if (!sipRes)
198                    sipIsErr = 1;
199            }
200
201            delete[] s;
202        }
203%End
204
205%VirtualCatcherCode
206        PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "n", a1);
207
208        if (result != NULL)
209        {
210            PyObject *buf;
211
212            sipParseResult(&sipIsErr, sipMethod, result, "O", &buf);
213
214            if (buf == Py_None)
215                sipRes = -1L;
216            else if (!SIPBytes_Check(buf))
217            {
218                sipBadCatcherResult(sipMethod);
219                sipIsErr = 1;
220            }
221            else
222            {
223                memcpy(a0, SIPBytes_AsString(buf), SIPBytes_Size(buf));
224                sipRes = SIPBytes_Size(buf);
225            }
226
227            Py_DECREF(buf);
228            Py_DECREF(result);
229        }
230%End
231
232    virtual SIP_PYOBJECT readLineData(qint64 maxlen) /TypeHint="Py_v3:bytes;str",ReleaseGIL/ [qint64 (char *data, qint64 maxlen)];
233%MethodCode
234        // Return the data read or None if there was an error.
235        if (a0 < 0)
236        {
237            PyErr_SetString(PyExc_ValueError, "maximum length of data to be read cannot be negative");
238            sipIsErr = 1;
239        }
240        else
241        {
242            char *s = new char[a0];
243            qint64 len;
244
245            Py_BEGIN_ALLOW_THREADS
246        #if defined(SIP_PROTECTED_IS_PUBLIC)
247            len = sipSelfWasArg ? sipCpp->QIODevice::readLineData(s, a0) : sipCpp->readLineData(s, a0);
248        #else
249            len = sipCpp->sipProtectVirt_readLineData(sipSelfWasArg, s, a0);
250        #endif
251            Py_END_ALLOW_THREADS
252
253            if (len < 0)
254            {
255                Py_INCREF(Py_None);
256                sipRes = Py_None;
257            }
258            else
259            {
260                sipRes = SIPBytes_FromStringAndSize(s, len);
261
262                if (!sipRes)
263                    sipIsErr = 1;
264            }
265
266            delete[] s;
267        }
268%End
269
270%VirtualCatcherCode
271        PyObject *result = sipCallMethod(&sipIsErr, sipMethod, "n", a1);
272
273        if (result != NULL)
274        {
275            PyObject *buf;
276
277            sipParseResult(&sipIsErr, sipMethod, result, "O", &buf);
278
279            if (buf == Py_None)
280                sipRes = -1L;
281            else if (!SIPBytes_Check(buf))
282            {
283                sipBadCatcherResult(sipMethod);
284                sipIsErr = 1;
285            }
286            else
287            {
288                memcpy(a0, SIPBytes_AsString(buf), SIPBytes_Size(buf));
289                sipRes = SIPBytes_Size(buf);
290            }
291
292            Py_DECREF(buf);
293            Py_DECREF(result);
294        }
295%End
296
297    virtual qint64 writeData(const char *data /Array/, qint64 len /ArraySize/) = 0;
298    void setOpenMode(QIODevice::OpenMode openMode);
299    void setErrorString(const QString &errorString);
300
301public:
302%If (Qt_5_7_0 -)
303    int readChannelCount() const;
304%End
305%If (Qt_5_7_0 -)
306    int writeChannelCount() const;
307%End
308%If (Qt_5_7_0 -)
309    int currentReadChannel() const;
310%End
311%If (Qt_5_7_0 -)
312    void setCurrentReadChannel(int channel);
313%End
314%If (Qt_5_7_0 -)
315    int currentWriteChannel() const;
316%End
317%If (Qt_5_7_0 -)
318    void setCurrentWriteChannel(int channel);
319%End
320%If (Qt_5_7_0 -)
321    void startTransaction();
322%End
323%If (Qt_5_7_0 -)
324    void commitTransaction();
325%End
326%If (Qt_5_7_0 -)
327    void rollbackTransaction();
328%End
329%If (Qt_5_7_0 -)
330    bool isTransactionStarted() const;
331%End
332
333signals:
334%If (Qt_5_7_0 -)
335    void channelReadyRead(int channel);
336%End
337%If (Qt_5_7_0 -)
338    void channelBytesWritten(int channel, qint64 bytes);
339%End
340
341public:
342%If (Qt_5_10_0 -)
343    qint64 skip(qint64 maxSize);
344%End
345};
346
347QFlags<QIODevice::OpenModeFlag> operator|(QIODevice::OpenModeFlag f1, QFlags<QIODevice::OpenModeFlag> f2);
348