1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelAutoPtr.hxx"
24 #include <numpy/arrayobject.h>
26 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
27 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
28 // if no more alive the "standart" DataArray deallocator is called.
29 void numarrdeal(void *pt, void *wron)
31 void **wronc=(void **)wron;
32 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
33 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
37 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
38 objC->flags|=NPY_OWNDATA;
39 Py_XDECREF(weakRefOnOwner);
44 typedef void (*MyDeallocator)(void *,void *);
45 MyDeallocator deall=(MyDeallocator)wronc[1];
47 Py_XDECREF(weakRefOnOwner);
52 template<class MCData>
53 struct PyCallBackDataArraySt {
58 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
59 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
63 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
65 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
67 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
68 return (PyObject *)self;
71 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
73 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
74 return (PyObject *)self;
77 static void callbackmcdataarray_dealloc(PyObject *self)
79 Py_TYPE(self)->tp_free(self);
82 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
83 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
84 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
88 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
95 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
96 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
97 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
101 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
109 PyTypeObject PyCallBackDataArrayInt_RefType = {
110 PyVarObject_HEAD_INIT(&PyType_Type, 0)
111 "callbackmcdataarrayint",
112 sizeof(PyCallBackDataArrayInt),
114 callbackmcdataarray_dealloc, /*tp_dealloc*/
121 0, /*tp_as_sequence*/
124 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
129 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
133 0, /*tp_richcompare*/
134 0, /*tp_weaklistoffset*/
145 callbackmcdataarray___init__, /*tp_init*/
146 PyType_GenericAlloc, /*tp_alloc*/
147 callbackmcdataarrayint___new__, /*tp_new*/
148 PyObject_GC_Del, /*tp_free*/
151 PyTypeObject PyCallBackDataArrayDouble_RefType = {
152 PyVarObject_HEAD_INIT(&PyType_Type, 0)
153 "callbackmcdataarraydouble",
154 sizeof(PyCallBackDataArrayDouble),
156 callbackmcdataarray_dealloc, /*tp_dealloc*/
163 0, /*tp_as_sequence*/
166 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
171 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
175 0, /*tp_richcompare*/
176 0, /*tp_weaklistoffset*/
187 callbackmcdataarray___init__, /*tp_init*/
188 PyType_GenericAlloc, /*tp_alloc*/
189 callbackmcdataarraydouble___new__, /*tp_new*/
190 PyObject_GC_Del, /*tp_free*/
193 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
194 // in input when an another DataArray is already client of this.
195 template<class MCData>
196 void numarrdeal2(void *pt, void *obj)
198 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
199 void **obj1=(void **)obj;
200 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
201 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
203 Py_XDECREF(weakRefOnOwner);
208 template<class MCData, class T>
209 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
211 int ndim=PyArray_NDIM(elt0);
212 if(ndim!=1 && ndim!=2)
213 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
214 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
216 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
217 throw INTERP_KERNEL::Exception(oss.str().c_str());
219 npy_intp sz0=PyArray_DIM(elt0,0);
220 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
222 int itemSize=PyArray_ITEMSIZE(elt0);
223 if(itemSize!=sizeof(T))
225 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
226 throw INTERP_KERNEL::Exception(oss.str().c_str());
228 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
229 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
231 if(itemSize!=PyArray_STRIDE(elt0,1))
232 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
233 const char *data=PyArray_BYTES(elt0);
234 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
235 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
237 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
238 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
239 int mask=NPY_OWNDATA; mask=~mask;
241 PyObject *deepestObj=elt0;
242 PyObject *base=elt0C->base;
243 if(base) deepestObj=base;
246 if(PyArray_Check(base))
248 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
249 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
252 if(base) deepestObj=base;
257 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
260 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
262 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
263 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
264 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
265 mma.setParameterForDeallocator(objs);
266 mma.setSpecificDeallocator(numarrdeal2<MCData>);
267 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
271 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
272 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
273 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
274 mma.setParameterForDeallocator(objs);
275 mma.setSpecificDeallocator(numarrdeal);
278 else if(PyArray_ISBEHAVED_RO(elt0))
279 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
284 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
287 PyErr_SetString(PyExc_ValueError,
288 "Cannot set the NumPy array 'base' "
289 "dependency to NULL after initialization");
293 * Allow the base to be set only once. Once the object which
294 * owns the data is set, it doesn't make sense to change it.
296 if (PyArray_BASE(arr) != NULL) {
298 PyErr_SetString(PyExc_ValueError,
299 "Cannot set the NumPy array 'base' "
300 "dependency more than once");
305 * Don't allow infinite chains of views, always set the base
306 * to the first owner of the data.
307 * That is, either the first object which isn't an array,
308 * or the first object which owns its own data.
311 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
312 PyArrayObject *obj_arr = (PyArrayObject *)obj;
316 /* If this array owns its own data, stop collapsing */
317 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
321 tmp = PyArray_BASE(obj_arr);
322 /* If there's no base, stop collapsing */
326 /* Stop the collapse new base when the would not be of the same
327 * type (i.e. different subclass).
329 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
339 /* Disallow circular references */
340 if ((PyObject *)arr == obj) {
342 PyErr_SetString(PyExc_ValueError,
343 "Cannot create a circular NumPy array 'base' dependency");
352 template<class MCData, class T>
353 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
355 if(!self->isAllocated())
357 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
358 throw INTERP_KERNEL::Exception(oss.str().c_str());
360 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
361 int nbComp=self->getNumberOfComponents();
364 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
365 throw INTERP_KERNEL::Exception(oss.str().c_str());
367 int nbDims=nbComp==1?1:2;
369 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
370 const T *bg=self->getConstPointer();
371 PyObject *ret=PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg));
372 if(mem.isDeallocatorCalled())
374 if(mem.getDeallocator()!=numarrdeal)
375 {// case for the first call of toNumPyArray
376 PyObject *ref=PyWeakref_NewRef(ret,NULL);
377 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) mem.getDeallocator();
378 mem.setParameterForDeallocator(objs);
379 mem.setSpecificDeallocator(numarrdeal);
383 {// case for the second and other call of toNumPyArray
384 void **objs=(void **)mem.getParameterForDeallocator();
385 PyObject *weakRefOnOwner=(PyObject *)objs[0];
386 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
388 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
390 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
393 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
394 Py_XDECREF(weakRefOnOwner);
395 PyObject *ref=PyWeakref_NewRef(ret,NULL);
403 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
404 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
406 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
408 int nbRows((int)m.size());
409 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
410 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
411 indPtr->alloc(nbRows+1,1);
412 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
414 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
416 sz2+=(int)(*it0).size();
419 indices->alloc(sz2,1); data->alloc(sz2,1);
420 int *indices_ptr(indices->getPointer());
421 double *data_ptr(data->getPointer());
422 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
423 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
425 *indices_ptr=(*it1).first;
426 *data_ptr=(*it1).second;
428 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
430 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
431 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
432 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
433 PyObject *tmp1(PyString_FromString("shape"));
434 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
435 PyObject* pdict=PyDict_New();
436 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
437 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
438 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
439 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
440 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
446 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
454 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
455 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
456 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
457 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
459 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
463 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
471 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
472 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
473 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
474 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
475 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
476 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
477 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
478 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
480 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
484 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
486 PyObject *ret=PyList_New(size);
487 for(int i=0;i<size;i++)
488 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
492 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
495 PyObject *ret=PyList_New(size);
496 for(int i=0;i<size;i++)
497 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
501 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
504 PyObject *ret=PyList_New(size);
505 std::set<int>::const_iterator it=v.begin();
506 for(int i=0;i<size;i++,it++)
507 PyList_SetItem(ret,i,PyInt_FromLong(*it));
511 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
513 PyObject *ret=PyList_New(nbOfTuples);
514 for(int i=0;i<nbOfTuples;i++)
516 PyObject *t=PyTuple_New(nbOfComp);
517 for(int j=0;j<nbOfComp;j++)
518 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
519 PyList_SetItem(ret,i,t);
524 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
526 if(PyList_Check(pyLi))
528 *size=PyList_Size(pyLi);
529 int *tmp=new int[*size];
530 for(int i=0;i<*size;i++)
532 PyObject *o=PyList_GetItem(pyLi,i);
535 int val=(int)PyInt_AS_LONG(o);
541 throw INTERP_KERNEL::Exception("list must contain integers only");
546 else if(PyTuple_Check(pyLi))
548 *size=PyTuple_Size(pyLi);
549 int *tmp=new int[*size];
550 for(int i=0;i<*size;i++)
552 PyObject *o=PyTuple_GetItem(pyLi,i);
555 int val=(int)PyInt_AS_LONG(o);
561 throw INTERP_KERNEL::Exception("tuple must contain integers only");
568 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
572 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
574 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
575 if(PyList_Check(pyLi))
577 int size=PyList_Size(pyLi);
579 for(int i=0;i<size;i++)
581 PyObject *o=PyList_GetItem(pyLi,i);
584 int sz2=PyTuple_Size(o);
586 throw INTERP_KERNEL::Exception(msg);
587 PyObject *o_0=PyTuple_GetItem(o,0);
588 if(!PyInt_Check(o_0))
589 throw INTERP_KERNEL::Exception(msg);
590 PyObject *o_1=PyTuple_GetItem(o,1);
591 if(!PyInt_Check(o_1))
592 throw INTERP_KERNEL::Exception(msg);
593 arr[i].first=(int)PyInt_AS_LONG(o_0);
594 arr[i].second=(int)PyInt_AS_LONG(o_1);
597 throw INTERP_KERNEL::Exception(msg);
600 else if(PyTuple_Check(pyLi))
602 int size=PyTuple_Size(pyLi);
604 for(int i=0;i<size;i++)
606 PyObject *o=PyTuple_GetItem(pyLi,i);
609 int sz2=PyTuple_Size(o);
611 throw INTERP_KERNEL::Exception(msg);
612 PyObject *o_0=PyTuple_GetItem(o,0);
613 if(!PyInt_Check(o_0))
614 throw INTERP_KERNEL::Exception(msg);
615 PyObject *o_1=PyTuple_GetItem(o,1);
616 if(!PyInt_Check(o_1))
617 throw INTERP_KERNEL::Exception(msg);
618 arr[i].first=(int)PyInt_AS_LONG(o_0);
619 arr[i].second=(int)PyInt_AS_LONG(o_1);
622 throw INTERP_KERNEL::Exception(msg);
626 throw INTERP_KERNEL::Exception(msg);
629 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
631 if(PyList_Check(pyLi))
633 int size=PyList_Size(pyLi);
635 for(int i=0;i<size;i++)
637 PyObject *o=PyList_GetItem(pyLi,i);
640 int val=(int)PyInt_AS_LONG(o);
644 throw INTERP_KERNEL::Exception("list must contain integers only");
647 else if(PyTuple_Check(pyLi))
649 int size=PyTuple_Size(pyLi);
651 for(int i=0;i<size;i++)
653 PyObject *o=PyTuple_GetItem(pyLi,i);
656 int val=(int)PyInt_AS_LONG(o);
660 throw INTERP_KERNEL::Exception("tuple must contain integers only");
665 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
669 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
672 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
674 if(PyList_Check(pyLi))
676 int size=PyList_Size(pyLi);
677 for(int i=0;i<size;i++)
679 PyObject *o=PyList_GetItem(pyLi,i);
682 int val=(int)PyInt_AS_LONG(o);
687 std::vector<int> arr2;
688 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
689 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
691 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
692 throw INTERP_KERNEL::Exception(oss.str().c_str());
694 arr.insert(arr.end(),arr2.begin(),arr2.end());
698 else if(PyTuple_Check(pyLi))
700 int size=PyTuple_Size(pyLi);
701 for(int i=0;i<size;i++)
703 PyObject *o=PyTuple_GetItem(pyLi,i);
706 int val=(int)PyInt_AS_LONG(o);
711 std::vector<int> arr2;
712 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
713 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
715 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
716 throw INTERP_KERNEL::Exception(oss.str().c_str());
718 arr.insert(arr.end(),arr2.begin(),arr2.end());
723 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
726 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
730 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
731 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
733 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
734 oss << " whereas nb of components expected is " << nbOfComp << " !";
735 throw INTERP_KERNEL::Exception(oss.str().c_str());
742 if((nbOfTuples!=size1 || nbOfComp!=size2))
744 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
746 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
747 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
748 throw INTERP_KERNEL::Exception(oss.str().c_str());
754 if(nbOfTuples==size1)
758 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
759 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
760 throw INTERP_KERNEL::Exception(oss.str().c_str());
766 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
768 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
769 if(PyInt_Check(pyLi))
771 long val=PyInt_AS_LONG(pyLi);
776 throw INTERP_KERNEL::Exception(MSG);
779 else if(PyList_Check(pyLi))
781 int size=PyList_Size(pyLi);
783 for(int i=0;i<size;i++)
785 PyObject *o=PyList_GetItem(pyLi,i);
787 fillArrayWithPyListInt3(o,tmp1,ret);
795 throw INTERP_KERNEL::Exception(MSG);
798 else if(PyTuple_Check(pyLi))
800 int size=PyTuple_Size(pyLi);
802 for(int i=0;i<size;i++)
804 PyObject *o=PyTuple_GetItem(pyLi,i);
806 fillArrayWithPyListInt3(o,tmp1,ret);
814 throw INTERP_KERNEL::Exception(MSG);
818 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
821 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
823 std::vector<int> ret;
824 int size1=-1,size2=-1;
825 if(PyList_Check(pyLi))
827 size1=PyList_Size(pyLi);
828 for(int i=0;i<size1;i++)
830 PyObject *o=PyList_GetItem(pyLi,i);
831 fillArrayWithPyListInt3(o,size2,ret);
836 else if(PyTuple_Check(pyLi))
838 size1=PyTuple_Size(pyLi);
839 for(int i=0;i<size1;i++)
841 PyObject *o=PyTuple_GetItem(pyLi,i);
842 fillArrayWithPyListInt3(o,size2,ret);
848 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
850 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
854 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
856 if(PyList_Check(pyLi))
858 Py_ssize_t sz=PyList_Size(pyLi);
860 for(int i=0;i<sz;i++)
862 PyObject *o=PyList_GetItem(pyLi,i);
863 if(PyString_Check(o))
864 vec[i]=PyString_AsString(o);
870 else if(PyTuple_Check(pyLi))
872 Py_ssize_t sz=PyTuple_Size(pyLi);
874 for(int i=0;i<sz;i++)
876 PyObject *o=PyTuple_GetItem(pyLi,i);
877 if(PyString_Check(o))
878 vec[i]=PyString_AsString(o);
888 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
890 PyObject *ret=PyList_New(size);
891 for(int i=0;i<size;i++)
892 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
896 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
899 PyObject *ret=PyList_New(size);
900 for(int i=0;i<size;i++)
901 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
905 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
907 PyObject *ret=PyList_New(nbOfTuples);
908 for(int i=0;i<nbOfTuples;i++)
910 PyObject *t=PyTuple_New(nbOfComp);
911 for(int j=0;j<nbOfComp;j++)
912 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
913 PyList_SetItem(ret,i,t);
918 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
920 PyObject *ret=PyList_New(nbOfTuples);
921 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
922 for(int i=0;i<nbOfTuples;i++)
924 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
925 PyList_SetItem(ret,i,PyString_FromString(tmp));
930 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
932 if(PyList_Check(pyLi))
934 *size=PyList_Size(pyLi);
935 double *tmp=(double *)malloc((*size)*sizeof(double));
936 for(int i=0;i<*size;i++)
938 PyObject *o=PyList_GetItem(pyLi,i);
941 double val=PyFloat_AS_DOUBLE(o);
944 else if(PyInt_Check(o))
946 long val0=PyInt_AS_LONG(o);
953 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
958 else if(PyTuple_Check(pyLi))
960 *size=PyTuple_Size(pyLi);
961 double *tmp=(double *)malloc((*size)*sizeof(double));
962 for(int i=0;i<*size;i++)
964 PyObject *o=PyTuple_GetItem(pyLi,i);
967 double val=PyFloat_AS_DOUBLE(o);
970 else if(PyInt_Check(o))
972 long val0=PyInt_AS_LONG(o);
979 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
985 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
988 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
990 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
991 if(PyFloat_Check(pyLi))
997 throw INTERP_KERNEL::Exception(MSG);
998 double val=PyFloat_AS_DOUBLE(pyLi);
1001 else if(PyInt_Check(pyLi))
1003 long val0=PyInt_AS_LONG(pyLi);
1009 throw INTERP_KERNEL::Exception(MSG);
1012 else if(PyList_Check(pyLi))
1014 int size=PyList_Size(pyLi);
1016 for(int i=0;i<size;i++)
1018 PyObject *o=PyList_GetItem(pyLi,i);
1020 fillArrayWithPyListDbl3(o,tmp1,ret);
1028 throw INTERP_KERNEL::Exception(MSG);
1031 else if(PyTuple_Check(pyLi))
1033 int size=PyTuple_Size(pyLi);
1035 for(int i=0;i<size;i++)
1037 PyObject *o=PyTuple_GetItem(pyLi,i);
1039 fillArrayWithPyListDbl3(o,tmp1,ret);
1047 throw INTERP_KERNEL::Exception(MSG);
1051 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1054 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1056 std::vector<double> ret;
1057 int size1=-1,size2=-1;
1058 if(PyList_Check(pyLi))
1060 size1=PyList_Size(pyLi);
1061 for(int i=0;i<size1;i++)
1063 PyObject *o=PyList_GetItem(pyLi,i);
1064 fillArrayWithPyListDbl3(o,size2,ret);
1069 else if(PyTuple_Check(pyLi))
1071 size1=PyTuple_Size(pyLi);
1072 for(int i=0;i<size1;i++)
1074 PyObject *o=PyTuple_GetItem(pyLi,i);
1075 fillArrayWithPyListDbl3(o,size2,ret);
1081 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1083 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1087 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1089 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1092 if(PyList_Check(pyLi))
1094 int size=PyList_Size(pyLi);
1096 for(int i=0;i<size;i++)
1098 PyObject *obj=PyList_GetItem(pyLi,i);
1099 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1100 if(!SWIG_IsOK(status))
1102 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1103 throw INTERP_KERNEL::Exception(oss.str().c_str());
1105 T arg=reinterpret_cast< T >(argp);
1109 else if(PyTuple_Check(pyLi))
1111 int size=PyTuple_Size(pyLi);
1113 for(int i=0;i<size;i++)
1115 PyObject *obj=PyTuple_GetItem(pyLi,i);
1116 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1117 if(!SWIG_IsOK(status))
1119 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1120 throw INTERP_KERNEL::Exception(oss.str().c_str());
1122 T arg=reinterpret_cast< T >(argp);
1126 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1129 T arg=reinterpret_cast< T >(argp);
1133 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1137 * if python int -> cpp int sw=1
1138 * if python list[int] -> cpp vector<int> sw=2
1139 * if python tuple[int] -> cpp vector<int> sw=2
1140 * if python DataArrayInt -> cpp DataArrayInt sw=3
1141 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1143 * switch between (int,vector<int>,DataArrayInt)
1145 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1148 if(PyInt_Check(value))
1150 iTyypp=(int)PyInt_AS_LONG(value);
1154 if(PyTuple_Check(value))
1156 int size=PyTuple_Size(value);
1157 stdvecTyypp.resize(size);
1158 for(int i=0;i<size;i++)
1160 PyObject *o=PyTuple_GetItem(value,i);
1162 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1165 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1166 throw INTERP_KERNEL::Exception(oss.str().c_str());
1172 if(PyList_Check(value))
1174 int size=PyList_Size(value);
1175 stdvecTyypp.resize(size);
1176 for(int i=0;i<size;i++)
1178 PyObject *o=PyList_GetItem(value,i);
1180 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1183 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1184 throw INTERP_KERNEL::Exception(oss.str().c_str());
1191 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1192 if(SWIG_IsOK(status))
1194 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1198 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1199 if(SWIG_IsOK(status))
1201 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1205 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1209 * if python double -> cpp double sw=1
1210 * if python int -> cpp double sw=1
1211 * if python list[double] -> cpp vector<double> sw=2
1212 * if python list[int] -> cpp vector<double> sw=2
1213 * if python tuple[double] -> cpp vector<double> sw=2
1214 * if python tuple[int] -> cpp vector<double> sw=2
1215 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1217 * switch between (int,vector<int>,DataArrayInt)
1219 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1222 if(PyFloat_Check(value))
1224 iTyypp=PyFloat_AS_DOUBLE(value);
1228 if(PyInt_Check(value))
1230 iTyypp=(double)PyInt_AS_LONG(value);
1234 if(PyTuple_Check(value))
1236 int size=PyTuple_Size(value);
1237 stdvecTyypp.resize(size);
1238 for(int i=0;i<size;i++)
1240 PyObject *o=PyTuple_GetItem(value,i);
1241 if(PyFloat_Check(o))
1242 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1243 else if(PyInt_Check(o))
1244 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1247 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1248 throw INTERP_KERNEL::Exception(oss.str().c_str());
1254 if(PyList_Check(value))
1256 int size=PyList_Size(value);
1257 stdvecTyypp.resize(size);
1258 for(int i=0;i<size;i++)
1260 PyObject *o=PyList_GetItem(value,i);
1261 if(PyFloat_Check(o))
1262 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1263 else if(PyInt_Check(o))
1264 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1267 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1268 throw INTERP_KERNEL::Exception(oss.str().c_str());
1275 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1276 if(!SWIG_IsOK(status))
1277 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1278 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1283 * if python double -> cpp double sw=1
1284 * if python int -> cpp double sw=1
1285 * if python list[double] -> cpp vector<double> sw=2
1286 * if python list[int] -> cpp vector<double> sw=2
1287 * if python tuple[double] -> cpp vector<double> sw=2
1288 * if python tuple[int] -> cpp vector<double> sw=2
1289 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1291 * switch between (int,vector<int>,DataArrayInt)
1293 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1296 if(PyFloat_Check(value))
1298 iTyypp=PyFloat_AS_DOUBLE(value);
1302 if(PyInt_Check(value))
1304 iTyypp=(double)PyInt_AS_LONG(value);
1308 if(PyTuple_Check(value))
1310 int size=PyTuple_Size(value);
1311 stdvecTyypp.resize(size);
1312 for(int i=0;i<size;i++)
1314 PyObject *o=PyTuple_GetItem(value,i);
1315 if(PyFloat_Check(o))
1316 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1317 else if(PyInt_Check(o))
1318 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1321 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1322 throw INTERP_KERNEL::Exception(oss.str().c_str());
1328 if(PyList_Check(value))
1330 int size=PyList_Size(value);
1331 stdvecTyypp.resize(size);
1332 for(int i=0;i<size;i++)
1334 PyObject *o=PyList_GetItem(value,i);
1335 if(PyFloat_Check(o))
1336 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1337 else if(PyInt_Check(o))
1338 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1341 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1342 throw INTERP_KERNEL::Exception(oss.str().c_str());
1349 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1350 if(!SWIG_IsOK(status))
1351 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1352 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1357 * if python int -> cpp int sw=1
1358 * if python list[int] -> cpp vector<int> sw=2
1359 * if python tuple[int] -> cpp vector<int> sw=2
1360 * if python slicp -> cpp pair sw=3 (begin,end,step)
1361 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1363 * switch between (int,vector<int>,DataArrayInt)
1365 static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1367 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1369 if(PyInt_Check(value))
1371 iTyypp=(int)PyInt_AS_LONG(value);
1375 if(PyTuple_Check(value))
1377 int size=PyTuple_Size(value);
1378 stdvecTyypp.resize(size);
1379 for(int i=0;i<size;i++)
1381 PyObject *o=PyTuple_GetItem(value,i);
1383 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1386 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1387 throw INTERP_KERNEL::Exception(oss.str().c_str());
1393 if(PyList_Check(value))
1395 int size=PyList_Size(value);
1396 stdvecTyypp.resize(size);
1397 for(int i=0;i<size;i++)
1399 PyObject *o=PyList_GetItem(value,i);
1401 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1404 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1405 throw INTERP_KERNEL::Exception(oss.str().c_str());
1411 if(PySlice_Check(value))
1413 Py_ssize_t strt=2,stp=2,step=2;
1414 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1415 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1416 if(nbelem!=0 || strt!=0 || stp!=0)
1418 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1419 throw INTERP_KERNEL::Exception(oss.str().c_str());
1423 p.second.second=step;
1428 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1429 if(SWIG_IsOK(status))
1431 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1434 std::ostringstream oss; oss << msg << " Instance in null !";
1435 throw INTERP_KERNEL::Exception(oss.str().c_str());
1440 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1441 if(SWIG_IsOK(status))
1443 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1446 std::ostringstream oss; oss << msg << " Instance in null !";
1447 throw INTERP_KERNEL::Exception(oss.str().c_str());
1449 stdvecTyypp.resize(tmp->getNumberOfCompo());
1450 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1454 throw INTERP_KERNEL::Exception(msg);
1458 * if python int -> cpp int sw=1
1459 * if python tuple[int] -> cpp vector<int> sw=2
1460 * if python list[int] -> cpp vector<int> sw=2
1461 * if python slice -> cpp pair sw=3
1462 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1464 static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1467 if(PyInt_Check(value))
1469 iTyypp=(int)PyInt_AS_LONG(value);
1473 if(PyTuple_Check(value))
1475 int size=PyTuple_Size(value);
1476 stdvecTyypp.resize(size);
1477 for(int i=0;i<size;i++)
1479 PyObject *o=PyTuple_GetItem(value,i);
1481 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1484 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1485 throw INTERP_KERNEL::Exception(oss.str().c_str());
1491 if(PyList_Check(value))
1493 int size=PyList_Size(value);
1494 stdvecTyypp.resize(size);
1495 for(int i=0;i<size;i++)
1497 PyObject *o=PyList_GetItem(value,i);
1499 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1502 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1503 throw INTERP_KERNEL::Exception(oss.str().c_str());
1509 if(PySlice_Check(value))
1511 Py_ssize_t strt=2,stp=2,step=2;
1512 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1513 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1514 if(nbelem!=0 || strt!=0 || stp!=0)
1516 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1517 throw INTERP_KERNEL::Exception(oss.str().c_str());
1521 p.second.second=step;
1526 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1527 if(!SWIG_IsOK(status))
1528 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1529 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1534 * if python string with size one -> cpp char sw=1
1535 * if python string with size different from one -> cpp string sw=2
1536 * if python tuple[string] or list[string] -> vector<string> sw=3
1537 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1538 * switch between (int,string,vector<string>,DataArrayChar)
1540 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1542 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1544 if(PyString_Check(value))
1546 const char *pt=PyString_AsString(value);
1547 Py_ssize_t sz=PyString_Size(value);
1561 if(PyTuple_Check(value))
1563 int size=PyTuple_Size(value);
1564 vsType.resize(size);
1565 for(int i=0;i<size;i++)
1567 PyObject *o=PyTuple_GetItem(value,i);
1568 if(PyString_Check(o))
1569 vsType[i]=PyString_AsString(o);
1572 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1573 throw INTERP_KERNEL::Exception(oss.str().c_str());
1579 if(PyList_Check(value))
1581 int size=PyList_Size(value);
1582 vsType.resize(size);
1583 for(int i=0;i<size;i++)
1585 PyObject *o=PyList_GetItem(value,i);
1586 if(PyString_Check(o))
1587 vsType[i]=PyString_AsString(o);
1590 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1591 throw INTERP_KERNEL::Exception(oss.str().c_str());
1598 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1599 if(SWIG_IsOK(status))
1601 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1604 std::ostringstream oss; oss << msg << " Instance in null !";
1605 throw INTERP_KERNEL::Exception(oss.str().c_str());
1610 throw INTERP_KERNEL::Exception(msg);
1614 * if value int -> cpp it sw=1
1615 * if value list[int] -> vt sw=2
1616 * if value tuple[int] -> vt sw=2
1617 * if value slice -> pt sw=3
1618 * if value DataArrayInt -> dt sw=4
1619 * if value tuple [int,int] -> cpp it,ip sw=5
1620 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1621 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1622 * if value tuple [slice,int] -> cpp pt,ip sw=7
1623 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1624 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1625 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1626 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1627 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1628 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1629 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1630 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1631 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1632 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1633 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1634 * if value tuple [int,slice] -> cpp it,pc sw=13
1635 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1636 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1637 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1638 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1640 * switch between (int,vector<int>,DataArrayInt)
1642 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1643 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1644 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1646 if(!PyTuple_Check(value))
1648 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1653 int sz=PyTuple_Size(value);
1655 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1656 PyObject *ob0=PyTuple_GetItem(value,0);
1658 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1659 PyObject *ob1=PyTuple_GetItem(value,1);
1660 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1666 * if value int -> cpp val sw=1
1667 * if value double -> cpp val sw=1
1668 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1669 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1670 * if value list[int,double] -> cpp std::vector<double> sw=4
1671 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1673 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1676 if(PyFloat_Check(value))
1678 val=PyFloat_AS_DOUBLE(value);
1682 if(PyInt_Check(value))
1684 val=(double)PyInt_AS_LONG(value);
1688 if(PyTuple_Check(value))
1690 int size=PyTuple_Size(value);
1692 for(int i=0;i<size;i++)
1694 PyObject *o=PyTuple_GetItem(value,i);
1695 if(PyFloat_Check(o))
1696 f[i]=PyFloat_AS_DOUBLE(o);
1697 else if(PyInt_Check(o))
1698 f[i]=(double)PyInt_AS_LONG(o);
1701 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1702 throw INTERP_KERNEL::Exception(oss.str().c_str());
1708 if(PyList_Check(value))
1710 int size=PyList_Size(value);
1712 for(int i=0;i<size;i++)
1714 PyObject *o=PyList_GetItem(value,i);
1715 if(PyFloat_Check(o))
1716 f[i]=PyFloat_AS_DOUBLE(o);
1717 else if(PyInt_Check(o))
1718 f[i]=(double)PyInt_AS_LONG(o);
1721 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1722 throw INTERP_KERNEL::Exception(oss.str().c_str());
1729 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1730 if(SWIG_IsOK(status))
1732 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1736 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1737 if(SWIG_IsOK(status))
1739 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1743 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1747 * if value int -> cpp val sw=1
1748 * if value double -> cpp val sw=1
1749 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1750 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1751 * if value list[int,double] -> cpp std::vector<double> sw=4
1752 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1754 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1755 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1758 if(PyFloat_Check(value))
1760 val=PyFloat_AS_DOUBLE(value);
1762 if(nbTuplesExpected*nbCompExpected!=1)
1764 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1765 throw INTERP_KERNEL::Exception(oss.str().c_str());
1769 if(PyInt_Check(value))
1771 val=(double)PyInt_AS_LONG(value);
1773 if(nbTuplesExpected*nbCompExpected!=1)
1775 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1776 throw INTERP_KERNEL::Exception(oss.str().c_str());
1780 if(PyTuple_Check(value) || PyList_Check(value))
1784 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1785 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1790 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1793 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1794 if(SWIG_IsOK(status))
1796 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1800 if(d->getNumberOfTuples()==nbTuplesExpected)
1802 if(d->getNumberOfComponents()==nbCompExpected)
1804 return d->getConstPointer();
1808 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1809 throw INTERP_KERNEL::Exception(oss.str().c_str());
1814 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1815 throw INTERP_KERNEL::Exception(oss.str().c_str());
1822 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1823 throw INTERP_KERNEL::Exception(oss.str().c_str());
1829 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1830 if(SWIG_IsOK(status))
1832 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1834 if(e->getNumberOfCompo()==nbCompExpected)
1836 if(nbTuplesExpected==1)
1837 return e->getConstPointer();
1840 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1841 throw INTERP_KERNEL::Exception(oss.str().c_str());
1846 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1847 throw INTERP_KERNEL::Exception(oss.str().c_str());
1850 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1854 * if value int -> cpp val sw=1
1855 * if value double -> cpp val sw=1
1856 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1857 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1858 * if value list[int,double] -> cpp std::vector<double> sw=4
1859 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1861 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1862 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1865 if(PyFloat_Check(value))
1867 val=PyFloat_AS_DOUBLE(value);
1869 if(nbCompExpected!=1)
1871 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1872 throw INTERP_KERNEL::Exception(oss.str().c_str());
1877 if(PyInt_Check(value))
1879 val=(double)PyInt_AS_LONG(value);
1881 if(nbCompExpected!=1)
1883 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1884 throw INTERP_KERNEL::Exception(oss.str().c_str());
1889 if(PyTuple_Check(value))
1891 int size=PyTuple_Size(value);
1893 for(int i=0;i<size;i++)
1895 PyObject *o=PyTuple_GetItem(value,i);
1896 if(PyFloat_Check(o))
1897 f[i]=PyFloat_AS_DOUBLE(o);
1898 else if(PyInt_Check(o))
1899 f[i]=(double)PyInt_AS_LONG(o);
1902 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1903 throw INTERP_KERNEL::Exception(oss.str().c_str());
1907 if(size%nbCompExpected!=0)
1909 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1910 throw INTERP_KERNEL::Exception(oss.str().c_str());
1912 nbTuples=size/nbCompExpected;
1915 if(PyList_Check(value))
1917 int size=PyList_Size(value);
1919 for(int i=0;i<size;i++)
1921 PyObject *o=PyList_GetItem(value,i);
1922 if(PyFloat_Check(o))
1923 f[i]=PyFloat_AS_DOUBLE(o);
1924 else if(PyInt_Check(o))
1925 f[i]=(double)PyInt_AS_LONG(o);
1928 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1929 throw INTERP_KERNEL::Exception(oss.str().c_str());
1933 if(size%nbCompExpected!=0)
1935 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1936 throw INTERP_KERNEL::Exception(oss.str().c_str());
1938 nbTuples=size/nbCompExpected;
1942 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1943 if(SWIG_IsOK(status))
1945 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1949 if(d->getNumberOfComponents()==nbCompExpected)
1951 nbTuples=d->getNumberOfTuples();
1952 return d->getConstPointer();
1956 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1957 throw INTERP_KERNEL::Exception(oss.str().c_str());
1964 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1965 throw INTERP_KERNEL::Exception(oss.str().c_str());
1968 { nbTuples=0; return 0; }
1971 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1972 if(SWIG_IsOK(status))
1974 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1978 if(e->getNumberOfCompo()==nbCompExpected)
1981 return e->getConstPointer();
1985 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1986 throw INTERP_KERNEL::Exception(oss.str().c_str());
1993 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1994 throw INTERP_KERNEL::Exception(oss.str().c_str());
1997 { nbTuples=0; return 0; }
2000 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2004 * if value int -> cpp val sw=1
2005 * if value double -> cpp val sw=1
2006 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2007 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2008 * if value list[int,double] -> cpp std::vector<double> sw=4
2009 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2011 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2012 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2014 ParaMEDMEM::DataArrayDouble *d=0;
2015 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2017 if(PyFloat_Check(value))
2019 val=PyFloat_AS_DOUBLE(value);
2024 if(PyInt_Check(value))
2026 val=(double)PyInt_AS_LONG(value);
2031 if(PyTuple_Check(value))
2033 int size=PyTuple_Size(value);
2035 for(int i=0;i<size;i++)
2037 PyObject *o=PyTuple_GetItem(value,i);
2038 if(PyFloat_Check(o))
2039 f[i]=PyFloat_AS_DOUBLE(o);
2040 else if(PyInt_Check(o))
2041 f[i]=(double)PyInt_AS_LONG(o);
2044 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2045 throw INTERP_KERNEL::Exception(oss.str().c_str());
2052 if(PyList_Check(value))
2054 int size=PyList_Size(value);
2056 for(int i=0;i<size;i++)
2058 PyObject *o=PyList_GetItem(value,i);
2059 if(PyFloat_Check(o))
2060 f[i]=PyFloat_AS_DOUBLE(o);
2061 else if(PyInt_Check(o))
2062 f[i]=(double)PyInt_AS_LONG(o);
2065 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2066 throw INTERP_KERNEL::Exception(oss.str().c_str());
2074 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2075 if(SWIG_IsOK(status))
2077 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2081 if(d->getNumberOfComponents()==1)
2083 nbTuples=d->getNumberOfTuples();
2084 return d->getConstPointer();
2088 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2089 throw INTERP_KERNEL::Exception(oss.str().c_str());
2096 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2097 throw INTERP_KERNEL::Exception(oss.str().c_str());
2100 { nbTuples=0; return 0; }
2103 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2104 if(SWIG_IsOK(status))
2106 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2110 nbTuples=e->getNumberOfCompo();
2111 return e->getConstPointer();
2117 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2118 throw INTERP_KERNEL::Exception(oss.str().c_str());
2121 { nbTuples=0; return 0; }
2124 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2128 * if python int -> cpp int sw=1
2129 * if python list[int] -> cpp vector<int> sw=2
2130 * if python tuple[int] -> cpp vector<int> sw=2
2131 * if python DataArrayInt -> cpp DataArrayInt sw=3
2132 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2134 * switch between (int,vector<int>,DataArrayInt)
2136 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2139 if(PyInt_Check(value))
2141 iTyypp=(int)PyInt_AS_LONG(value);
2145 if(PyTuple_Check(value))
2147 int size=PyTuple_Size(value);
2148 stdvecTyypp.resize(size);
2149 for(int i=0;i<size;i++)
2151 PyObject *o=PyTuple_GetItem(value,i);
2153 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2156 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2157 throw INTERP_KERNEL::Exception(oss.str().c_str());
2161 return &stdvecTyypp[0];
2163 if(PyList_Check(value))
2165 int size=PyList_Size(value);
2166 stdvecTyypp.resize(size);
2167 for(int i=0;i<size;i++)
2169 PyObject *o=PyList_GetItem(value,i);
2171 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2174 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2175 throw INTERP_KERNEL::Exception(oss.str().c_str());
2179 return &stdvecTyypp[0];
2182 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2183 if(SWIG_IsOK(status))
2185 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2188 sw=3; sz=daIntTyypp->getNbOfElems();
2189 return daIntTyypp->begin();
2197 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2198 if(SWIG_IsOK(status))
2200 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2201 sw=4; sz=daIntTuple->getNumberOfCompo();
2202 return daIntTuple->getConstPointer();
2204 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2207 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2210 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2211 if(!SWIG_IsOK(status))
2213 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2214 if(!SWIG_IsOK(status))
2216 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2217 if(!SWIG_IsOK(status))
2219 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2220 if(!SWIG_IsOK(status))
2222 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2223 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2224 throw INTERP_KERNEL::Exception(oss.str().c_str());
2229 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);