1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <NCollection_Sequence.hxx>
23 // NCollection_Sequence<TYPE> is implemented as a Python list.
25 %MappedType NCollection_Sequence<TYPE>
28 #include <NCollection_Sequence.hxx>
35 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
38 // Set the list elements.
39 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
41 TYPE* t = new TYPE( sipCpp->Value( i ) );
44 if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL )
52 PyList_SET_ITEM( l, i - 1, pobj );
61 // Check the type if that is all that is required.
64 if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0)
67 for (SIP_SSIZE_T i = 0; i < len; ++i)
69 PyObject *itm = PySequence_ITEM(sipPy, i);
70 bool ok = (itm && sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE));
81 NCollection_Sequence<TYPE> *aSeq = new NCollection_Sequence<TYPE>;
82 len = PySequence_Size(sipPy);
84 for (SIP_SSIZE_T i = 0; i < len; ++i)
86 PyObject *itm = PySequence_ITEM(sipPy, i);
88 TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
94 sipReleaseType(t, sipType_TYPE, state);
102 sipReleaseType(t, sipType_TYPE, state);
107 return sipGetState(sipTransferObj);
111 // NCollection_Sequence<double> is implemented as a Python list of floats.
112 %MappedType NCollection_Sequence<double>
115 #include <NCollection_Sequence.hxx>
122 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
125 // Set the list elements.
126 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
129 if ( ( pobj = PyFloat_FromDouble( sipCpp->Value( i ) ) ) == NULL )
136 PyList_SET_ITEM( l, i - 1, pobj );
143 // Check the type if that is all that is required.
144 if ( sipIsErr == NULL )
145 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
147 NCollection_Sequence<double> *aSeq = new NCollection_Sequence<double>;
149 SIP_SSIZE_T len = PySequence_Size(sipPy);
150 for ( SIP_SSIZE_T i = 0; i < len; ++i )
152 PyObject *itm = PySequence_ITEM( sipPy, i );
161 aSeq->Append( PyFloat_AsDouble( itm ) );
168 return sipGetState( sipTransferObj );
172 // NCollection_Sequence<int> is implemented as a Python list of integers.
173 %MappedType NCollection_Sequence<int>
176 #include <NCollection_Sequence.hxx>
183 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
186 // Set the list elements.
187 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
190 if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL )
197 PyList_SET_ITEM( l, i - 1, pobj );
204 // Check the type if that is all that is required.
205 if ( sipIsErr == NULL )
206 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
208 NCollection_Sequence<int> *aSeq = new NCollection_Sequence<int>;
210 SIP_SSIZE_T len = PySequence_Size(sipPy);
211 for ( SIP_SSIZE_T i = 0; i < len; ++i )
213 PyObject *itm = PySequence_ITEM( sipPy, i );
222 aSeq->Append( SIPLong_AsLong( itm ) );
229 return sipGetState( sipTransferObj );
233 // NCollection_Sequence<bool> is implemented as a Python list of integers.
234 %MappedType NCollection_Sequence<bool>
237 #include <NCollection_Sequence.hxx>
244 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
247 // Set the list elements.
248 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
251 if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL )
258 PyList_SET_ITEM( l, i - 1, pobj );
265 // Check the type if that is all that is required.
266 if ( sipIsErr == NULL )
267 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
269 NCollection_Sequence<bool> *aSeq = new NCollection_Sequence<bool>;
271 SIP_SSIZE_T len = PySequence_Size(sipPy);
272 for ( SIP_SSIZE_T i = 0; i < len; ++i )
274 PyObject *itm = PySequence_ITEM( sipPy, i );
283 aSeq->Append( SIPLong_AsLong( itm ) != 0 );
290 return sipGetState( sipTransferObj );