forked from mitya57/python-poppler-qt5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.sip
335 lines (257 loc) · 6.5 KB
/
types.sip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Various conversions that are not made by PyQt5 default.
*/
/**
* Convert QSet<Poppler::Document::RenderBackend>
* from any Python sequence and to a Python list.
*/
%MappedType QSet<Poppler::Document::RenderBackend>
{
%TypeHeaderCode
#include <qset.h>
%End
%ConvertFromTypeCode
// Create the list.
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
// Set the list elements.
QSet<Poppler::Document::RenderBackend> set = *sipCpp;
int i = 0;
foreach (Poppler::Document::RenderBackend value, set)
{
PyObject *obj = PyLong_FromLong ((long) value);
if (obj == NULL || PyList_SetItem(l, i, obj) < 0)
{
Py_DECREF(l);
if (obj)
Py_DECREF(obj);
return NULL;
}
Py_DECREF(obj);
i++;
}
return l;
%End
%ConvertToTypeCode
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PySequence_Check(sipPy))
return 0;
return 1;
}
QSet<Poppler::Document::RenderBackend> *qs = new QSet<Poppler::Document::RenderBackend>;
for (int i = 0; i < PySequence_Size(sipPy); ++i)
{
Poppler::Document::RenderBackend t = (Poppler::Document::RenderBackend)PyLong_AsLong(PySequence_ITEM (sipPy, i));
*qs << t;
}
*sipCppPtr = qs;
return sipGetState(sipTransferObj);
%End
};
/**
* Convert QLinkedList<TYPE> from any sequence and to a Python list.
*/
template<TYPE>
%MappedType QLinkedList<TYPE>
{
%TypeHeaderCode
#include <qlinkedlist.h>
%End
%ConvertFromTypeCode
// Create the list.
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
// Set the list elements.
TYPE item;
QLinkedList<TYPE>::iterator i;
int index = 0;
for (i = sipCpp->begin(); i != sipCpp->end(); ++i)
{
TYPE *t = new TYPE(*i);
PyObject *tobj;
if ((tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
return NULL;
}
PyList_SET_ITEM(l, index, tobj);
++index;
}
return l;
%End
%ConvertToTypeCode
SIP_SSIZE_T len;
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0)
return 0;
for (SIP_SSIZE_T i = 0; i < len; ++i)
{
PyObject *itm = PySequence_ITEM(sipPy, i);
bool ok = (itm && sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE));
Py_XDECREF(itm);
if (!ok)
return 0;
}
return 1;
}
QLinkedList<TYPE> *qll = new QLinkedList<TYPE>;
len = PySequence_Size(sipPy);
for (SIP_SSIZE_T i = 0; i < len; ++i)
{
PyObject *itm = PySequence_ITEM(sipPy, i);
int state;
TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
Py_DECREF(itm);
if (*sipIsErr)
{
sipReleaseType(t, sipType_TYPE, state);
delete qll;
return 0;
}
qll->append(*t);
sipReleaseType(t, sipType_TYPE, state);
}
*sipCppPtr = qll;
return sipGetState(sipTransferObj);
%End
};
/**
* Convert QList<QLinkedList<TYPE>>
*/
template <TYPE>
%MappedType QList< QLinkedList<TYPE> >
{
%TypeHeaderCode
#include <qlist.h>
#include <qlinkedlist.h>
%End
%ConvertFromTypeCode
// Create the list.
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
const sipTypeDef* qlinkedlist_type = sipFindType("QLinkedList<TYPE>");
// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QLinkedList<TYPE>* t = new QLinkedList<TYPE>(sipCpp->at(i));
PyObject *tobj;
if ((tobj = sipConvertFromType(t, qlinkedlist_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
return NULL;
}
PyList_SET_ITEM(l, i, tobj);
}
return l;
%End
%ConvertToTypeCode
const sipTypeDef* qlinkedlist_type = sipFindType("QLinkedList<TYPE>");
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PySequence_Check(sipPy))
return 0;
for (int i = 0; i < PySequence_Size(sipPy); ++i)
if (!sipCanConvertToType(PySequence_ITEM(sipPy, i), qlinkedlist_type, SIP_NOT_NONE))
return 0;
return 1;
}
QList< QLinkedList<TYPE> > *ql = new QList< QLinkedList<TYPE> >;
for (int i = 0; i < PySequence_Size(sipPy); ++i)
{
int state;
QLinkedList<TYPE> * t = reinterpret_cast< QLinkedList<TYPE> * >(sipConvertToType(PySequence_ITEM(sipPy, i), qlinkedlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
if (*sipIsErr)
{
sipReleaseType(t, qlinkedlist_type, state);
delete ql;
return 0;
}
ql->append(*t);
sipReleaseType(t, qlinkedlist_type, state);
}
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End
};
/**
* Convert time_t to and from long integer
*/
%MappedType time_t
{
%TypeHeaderCode
#include <time.h>
%End
%ConvertFromTypeCode
PyObject* pTime;
pTime = PyLong_FromLong(*sipCpp);
return pTime;
%End
%ConvertToTypeCode
if (sipIsErr == NULL)
{
return PyLong_Check(sipPy);
}
if (sipPy == Py_None)
{
*sipCppPtr = new time_t();
return 1;
}
if (PyLong_Check(sipPy))
{
*sipCppPtr = new time_t(PyLong_AsLong(sipPy));
return 1;
}
return 0;
%End
};
/**
* Convert to and from QList<qint64>
*/
%MappedType QList<qint64>
{
%TypeHeaderCode
#include <QList>
%End
%ConvertFromTypeCode
// Create the list.
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
// Set the list elements.
QList<qint64>::iterator it = sipCpp->begin();
for (int i = 0; it != sipCpp->end(); ++it, ++i)
{
PyObject *tobj;
if ((tobj = PyLong_FromLongLong(*it)) == NULL)
{
Py_DECREF(l);
return NULL;
}
PyList_SET_ITEM(l, i, tobj);
}
return l;
%End
%ConvertToTypeCode
// Check the type if that is all that is required.
if (sipIsErr == NULL)
return PyList_Check(sipPy);
QList<qint64> *qlist = new QList<qint64>;
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
*qlist << PyLong_AsLongLong(PyList_GET_ITEM(sipPy, i));
}
*sipCppPtr = qlist;
return sipGetState(sipTransferObj);
%End
};
/* kate: indent-width 4; space-indent on; hl c++; indent-mode cstyle; */