// 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 = 0; 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, sipType_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, tobj);
+ PyList_SET_ITEM( l, i - 1, pobj );
}
return l;
return 1;
}
- NCollection_Sequence<TYPE> *ql = new NCollection_Sequence<TYPE>;
+ NCollection_Sequence<TYPE> *aSeq = new NCollection_Sequence<TYPE>;
len = PySequence_Size(sipPy);
for (SIP_SSIZE_T i = 0; i < len; ++i)
{
sipReleaseType(t, sipType_TYPE, state);
- delete ql;
+ delete aSeq;
return 0;
}
- ql->Append(*t);
+ aSeq->Append(*t);
sipReleaseType(t, sipType_TYPE, state);
}
- *sipCppPtr = ql;
+ *sipCppPtr = aSeq;
return sipGetState(sipTransferObj);
%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