1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include <NCollection_Sequence.hxx>
27 // NCollection_Sequence<TYPE> is implemented as a Python list.
29 %MappedType NCollection_Sequence<TYPE>
32 #include <NCollection_Sequence.hxx>
39 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
42 // Set the list elements.
43 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
45 TYPE* t = new TYPE( sipCpp->Value( i ) );
48 if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL )
56 PyList_SET_ITEM( l, i - 1, pobj );
65 // Check the type if that is all that is required.
68 if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0)
71 for (SIP_SSIZE_T i = 0; i < len; ++i)
73 PyObject *itm = PySequence_ITEM(sipPy, i);
74 bool ok = (itm && sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE));
85 NCollection_Sequence<TYPE> *aSeq = new NCollection_Sequence<TYPE>;
86 len = PySequence_Size(sipPy);
88 for (SIP_SSIZE_T i = 0; i < len; ++i)
90 PyObject *itm = PySequence_ITEM(sipPy, i);
92 TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
98 sipReleaseType(t, sipType_TYPE, state);
106 sipReleaseType(t, sipType_TYPE, state);
111 return sipGetState(sipTransferObj);
115 // NCollection_Sequence<double> is implemented as a Python list of floats.
116 %MappedType NCollection_Sequence<double>
119 #include <NCollection_Sequence.hxx>
126 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
129 // Set the list elements.
130 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
133 if ( ( pobj = PyFloat_FromDouble( sipCpp->Value( i ) ) ) == NULL )
140 PyList_SET_ITEM( l, i - 1, pobj );
147 // Check the type if that is all that is required.
148 if ( sipIsErr == NULL )
149 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
151 NCollection_Sequence<double> *aSeq = new NCollection_Sequence<double>;
153 SIP_SSIZE_T len = PySequence_Size(sipPy);
154 for ( SIP_SSIZE_T i = 0; i < len; ++i )
156 PyObject *itm = PySequence_ITEM( sipPy, i );
165 aSeq->Append( PyFloat_AsDouble( itm ) );
172 return sipGetState( sipTransferObj );
176 // NCollection_Sequence<int> is implemented as a Python list of integers.
177 %MappedType NCollection_Sequence<int>
180 #include <NCollection_Sequence.hxx>
187 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
190 // Set the list elements.
191 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
194 if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL )
201 PyList_SET_ITEM( l, i - 1, pobj );
208 // Check the type if that is all that is required.
209 if ( sipIsErr == NULL )
210 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
212 NCollection_Sequence<int> *aSeq = new NCollection_Sequence<int>;
214 SIP_SSIZE_T len = PySequence_Size(sipPy);
215 for ( SIP_SSIZE_T i = 0; i < len; ++i )
217 PyObject *itm = PySequence_ITEM( sipPy, i );
226 aSeq->Append( SIPLong_AsLong( itm ) );
233 return sipGetState( sipTransferObj );
237 // NCollection_Sequence<bool> is implemented as a Python list of integers.
238 %MappedType NCollection_Sequence<bool>
241 #include <NCollection_Sequence.hxx>
248 if ( ( l = PyList_New( sipCpp->Length() ) ) == NULL )
251 // Set the list elements.
252 for ( int i = 1, n = sipCpp->Length(); i <= n; ++i )
255 if ( ( pobj = SIPLong_FromLong( sipCpp->Value( i ) ) ) == NULL )
262 PyList_SET_ITEM( l, i - 1, pobj );
269 // Check the type if that is all that is required.
270 if ( sipIsErr == NULL )
271 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
273 NCollection_Sequence<bool> *aSeq = new NCollection_Sequence<bool>;
275 SIP_SSIZE_T len = PySequence_Size(sipPy);
276 for ( SIP_SSIZE_T i = 0; i < len; ++i )
278 PyObject *itm = PySequence_ITEM( sipPy, i );
287 aSeq->Append( SIPLong_AsLong( itm ) != 0 );
294 return sipGetState( sipTransferObj );