1// This is the SIP interface definition for the QList based mapped types
2// specific to the QtMultimedia module.
3//
4// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
5//
6// This file is part of PyQt5.
7//
8// This file may be used under the terms of the GNU General Public License
9// version 3.0 as published by the Free Software Foundation and appearing in
10// the file LICENSE included in the packaging of this file.  Please review the
11// following information to ensure the GNU General Public License version 3.0
12// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
13//
14// If you do not wish to use this file under the terms of the GPL version 3.0
15// then you may purchase a commercial license.  For more information contact
16// info@riverbankcomputing.com.
17//
18// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20
21
22%MappedType QList<QVideoFrame::PixelFormat>
23        /TypeHintIn="Iterable[QVideoFrame.PixelFormat]",
24        TypeHintOut="List[QVideoFrame.PixelFormat]", TypeHintValue="[]"/
25{
26%TypeHeaderCode
27#include <qvideoframe.h>
28%End
29
30%ConvertFromTypeCode
31    PyObject *l = PyList_New(sipCpp->size());
32
33    if (!l)
34        return 0;
35
36    for (int i = 0; i < sipCpp->size(); ++i)
37    {
38        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
39                sipType_QVideoFrame_PixelFormat);
40
41        if (!eobj)
42        {
43            Py_DECREF(l);
44
45            return 0;
46        }
47
48        PyList_SetItem(l, i, eobj);
49    }
50
51    return l;
52%End
53
54%ConvertToTypeCode
55    PyObject *iter = PyObject_GetIter(sipPy);
56
57    if (!sipIsErr)
58    {
59        PyErr_Clear();
60        Py_XDECREF(iter);
61
62        return (iter
63#if PY_MAJOR_VERSION < 3
64                && !PyString_Check(sipPy)
65#endif
66                && !PyUnicode_Check(sipPy));
67    }
68
69    if (!iter)
70    {
71        *sipIsErr = 1;
72
73        return 0;
74    }
75
76    QList<QVideoFrame::PixelFormat> *ql = new QList<QVideoFrame::PixelFormat>;
77
78    for (Py_ssize_t i = 0; ; ++i)
79    {
80        PyErr_Clear();
81        PyObject *itm = PyIter_Next(iter);
82
83        if (!itm)
84        {
85            if (PyErr_Occurred())
86            {
87                delete ql;
88                Py_DECREF(iter);
89                *sipIsErr = 1;
90
91                return 0;
92            }
93
94            break;
95        }
96
97        int v = sipConvertToEnum(itm, sipType_QVideoFrame_PixelFormat);
98
99        if (PyErr_Occurred())
100        {
101            PyErr_Format(PyExc_TypeError,
102                    "index %zd has type '%s' but 'QVideoFrame.PixelFormat' is expected",
103                    i, sipPyTypeName(Py_TYPE(itm)));
104
105            Py_DECREF(itm);
106            delete ql;
107            Py_DECREF(iter);
108            *sipIsErr = 1;
109
110            return 0;
111        }
112
113        ql->append(static_cast<QVideoFrame::PixelFormat>(v));
114
115        Py_DECREF(itm);
116    }
117
118    Py_DECREF(iter);
119
120    *sipCppPtr = ql;
121
122    return sipGetState(sipTransferObj);
123%End
124};
125
126
127%MappedType QList<QAudioFormat::Endian>
128        /TypeHintIn="Iterable[QAudioFormat.Endian]",
129        TypeHintOut="List[QAudioFormat.Endian]", TypeHintValue="[]"/
130{
131%TypeHeaderCode
132#include <qaudioformat.h>
133%End
134
135%ConvertFromTypeCode
136    PyObject *l = PyList_New(sipCpp->size());
137
138    if (!l)
139        return 0;
140
141    for (int i = 0; i < sipCpp->size(); ++i)
142    {
143        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
144                sipType_QAudioFormat_Endian);
145
146        if (!eobj)
147        {
148            Py_DECREF(l);
149
150            return 0;
151        }
152
153        PyList_SetItem(l, i, eobj);
154    }
155
156    return l;
157%End
158
159%ConvertToTypeCode
160    PyObject *iter = PyObject_GetIter(sipPy);
161
162    if (!sipIsErr)
163    {
164        PyErr_Clear();
165        Py_XDECREF(iter);
166
167        return (iter
168#if PY_MAJOR_VERSION < 3
169                && !PyString_Check(sipPy)
170#endif
171                && !PyUnicode_Check(sipPy));
172    }
173
174    if (!iter)
175    {
176        *sipIsErr = 1;
177
178        return 0;
179    }
180
181    QList<QAudioFormat::Endian> *ql = new QList<QAudioFormat::Endian>;
182
183    for (Py_ssize_t i = 0; ; ++i)
184    {
185        PyErr_Clear();
186        PyObject *itm = PyIter_Next(iter);
187
188        if (!itm)
189        {
190            if (PyErr_Occurred())
191            {
192                delete ql;
193                Py_DECREF(iter);
194                *sipIsErr = 1;
195
196                return 0;
197            }
198
199            break;
200        }
201
202        int v = sipConvertToEnum(itm, sipType_QAudioFormat_Endian);
203
204        if (PyErr_Occurred())
205        {
206            PyErr_Format(PyExc_TypeError,
207                    "index %zd has type '%s' but 'QAudioFormat.Endian' is expected",
208                    i, sipPyTypeName(Py_TYPE(itm)));
209
210            Py_DECREF(itm);
211            delete ql;
212            Py_DECREF(iter);
213            *sipIsErr = 1;
214
215            return 0;
216        }
217
218        ql->append(static_cast<QAudioFormat::Endian>(v));
219
220        Py_DECREF(itm);
221    }
222
223    Py_DECREF(iter);
224
225    *sipCppPtr = ql;
226
227    return sipGetState(sipTransferObj);
228%End
229};
230
231
232%MappedType QList<QAudioFormat::SampleType>
233        /TypeHintIn="Iterable[QAudioFormat.SampleType]",
234        TypeHintOut="List[QAudioFormat.SampleType]", TypeHintValue="[]"/
235{
236%TypeHeaderCode
237#include <qaudioformat.h>
238%End
239
240%ConvertFromTypeCode
241    PyObject *l = PyList_New(sipCpp->size());
242
243    if (!l)
244        return 0;
245
246    for (int i = 0; i < sipCpp->size(); ++i)
247    {
248        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
249                sipType_QAudioFormat_SampleType);
250
251        if (!eobj)
252        {
253            Py_DECREF(l);
254
255            return 0;
256        }
257
258        PyList_SetItem(l, i, eobj);
259    }
260
261    return l;
262%End
263
264%ConvertToTypeCode
265    PyObject *iter = PyObject_GetIter(sipPy);
266
267    if (!sipIsErr)
268    {
269        PyErr_Clear();
270        Py_XDECREF(iter);
271
272        return (iter
273#if PY_MAJOR_VERSION < 3
274                && !PyString_Check(sipPy)
275#endif
276                && !PyUnicode_Check(sipPy));
277    }
278
279    if (!iter)
280    {
281        *sipIsErr = 1;
282
283        return 0;
284    }
285
286    QList<QAudioFormat::SampleType> *ql = new QList<QAudioFormat::SampleType>;
287
288    for (Py_ssize_t i = 0; ; ++i)
289    {
290        PyErr_Clear();
291        PyObject *itm = PyIter_Next(iter);
292
293        if (!itm)
294        {
295            if (PyErr_Occurred())
296            {
297                delete ql;
298                Py_DECREF(iter);
299                *sipIsErr = 1;
300
301                return 0;
302            }
303
304            break;
305        }
306
307        int v = sipConvertToEnum(itm, sipType_QAudioFormat_SampleType);
308
309        if (PyErr_Occurred())
310        {
311            PyErr_Format(PyExc_TypeError,
312                    "index %zd has type '%s' but 'QAudioFormat.SampleType' is expected",
313                    i, sipPyTypeName(Py_TYPE(itm)));
314
315            Py_DECREF(itm);
316            delete ql;
317            Py_DECREF(iter);
318            *sipIsErr = 1;
319
320            return 0;
321        }
322
323        ql->append(static_cast<QAudioFormat::SampleType>(v));
324
325        Py_DECREF(itm);
326    }
327
328    Py_DECREF(iter);
329
330    *sipCppPtr = ql;
331
332    return sipGetState(sipTransferObj);
333%End
334};
335
336
337%If (Qt_5_6_0 -)
338
339%MappedType QList<QAudio::Role>
340        /TypeHintIn="Iterable[QAudio.Role]",
341        TypeHintOut="List[QAudio.Role]", TypeHintValue="[]"/
342{
343%TypeHeaderCode
344#include <qaudio.h>
345%End
346
347%ConvertFromTypeCode
348    PyObject *l = PyList_New(sipCpp->size());
349
350    if (!l)
351        return 0;
352
353    for (int i = 0; i < sipCpp->size(); ++i)
354    {
355        PyObject *eobj = sipConvertFromEnum(sipCpp->at(i),
356                sipType_QAudio_Role);
357
358        if (!eobj)
359        {
360            Py_DECREF(l);
361
362            return 0;
363        }
364
365        PyList_SetItem(l, i, eobj);
366    }
367
368    return l;
369%End
370
371%ConvertToTypeCode
372    PyObject *iter = PyObject_GetIter(sipPy);
373
374    if (!sipIsErr)
375    {
376        PyErr_Clear();
377        Py_XDECREF(iter);
378
379        return (iter
380#if PY_MAJOR_VERSION < 3
381                && !PyString_Check(sipPy)
382#endif
383                && !PyUnicode_Check(sipPy));
384    }
385
386    if (!iter)
387    {
388        *sipIsErr = 1;
389
390        return 0;
391    }
392
393    QList<QAudio::Role> *ql = new QList<QAudio::Role>;
394
395    for (Py_ssize_t i = 0; ; ++i)
396    {
397        PyErr_Clear();
398        PyObject *itm = PyIter_Next(iter);
399
400        if (!itm)
401        {
402            if (PyErr_Occurred())
403            {
404                delete ql;
405                Py_DECREF(iter);
406                *sipIsErr = 1;
407
408                return 0;
409            }
410
411            break;
412        }
413
414        int v = sipConvertToEnum(itm, sipType_QAudio_Role);
415
416        if (PyErr_Occurred())
417        {
418            PyErr_Format(PyExc_TypeError,
419                    "index %zd has type '%s' but 'QAudio.Role' is expected",
420                    i, sipPyTypeName(Py_TYPE(itm)));
421
422            Py_DECREF(itm);
423            delete ql;
424            Py_DECREF(iter);
425            *sipIsErr = 1;
426
427            return 0;
428        }
429
430        ql->append(static_cast<QAudio::Role>(v));
431
432        Py_DECREF(itm);
433    }
434
435    Py_DECREF(iter);
436
437    *sipCppPtr = ql;
438
439    return sipGetState(sipTransferObj);
440%End
441};
442
443%End
444