// qvector.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. // QVector is implemented as a Python list. template %MappedType QVector { %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; } QVector *qv = new QVector; 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 qv; return 0; } qv->append(*t); sipReleaseInstance(t, sipClass_TYPE, state); } *sipCppPtr = qv; return sipGetState(sipTransferObj); %End }; // QVector is implemented as a Python list of integers. %MappedType QVector { %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); QVector *qv = new QVector; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) qv->append(PyInt_AsLong(PyList_GET_ITEM(sipPy, i))); *sipCppPtr = qv; return sipGetState(sipTransferObj); %End }; // QVector is implemented as a Python list of floats. %MappedType QVector { %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); QVector *ql = new QVector; 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 }; // QVector > is implemented as a Python list of 2-element tuples. template %MappedType QVector > { %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 *pt = new TYPE(p.second); PyObject *pobj; if ((pobj = sipBuildResult(NULL, "(dB)", p.first, pt, sipClass_TYPE, sipTransferObj)) == NULL) { Py_DECREF(l); delete pt; 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; } QVector > *qv = new QVector >; for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); int state; TYPE *s; QPair p; p.first = PyFloat_AsDouble(PyTuple_GET_ITEM(tup, 0)); s = reinterpret_cast(sipConvertToInstance(PyTuple_GET_ITEM(tup, 1), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); if (*sipIsErr) { sipReleaseInstance(s, sipClass_TYPE, state); delete qv; return 0; } p.second = *s; qv->append(p); sipReleaseInstance(s, sipClass_TYPE, state); } return sipGetState(sipTransferObj); %End };