// qlist.sip generated by MetaSIP on Fri Sep 28 17:07:47 2007 // // This file is part of the QtCore Python extension module. // // Copyright (c) 2007 // Phil Thompson // // This file is part of PyQt. // // This copy of PyQt is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License version 2 as published by // the Free Software Foundation and appearing in the file LICENSE included in the // packaging of this file. // // PyQt is supplied in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more // details. // // You should have received a copy of the GNU General Public License along with // PyQt; see the file LICENSE. If not, write to the Free Software Foundation, // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // QList is implemented as a Python list. template %MappedType QList { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { TYPE *t = new TYPE(sipCpp->at(i)); PyObject *tobj; if ((tobj = sipConvertFromNewInstance(t, sipClass_TYPE, sipTransferObj)) == NULL) { Py_DECREF(l); delete t; 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) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) if (!sipCanConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, SIP_NOT_NONE)) return 0; return 1; } QList *ql = new QList; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { int state; TYPE *t = reinterpret_cast(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); if (*sipIsErr) { sipReleaseInstance(t, sipClass_TYPE, state); delete ql; return 0; } ql->append(*t); sipReleaseInstance(t, sipClass_TYPE, state); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; // QList is implemented as a Python list. template %MappedType QList { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { TYPE *t = sipCpp->at(i); PyObject *tobj; if ((tobj = sipConvertFromInstance(t, sipClass_TYPE, sipTransferObj)) == 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) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) if (!sipCanConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, 0)) return 0; return 1; } QList *ql = new QList; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { TYPE *t = reinterpret_cast(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, 0, 0, sipIsErr)); if (*sipIsErr) { delete ql; return 0; } ql->append(t); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; // QList > is implemented as a Python list of 2-element tuples. template %MappedType QList > { %TypeHeaderCode #include #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { const QPair &p = sipCpp->at(i); TYPE1 *s1 = new TYPE1(p.first); TYPE2 *s2 = new TYPE2(p.second); PyObject *pobj; if ((pobj = sipBuildResult(NULL, "(BB)", s1, sipClass_TYPE1, sipTransferObj, s2, sipClass_TYPE2, sipTransferObj)) == NULL) { Py_DECREF(l); delete s1; delete s2; return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); if (PyTuple_Size(tup) != 2) return 0; if (!sipCanConvertToInstance(PyTuple_GET_ITEM(tup, 0), sipClass_TYPE1, SIP_NOT_NONE)) return 0; if (!sipCanConvertToInstance(PyTuple_GET_ITEM(tup, 1), sipClass_TYPE2, SIP_NOT_NONE)) return 0; } return 1; } QList > *ql = new QList >; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); int state1, state2; TYPE1 *s1 = reinterpret_cast(sipConvertToInstance(PyTuple_GET_ITEM(tup, 0), sipClass_TYPE1, sipTransferObj, SIP_NOT_NONE, &state1, sipIsErr)); TYPE2 *s2 = reinterpret_cast(sipConvertToInstance(PyTuple_GET_ITEM(tup, 1), sipClass_TYPE2, sipTransferObj, SIP_NOT_NONE, &state2, sipIsErr)); if (*sipIsErr) { sipReleaseInstance(s1, sipClass_TYPE1, state1); sipReleaseInstance(s2, sipClass_TYPE2, state2); delete ql; return 0; } ql->append(QPair(*s1, *s2)); sipReleaseInstance(s1, sipClass_TYPE1, state1); sipReleaseInstance(s2, sipClass_TYPE2, state2); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; // QList > is implemented as a Python list of 2-element tuples. %MappedType QList > { %TypeHeaderCode #include #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { const QPair &p = sipCpp->at(i); PyObject *pobj; if ((pobj = Py_BuildValue((char *)"ii", p.first, p.second)) == NULL) { Py_DECREF(l); return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) if (PyTuple_Size(PyList_GET_ITEM(sipPy, i)) != 2) return 0; return 1; } QList > *ql = new QList >; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); int first = PyInt_AsLong(PyTuple_GET_ITEM(tup, 0)); int second = PyInt_AsLong(PyTuple_GET_ITEM(tup, 1)); ql->append(QPair(first, second)); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; %If (Qt_4_3_0 -) // QList > is implemented as a Python list of 2-element tuples. %MappedType QList > { %TypeHeaderCode #include #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { const QPair &p = sipCpp->at(i); PyObject *pobj; if ((pobj = Py_BuildValue((char *)"dd", p.first, p.second)) == NULL) { Py_DECREF(l); return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) if (PyTuple_Size(PyList_GET_ITEM(sipPy, i)) != 2) return 0; return 1; } QList > *ql = new QList >; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); double first = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0)); double second = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 1)); ql->append(QPair(first, second)); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; %End %If (Qt_4_3_0 -) // QList > is implemented as a Python list of 2-element tuples. template %MappedType QList > { %TypeHeaderCode #include #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { const QPair &p = sipCpp->at(i); TYPE *t = new TYPE(p.second); PyObject *pobj; if ((pobj = sipBuildResult(NULL, "(dB)", p.first, t, sipClass_TYPE, sipTransferObj)) == NULL) { Py_DECREF(l); delete t; return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) { if (!PyList_Check(sipPy)) return 0; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); if (PyTuple_Size(tup) != 2) return 0; if (!sipCanConvertToInstance(PyTuple_GET_ITEM(tup, 1), sipClass_TYPE, SIP_NOT_NONE)) return 0; } return 1; } QList > *ql = new QList >; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); double d; int state; d = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0)); TYPE *t = reinterpret_cast(sipConvertToInstance(PyTuple_GET_ITEM(tup, 1), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); if (*sipIsErr) { sipReleaseInstance(t, sipClass_TYPE, state); delete ql; return 0; } ql->append(QPair(d, *t)); sipReleaseInstance(t, sipClass_TYPE, state); } *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; %End // QList is implemented as a Python list of integers. %MappedType QList { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { PyObject *pobj; if ((pobj = PyInt_FromLong(sipCpp->value(i))) == NULL) { Py_DECREF(l); return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) return PyList_Check(sipPy); QList *ql = new QList; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) ql->append(PyInt_AsLong(PyList_GET_ITEM(sipPy, i))); *sipCppPtr = ql; return sipGetState(sipTransferObj); %End }; // QList is implemented as a Python list of floats. %MappedType QList { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ((l = PyList_New(sipCpp->size())) == NULL) return NULL; // Set the list elements. for (int i = 0; i < sipCpp->size(); ++i) { PyObject *pobj; if ((pobj = PyFloat_FromDouble(sipCpp->value(i))) == NULL) { Py_DECREF(l); return NULL; } PyList_SET_ITEM(l, i, pobj); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if (sipIsErr == NULL) return PyList_Check(sipPy); QList *ql = new QList; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) ql->append(PyFloat_AsDouble(PyList_GET_ITEM(sipPy, i))); *sipCppPtr = ql; return sipGetState(sipTransferObj); %End };