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
23 // std::vector<TYPE> is implemented as a Python list.
25 %MappedType std::vector<TYPE>
35 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
38 // Set the list elements.
39 for ( int i = 0, n = sipCpp->size(); i < n; ++i )
41 TYPE* t = new TYPE( (*sipCpp)[i] );
44 if ( ( pobj = sipConvertFromNewType( t, sipType_TYPE, sipTransferObj ) ) == NULL )
52 PyList_SET_ITEM( l, i, 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 std::vector<TYPE> *aSeq = new std::vector<TYPE>;
82 len = PySequence_Size(sipPy);
85 for (SIP_SSIZE_T i = 0; i < len; ++i)
87 PyObject *itm = PySequence_ITEM(sipPy, i);
89 TYPE *t = reinterpret_cast<TYPE *>(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
95 sipReleaseType(t, sipType_TYPE, state);
103 sipReleaseType(t, sipType_TYPE, state);
108 return sipGetState(sipTransferObj);
112 // std::vector<double> is implemented as a Python list of floats.
113 %MappedType std::vector<double>
123 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
126 // Set the list elements.
127 for ( int i = 0, n = sipCpp->size(); i < n; ++i )
130 if ( ( pobj = PyFloat_FromDouble( (*sipCpp)[i] ) ) == NULL )
137 PyList_SET_ITEM( l, i, pobj );
144 // Check the type if that is all that is required.
145 if ( sipIsErr == NULL )
146 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
148 std::vector<double> *aSeq = new std::vector<double>;
150 SIP_SSIZE_T len = PySequence_Size(sipPy);
151 aSeq->reserve( len );
152 for ( SIP_SSIZE_T i = 0; i < len; ++i )
154 PyObject *itm = PySequence_ITEM( sipPy, i );
163 aSeq->push_back( PyFloat_AsDouble( itm ) );
170 return sipGetState( sipTransferObj );
174 // std::vector<int> is implemented as a Python list of integers.
175 %MappedType std::vector<int>
185 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
188 // Set the list elements.
189 for ( int i = 0, n = sipCpp->size(); i < n; ++i )
192 if ( ( pobj = SIPLong_FromLong( (*sipCpp)[i] ) ) == NULL )
199 PyList_SET_ITEM( l, i, pobj );
206 // Check the type if that is all that is required.
207 if ( sipIsErr == NULL )
208 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
210 std::vector<int> *aSeq = new std::vector<int>;
212 SIP_SSIZE_T len = PySequence_Size(sipPy);
213 aSeq->reserve( len );
214 for ( SIP_SSIZE_T i = 0; i < len; ++i )
216 PyObject *itm = PySequence_ITEM( sipPy, i );
225 aSeq->push_back( SIPLong_AsLong( itm ) );
232 return sipGetState( sipTransferObj );
236 // std::vector<bool> is implemented as a Python list of integers.
237 %MappedType std::vector<bool>
247 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
250 // Set the list elements.
251 for ( int i = 0, n = sipCpp->size(); i < n; ++i )
254 if ( ( pobj = SIPLong_FromLong( (*sipCpp)[i] ) ) == NULL )
261 PyList_SET_ITEM( l, i, pobj );
268 // Check the type if that is all that is required.
269 if ( sipIsErr == NULL )
270 return ( PySequence_Check( sipPy) && PySequence_Size( sipPy ) >= 0 );
272 std::vector<bool> *aSeq = new std::vector<bool>;
274 SIP_SSIZE_T len = PySequence_Size(sipPy);
275 aSeq->reserve( len );
276 for ( SIP_SSIZE_T i = 0; i < len; ++i )
278 PyObject *itm = PySequence_ITEM( sipPy, i );
287 aSeq->push_back( SIPLong_AsLong( itm ) != 0 );
294 return sipGetState( sipTransferObj );