From: adv Date: Fri, 24 Jan 2014 09:47:43 +0000 (+0000) Subject: Sequence for doubles has been specialized. X-Git-Tag: BR_hydro_v_1_0~47 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c700eb7ef1659251f04602a8fc0591a53466767;p=modules%2Fhydro.git Sequence for doubles has been specialized. --- diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index ce920138..32006e70 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -151,6 +151,9 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2600.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2600.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2400.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence2400.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) diff --git a/src/HYDROPy/CAS/NCollection_Sequence.sip b/src/HYDROPy/CAS/NCollection_Sequence.sip index dc4f30d9..37106f2a 100644 --- a/src/HYDROPy/CAS/NCollection_Sequence.sip +++ b/src/HYDROPy/CAS/NCollection_Sequence.sip @@ -112,6 +112,67 @@ template %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, 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 {