// qvector.sip generated by MetaSIP on Fri Feb 10 10:37:52 2012 // // This file is part of the QtCore Python extension module. // // Copyright (c) 2011 Riverbank Computing Limited // // This file is part of PyQt. // // This file may be used under the terms of the GNU General Public // License versions 2.0 or 3.0 as published by the Free Software // Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 // included in the packaging of this file. Alternatively you may (at // your option) use any later version of the GNU General Public // License if such license has been publicly approved by Riverbank // Computing Limited (or its successors, if any) and the KDE Free Qt // Foundation. In addition, as a special exception, Riverbank gives you // certain additional rights. These rights are described in the Riverbank // GPL Exception version 1.1, which can be found in the file // GPL_EXCEPTION.txt in this package. // // If you are unsure which license is appropriate for your use, please // contact the sales department at sales@riverbankcomputing.com. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // QVector is implemented as a Python list. template %MappedType QVector /DocType="list-of-TYPE"/ { %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 = sipConvertFromNewType(t, sipType_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 (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) if (!sipCanConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, SIP_NOT_NONE)) return 0; return 1; } QVector *qv = new QVector; for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) { int state; TYPE *t = reinterpret_cast(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); if (*sipIsErr) { sipReleaseType(t, sipType_TYPE, state); delete qv; return 0; } qv->append(*t); sipReleaseType(t, sipType_TYPE, state); } *sipCppPtr = qv; return sipGetState(sipTransferObj); %End }; // QVector is implemented as a Python list of integers. %MappedType QVector /DocType="list-of-int"/ { %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; // Convert to a Python long to make sure it doesn't get interpreted as // a signed value. if ((pobj = PyLong_FromUnsignedLong(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 (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) qv->append(PyLong_AsUnsignedLong(PyList_GET_ITEM(sipPy, i))); *sipCppPtr = qv; return sipGetState(sipTransferObj); %End }; // QVector is implemented as a Python list of floats. %MappedType QVector /DocType="list-of-float"/ { %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 (SIP_SSIZE_T 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 > /DocType="list-of-tuple-of-float-TYPE"/ { %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, "(dN)", p.first, pt, sipType_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 (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i) { PyObject *tup = PyList_GET_ITEM(sipPy, i); if (PyTuple_Size(tup) != 2) return 0; if (!sipCanConvertToType(PyTuple_GET_ITEM(tup, 1), sipType_TYPE, SIP_NOT_NONE)) return 0; } return 1; } QVector > *qv = new QVector >; for (SIP_SSIZE_T 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(sipConvertToType(PyTuple_GET_ITEM(tup, 1), sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); if (*sipIsErr) { sipReleaseType(s, sipType_TYPE, state); delete qv; return 0; } p.second = *s; qv->append(p); sipReleaseType(s, sipType_TYPE, state); } *sipCppPtr = qv; return sipGetState(sipTransferObj); %End };