// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License. // // This library is distributed 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // %ExportedHeaderCode #include %End // NCollection_Sequence is implemented as a Python list. template %MappedType NCollection_Sequence { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL ) return NULL; // Set the list elements. for ( int i = 1, n = sipCpp->Length(); i <= n; ++i ) { TYPE* t = new TYPE( sipCpp->Value( i ) ); PyObject* pobj; if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL ) { Py_DECREF( l ); delete t; return NULL; } PyList_SET_ITEM( l, i - 1, pobj ); } 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; } NCollection_Sequence *aSeq = new NCollection_Sequence; 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(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); Py_DECREF(itm); if (*sipIsErr) { sipReleaseType(t, sipType_TYPE, state); delete aSeq; return 0; } aSeq->Append(*t); sipReleaseType(t, sipType_TYPE, state); } *sipCppPtr = aSeq; return sipGetState(sipTransferObj); %End }; // NCollection_Sequence is implemented as a Python list of floats. %MappedType NCollection_Sequence { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL ) return NULL; // Set the list elements. for ( int i = 1, n = sipCpp->Length(); i <= n; ++i ) { PyObject *pobj; if ( ( pobj = PyFloat_FromDouble( sipCpp->Value( i ) ) ) == NULL ) { Py_DECREF(l); return NULL; } PyList_SET_ITEM( l, i - 1, pobj ); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if ( sipIsErr == NULL ) return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); NCollection_Sequence *aSeq = new NCollection_Sequence; SIP_SSIZE_T len = PySequence_Size(sipPy); for ( SIP_SSIZE_T i = 0; i < len; ++i ) { PyObject *itm = PySequence_ITEM( sipPy, i ); if ( !itm ) { delete aSeq; *sipIsErr = 1; return 0; } aSeq->Append( PyFloat_AsDouble( itm ) ); Py_DECREF( itm ); } *sipCppPtr = aSeq; return sipGetState( sipTransferObj ); %End }; // NCollection_Sequence is implemented as a Python list of integers. %MappedType NCollection_Sequence { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL ) return NULL; // Set the list elements. for ( int i = 1, n = sipCpp->Length(); i <= n; ++i ) { PyObject *pobj; if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL ) { Py_DECREF(l); return NULL; } PyList_SET_ITEM( l, i - 1, pobj ); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if ( sipIsErr == NULL ) return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); NCollection_Sequence *aSeq = new NCollection_Sequence; SIP_SSIZE_T len = PySequence_Size(sipPy); for ( SIP_SSIZE_T i = 0; i < len; ++i ) { PyObject *itm = PySequence_ITEM( sipPy, i ); if ( !itm ) { delete aSeq; *sipIsErr = 1; return 0; } aSeq->Append( SIPLong_AsLong( itm ) ); Py_DECREF( itm ); } *sipCppPtr = aSeq; return sipGetState( sipTransferObj ); %End }; // NCollection_Sequence is implemented as a Python list of integers. %MappedType NCollection_Sequence { %TypeHeaderCode #include %End %ConvertFromTypeCode // Create the list. PyObject *l; if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL ) return NULL; // Set the list elements. for ( int i = 1, n = sipCpp->Length(); i <= n; ++i ) { PyObject *pobj; if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL ) { Py_DECREF(l); return NULL; } PyList_SET_ITEM( l, i - 1, pobj ); } return l; %End %ConvertToTypeCode // Check the type if that is all that is required. if ( sipIsErr == NULL ) return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 ); NCollection_Sequence *aSeq = new NCollection_Sequence; SIP_SSIZE_T len = PySequence_Size(sipPy); for ( SIP_SSIZE_T i = 0; i < len; ++i ) { PyObject *itm = PySequence_ITEM( sipPy, i ); if ( !itm ) { delete aSeq; *sipIsErr = 1; return 0; } aSeq->Append( SIPLong_AsLong( itm ) != 0 ); Py_DECREF( itm ); } *sipCppPtr = aSeq; return sipGetState( sipTransferObj ); %End };