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
33 #include <numpy/arrayobject.h>
37 #if defined(SWIGPYTHON)
38 %typemap(in) std::string * , const std::string * , const std::string * const {
39 /* typemap in for string * , const string * , const string * const */
40 /* Check if is a list */
41 if (PyList_Check($input)) {
42 int size = PyList_Size($input);
44 $1 = new string[size];
45 for (i = 0; i < size; i++) {
46 PyObject *o = PyList_GetItem($input,i);
47 if (PyString_Check(o))
48 $1[i] = string(PyString_AsString(PyList_GetItem($input,i)));
50 PyErr_SetString(PyExc_TypeError,"list must contain strings");
58 PyErr_SetString(PyExc_TypeError,"not a list");
62 %typemap(freearg) string * , const string * , const string * const {
67 #if defined(SWIGPYTHON)
68 %typemap(in) double * , const double * , const double * const
70 /* typemap in for double * , const double * , const double * const */
71 /* Check if $input is a list */
73 if (!ok && PyList_Check($input))
75 int size = PyList_Size($input);
77 $1 = (double *) malloc(size*sizeof(double));
78 for (i = 0; i < size; i++) {
79 PyObject *o = PyList_GetItem($input,i);
81 $1[i] = PyFloat_AsDouble(PyList_GetItem($input,i));
83 PyErr_SetString(PyExc_TypeError,"list must contain floats");
91 /* Check if $input is a ndarray */
92 if ( !ok && PyArray_Check($input))
94 if ( !PyArray_ISFLOAT ($input))
96 PyErr_SetString(PyExc_TypeError,"ndarray must contain floats");
100 npy_intp size = PyArray_SIZE($input);
101 double* workPtr = $1 = (double *) malloc(size*sizeof(double));
103 if ( PyArray_ISCONTIGUOUS( $input )) // the data is in a single C-style contiguous segment
105 const char * dataPtr = PyArray_BYTES( $input );
106 int step = PyArray_ITEMSIZE( $input );
109 *workPtr++ = *((const double*) dataPtr);
115 PyArrayIterObject *iter = (PyArrayIterObject *)PyArray_IterNew($input);
118 PyErr_SetString(PyExc_RuntimeError,"can't iterate over a ndarray");
122 while (iter->index < iter->size)
124 *workPtr++ = *((const double*) iter->dataptr);
125 PyArray_ITER_NEXT(iter);
133 PyErr_SetString(PyExc_TypeError,"not a list nor a ndarray");
139 #if defined(SWIGPYTHON)
140 %typemap(in) int * , const int * , const int * const
142 /* typemap in for int * , const int * , const int * const */
143 /* Check if is a list */
145 if (PyList_Check($input))
147 int size = PyList_Size($input);
149 $1 = (int *) malloc(size*sizeof(int));
150 for (i = 0; i < size; i++)
152 PyObject *o = PyList_GetItem($input,i);
154 $1[i] = PyInt_AsLong(PyList_GetItem($input,i));
156 PyErr_SetString(PyExc_TypeError,"list must contain integers");
164 /* Check if $input is a ndarray */
165 if ( !ok && PyArray_Check($input))
167 if ( !PyArray_ISINTEGER ($input))
169 PyErr_SetString(PyExc_TypeError,"ndarray must contain integers");
173 npy_intp size = PyArray_SIZE($input);
174 int* workPtr = $1 = (int *) malloc(size*sizeof(int));
176 if ( PyArray_ISCONTIGUOUS( $input )) // the data is in a single C-style contiguous segment
178 const char * dataPtr = PyArray_BYTES( $input );
179 int step = PyArray_ITEMSIZE( $input );
182 *workPtr++ = *((const int*) dataPtr);
188 PyArrayIterObject *iter = (PyArrayIterObject *)PyArray_IterNew($input);
191 PyErr_SetString(PyExc_RuntimeError,"can't iterate over a ndarray");
195 while (iter->index < iter->size)
197 *workPtr++ = *((const int*) iter->dataptr);
198 PyArray_ITER_NEXT(iter);
206 PyErr_SetString(PyExc_TypeError,"not a list nor a ndarray");
212 #if defined(SWIGPYTHON)
213 %typemap(in) medGeometryElement * , const medGeometryElement * , const medGeometryElement * const
215 /* typemap in for medGeometryElement * , const medGeometryElement * , const medGeometryElement * const */
216 /* Check if is a list */
217 if (PyList_Check($input)) {
218 int size = PyList_Size($input);
220 $1 = (medGeometryElement *) malloc(size*sizeof(medGeometryElement));
221 for (i = 0; i < size; i++) {
222 PyObject *o = PyList_GetItem($input,i);
224 $1[i] = (medGeometryElement) PyInt_AsLong(PyList_GetItem($input,i));
226 PyErr_SetString(PyExc_TypeError,"list must contain integers");
234 PyErr_SetString(PyExc_TypeError,"not a list");
240 #if defined(SWIGPYTHON)
241 %typemap(out) list<string> {
243 list<string>::iterator iL;
245 $result = PyList_New($1->size());
246 for (i=0, iL=$1->begin(); iL!=$1->end(); i++, iL++)
247 PyList_SetItem($result,i,PyString_FromString((*iL).c_str()));
251 %typemap(freearg) int * , const int * , const int * const {
252 /* free the memory allocated in the typemap in for int * , const int * , const int * const */
256 %typemap(freearg) double * , const double * , const double * const {
257 /* free the memory allocated in the typemap in for double * , const double * , const double * const */
261 %typemap(freearg) medGeometryElement * , const medGeometryElement * , const medGeometryElement * const {
262 /* free the memory allocated in the typemap in for medGeometryElement * , const medGeometryElement * , const medGeometryElement * const */