Salome HOME
Merge remote-tracking branch 'origin/BR_IMPROVEMENTS' into BR_v14_rc
[modules/hydro.git] / src / HYDROPy / CAS / NCollection_Sequence.sip
index 8c002cd38d0111b0b8c929aa6e6b0ddd76bae503..28b8799bb54b11b530b3016d2955cbf1b8b6713b 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// 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
@@ -36,24 +32,24 @@ template<TYPE>
     // Create the list.
     PyObject *l;
 
-    if ((l = PyList_New(sipCpp->Length())) == NULL)
-        return NULL;
+    if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
+      return NULL;
 
     // Set the list elements.
-    for (int i = 1; i <= sipCpp->Length(); ++i)
+    for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
     {
-        TYPE *t = new TYPE(sipCpp->Value(i));
-        PyObject *tobj;
+      TYPE* t = new TYPE( sipCpp->Value( i ) );
 
-        if ((tobj = sipConvertFromNewType(t, sipFindType("TYPE"), sipTransferObj)) == NULL)
-        {
-            Py_DECREF(l);
-            delete t;
+      PyObject* pobj;
+      if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL )
+      {
+        Py_DECREF( l );
+        delete t;
 
-            return NULL;
-        }
+        return NULL;
+      }
 
-        PyList_SET_ITEM(l, i - 1, tobj);
+      PyList_SET_ITEM( l, i - 1, pobj );
     }
 
     return l;
@@ -71,7 +67,7 @@ template<TYPE>
         for (SIP_SSIZE_T i = 0; i < len; ++i)
         {
             PyObject *itm = PySequence_ITEM(sipPy, i);
-            bool ok = (itm && sipCanConvertToType(itm, sipFindType("TYPE"), SIP_NOT_NONE));
+            bool ok = (itm && sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE));
 
             Py_XDECREF(itm);
 
@@ -89,13 +85,13 @@ template<TYPE>
     {
         PyObject *itm = PySequence_ITEM(sipPy, i);
         int state;
-        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipFindType("TYPE"), sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
+        TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
 
         Py_DECREF(itm);
  
         if (*sipIsErr)
         {
-            sipReleaseType(t, sipFindType("TYPE"), state);
+            sipReleaseType(t, sipType_TYPE, state);
 
             delete aSeq;
             return 0;
@@ -103,7 +99,7 @@ template<TYPE>
 
         aSeq->Append(*t);
 
-        sipReleaseType(t, sipFindType("TYPE"), state);
+        sipReleaseType(t, sipType_TYPE, state);
     }
  
     *sipCppPtr = aSeq;
@@ -112,3 +108,185 @@ template<TYPE>
 %End
 };
 
+// NCollection_Sequence<double> is implemented as a Python list of floats.
+%MappedType NCollection_Sequence<double>
+{
+%TypeHeaderCode
+#include <NCollection_Sequence.hxx>
+%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<double> *aSeq = new NCollection_Sequence<double>;
+
+    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<int> is implemented as a Python list of integers.
+%MappedType NCollection_Sequence<int>
+{
+%TypeHeaderCode
+#include <NCollection_Sequence.hxx>
+%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<int> *aSeq = new NCollection_Sequence<int>;
+
+    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<bool> is implemented as a Python list of integers.
+%MappedType NCollection_Sequence<bool>
+{
+%TypeHeaderCode
+#include <NCollection_Sequence.hxx>
+%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<bool> *aSeq = new NCollection_Sequence<bool>;
+
+    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
+};
\ No newline at end of file