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
20 #include "InterpKernelAutoPtr.hxx"
23 #include <numpy/arrayobject.h>
25 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
26 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
27 // if no more alive the "standart" DataArray deallocator is called.
28 void numarrdeal(void *pt, void *wron)
30 void **wronc=(void **)wron;
31 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
32 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
36 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
37 objC->flags|=NPY_OWNDATA;
38 Py_XDECREF(weakRefOnOwner);
43 typedef void (*MyDeallocator)(void *,void *);
44 MyDeallocator deall=(MyDeallocator)wronc[1];
46 Py_XDECREF(weakRefOnOwner);
51 template<class MCData>
52 struct PyCallBackDataArraySt {
57 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
58 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
62 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
64 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
66 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
67 return (PyObject *)self;
70 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
72 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
73 return (PyObject *)self;
76 static void callbackmcdataarray_dealloc(PyObject *self)
78 Py_TYPE(self)->tp_free(self);
81 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
82 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
83 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
87 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
94 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
95 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
96 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
100 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
108 PyTypeObject PyCallBackDataArrayInt_RefType = {
109 PyVarObject_HEAD_INIT(&PyType_Type, 0)
110 "callbackmcdataarrayint",
111 sizeof(PyCallBackDataArrayInt),
113 callbackmcdataarray_dealloc, /*tp_dealloc*/
120 0, /*tp_as_sequence*/
123 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
128 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
132 0, /*tp_richcompare*/
133 0, /*tp_weaklistoffset*/
144 callbackmcdataarray___init__, /*tp_init*/
145 PyType_GenericAlloc, /*tp_alloc*/
146 callbackmcdataarrayint___new__, /*tp_new*/
147 PyObject_GC_Del, /*tp_free*/
150 PyTypeObject PyCallBackDataArrayDouble_RefType = {
151 PyVarObject_HEAD_INIT(&PyType_Type, 0)
152 "callbackmcdataarraydouble",
153 sizeof(PyCallBackDataArrayDouble),
155 callbackmcdataarray_dealloc, /*tp_dealloc*/
162 0, /*tp_as_sequence*/
165 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
170 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
174 0, /*tp_richcompare*/
175 0, /*tp_weaklistoffset*/
186 callbackmcdataarray___init__, /*tp_init*/
187 PyType_GenericAlloc, /*tp_alloc*/
188 callbackmcdataarraydouble___new__, /*tp_new*/
189 PyObject_GC_Del, /*tp_free*/
192 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
193 // in input when an another DataArray is already client of this.
194 template<class MCData>
195 void numarrdeal2(void *pt, void *obj)
197 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
198 void **obj1=(void **)obj;
199 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
200 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
202 Py_XDECREF(weakRefOnOwner);
207 template<class MCData, class T>
208 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
210 int ndim=PyArray_NDIM(elt0);
211 if(ndim!=1 && ndim!=2)
212 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
213 if(PyArray_ObjectType(elt0,0)!=npyObjectType)
215 std::ostringstream oss; oss << "Input numpy array has not of type " << msg << " at component #0 !";
216 throw INTERP_KERNEL::Exception(oss.str().c_str());
219 if(PyArray_ObjectType(elt0,1)!=npyObjectType)
221 std::ostringstream oss; oss << "Input numpy array has not of type " << msg << " at component #1 !";
222 throw INTERP_KERNEL::Exception(oss.str().c_str());
224 npy_intp sz0=PyArray_DIM(elt0,0);
225 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
227 int itemSize=PyArray_ITEMSIZE(elt0);
228 if(itemSize!=sizeof(T))
230 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
231 throw INTERP_KERNEL::Exception(oss.str().c_str());
233 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
234 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
236 if(itemSize!=PyArray_STRIDE(elt0,1))
237 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 !");
238 const char *data=PyArray_BYTES(elt0);
239 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
240 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
242 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
243 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
244 int mask=NPY_OWNDATA; mask=~mask;
246 PyObject *deepestObj=elt0;
247 PyObject *base=elt0C->base;
248 if(base) deepestObj=base;
251 if(PyArray_Check(base))
253 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
254 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
257 if(base) deepestObj=base;
262 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
265 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
267 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
268 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
269 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
270 mma.setParameterForDeallocator(objs);
271 mma.setSpecificDeallocator(numarrdeal2<MCData>);
272 //"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 !");
276 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
277 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
278 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
279 mma.setParameterForDeallocator(objs);
280 mma.setSpecificDeallocator(numarrdeal);
283 else if(PyArray_ISBEHAVED_RO(elt0))
284 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
289 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
292 PyErr_SetString(PyExc_ValueError,
293 "Cannot set the NumPy array 'base' "
294 "dependency to NULL after initialization");
298 * Allow the base to be set only once. Once the object which
299 * owns the data is set, it doesn't make sense to change it.
301 if (PyArray_BASE(arr) != NULL) {
303 PyErr_SetString(PyExc_ValueError,
304 "Cannot set the NumPy array 'base' "
305 "dependency more than once");
310 * Don't allow infinite chains of views, always set the base
311 * to the first owner of the data.
312 * That is, either the first object which isn't an array,
313 * or the first object which owns its own data.
316 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
317 PyArrayObject *obj_arr = (PyArrayObject *)obj;
321 /* If this array owns its own data, stop collapsing */
322 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
326 tmp = PyArray_BASE(obj_arr);
327 /* If there's no base, stop collapsing */
331 /* Stop the collapse new base when the would not be of the same
332 * type (i.e. different subclass).
334 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
344 /* Disallow circular references */
345 if ((PyObject *)arr == obj) {
347 PyErr_SetString(PyExc_ValueError,
348 "Cannot create a circular NumPy array 'base' dependency");
357 template<class MCData, class T>
358 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
360 if(!self->isAllocated())
362 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
363 throw INTERP_KERNEL::Exception(oss.str().c_str());
365 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
366 int nbComp=self->getNumberOfComponents();
369 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
370 throw INTERP_KERNEL::Exception(oss.str().c_str());
372 int nbDims=nbComp==1?1:2;
374 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
375 const T *bg=self->getConstPointer();
376 PyObject *ret=PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg));
377 if(mem.isDeallocatorCalled())
379 if(mem.getDeallocator()!=numarrdeal)
380 {// case for the first call of toNumPyArray
381 PyObject *ref=PyWeakref_NewRef(ret,NULL);
382 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) mem.getDeallocator();
383 mem.setParameterForDeallocator(objs);
384 mem.setSpecificDeallocator(numarrdeal);
388 {// case for the second and other call of toNumPyArray
389 void **objs=(void **)mem.getParameterForDeallocator();
390 PyObject *weakRefOnOwner=(PyObject *)objs[0];
391 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
393 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
395 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
398 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
399 Py_XDECREF(weakRefOnOwner);
400 PyObject *ref=PyWeakref_NewRef(ret,NULL);
410 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
418 if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
419 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
420 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
421 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
422 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
423 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
424 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
425 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
427 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
431 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
439 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
440 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
441 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
442 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
443 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
444 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
445 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
446 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
447 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
448 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
450 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
454 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
462 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
463 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
464 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
465 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
467 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
471 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
479 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
480 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
481 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
482 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
483 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
484 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
485 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
486 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
488 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
492 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
500 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
501 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
503 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
507 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
509 PyObject *ret=PyList_New(size);
510 for(int i=0;i<size;i++)
511 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
515 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
518 PyObject *ret=PyList_New(size);
519 for(int i=0;i<size;i++)
520 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
524 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
527 PyObject *ret=PyList_New(size);
528 std::set<int>::const_iterator it=v.begin();
529 for(int i=0;i<size;i++,it++)
530 PyList_SetItem(ret,i,PyInt_FromLong(*it));
534 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
536 PyObject *ret=PyList_New(nbOfTuples);
537 for(int i=0;i<nbOfTuples;i++)
539 PyObject *t=PyTuple_New(nbOfComp);
540 for(int j=0;j<nbOfComp;j++)
541 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
542 PyList_SetItem(ret,i,t);
547 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
549 if(PyList_Check(pyLi))
551 *size=PyList_Size(pyLi);
552 int *tmp=new int[*size];
553 for(int i=0;i<*size;i++)
555 PyObject *o=PyList_GetItem(pyLi,i);
558 int val=(int)PyInt_AS_LONG(o);
564 throw INTERP_KERNEL::Exception("list must contain integers only");
569 else if(PyTuple_Check(pyLi))
571 *size=PyTuple_Size(pyLi);
572 int *tmp=new int[*size];
573 for(int i=0;i<*size;i++)
575 PyObject *o=PyTuple_GetItem(pyLi,i);
578 int val=(int)PyInt_AS_LONG(o);
584 throw INTERP_KERNEL::Exception("tuple must contain integers only");
591 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
595 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
597 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
598 if(PyList_Check(pyLi))
600 int size=PyList_Size(pyLi);
602 for(int i=0;i<size;i++)
604 PyObject *o=PyList_GetItem(pyLi,i);
607 int sz2=PyTuple_Size(o);
609 throw INTERP_KERNEL::Exception(msg);
610 PyObject *o_0=PyTuple_GetItem(o,0);
611 if(!PyInt_Check(o_0))
612 throw INTERP_KERNEL::Exception(msg);
613 PyObject *o_1=PyTuple_GetItem(o,1);
614 if(!PyInt_Check(o_1))
615 throw INTERP_KERNEL::Exception(msg);
616 arr[i].first=(int)PyInt_AS_LONG(o_0);
617 arr[i].second=(int)PyInt_AS_LONG(o_1);
620 throw INTERP_KERNEL::Exception(msg);
623 else if(PyTuple_Check(pyLi))
625 int size=PyTuple_Size(pyLi);
627 for(int i=0;i<size;i++)
629 PyObject *o=PyTuple_GetItem(pyLi,i);
632 int sz2=PyTuple_Size(o);
634 throw INTERP_KERNEL::Exception(msg);
635 PyObject *o_0=PyTuple_GetItem(o,0);
636 if(!PyInt_Check(o_0))
637 throw INTERP_KERNEL::Exception(msg);
638 PyObject *o_1=PyTuple_GetItem(o,1);
639 if(!PyInt_Check(o_1))
640 throw INTERP_KERNEL::Exception(msg);
641 arr[i].first=(int)PyInt_AS_LONG(o_0);
642 arr[i].second=(int)PyInt_AS_LONG(o_1);
645 throw INTERP_KERNEL::Exception(msg);
649 throw INTERP_KERNEL::Exception(msg);
652 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
654 if(PyList_Check(pyLi))
656 int size=PyList_Size(pyLi);
658 for(int i=0;i<size;i++)
660 PyObject *o=PyList_GetItem(pyLi,i);
663 int val=(int)PyInt_AS_LONG(o);
667 throw INTERP_KERNEL::Exception("list must contain integers only");
670 else if(PyTuple_Check(pyLi))
672 int size=PyTuple_Size(pyLi);
674 for(int i=0;i<size;i++)
676 PyObject *o=PyTuple_GetItem(pyLi,i);
679 int val=(int)PyInt_AS_LONG(o);
683 throw INTERP_KERNEL::Exception("tuple must contain integers only");
688 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
692 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
695 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
697 if(PyList_Check(pyLi))
699 int size=PyList_Size(pyLi);
700 for(int i=0;i<size;i++)
702 PyObject *o=PyList_GetItem(pyLi,i);
705 int val=(int)PyInt_AS_LONG(o);
710 std::vector<int> arr2;
711 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
712 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
714 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
715 throw INTERP_KERNEL::Exception(oss.str().c_str());
717 arr.insert(arr.end(),arr2.begin(),arr2.end());
721 else if(PyTuple_Check(pyLi))
723 int size=PyTuple_Size(pyLi);
724 for(int i=0;i<size;i++)
726 PyObject *o=PyTuple_GetItem(pyLi,i);
729 int val=(int)PyInt_AS_LONG(o);
734 std::vector<int> arr2;
735 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
736 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
738 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
739 throw INTERP_KERNEL::Exception(oss.str().c_str());
741 arr.insert(arr.end(),arr2.begin(),arr2.end());
746 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
749 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
753 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
754 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
756 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
757 oss << " whereas nb of components expected is " << nbOfComp << " !";
758 throw INTERP_KERNEL::Exception(oss.str().c_str());
765 if((nbOfTuples!=size1 || nbOfComp!=size2))
767 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
769 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
770 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
771 throw INTERP_KERNEL::Exception(oss.str().c_str());
777 if(nbOfTuples==size1)
781 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
782 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
783 throw INTERP_KERNEL::Exception(oss.str().c_str());
789 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
791 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
792 if(PyInt_Check(pyLi))
794 long val=PyInt_AS_LONG(pyLi);
799 throw INTERP_KERNEL::Exception(MSG);
802 else if(PyList_Check(pyLi))
804 int size=PyList_Size(pyLi);
806 for(int i=0;i<size;i++)
808 PyObject *o=PyList_GetItem(pyLi,i);
810 fillArrayWithPyListInt3(o,tmp1,ret);
818 throw INTERP_KERNEL::Exception(MSG);
821 else if(PyTuple_Check(pyLi))
823 int size=PyTuple_Size(pyLi);
825 for(int i=0;i<size;i++)
827 PyObject *o=PyTuple_GetItem(pyLi,i);
829 fillArrayWithPyListInt3(o,tmp1,ret);
837 throw INTERP_KERNEL::Exception(MSG);
841 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
844 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
846 std::vector<int> ret;
847 int size1=-1,size2=-1;
848 if(PyList_Check(pyLi))
850 size1=PyList_Size(pyLi);
851 for(int i=0;i<size1;i++)
853 PyObject *o=PyList_GetItem(pyLi,i);
854 fillArrayWithPyListInt3(o,size2,ret);
859 else if(PyTuple_Check(pyLi))
861 size1=PyTuple_Size(pyLi);
862 for(int i=0;i<size1;i++)
864 PyObject *o=PyTuple_GetItem(pyLi,i);
865 fillArrayWithPyListInt3(o,size2,ret);
871 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
873 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
877 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
879 if(PyList_Check(pyLi))
881 Py_ssize_t sz=PyList_Size(pyLi);
883 for(int i=0;i<sz;i++)
885 PyObject *o=PyList_GetItem(pyLi,i);
886 if(PyString_Check(o))
887 vec[i]=PyString_AsString(o);
893 else if(PyTuple_Check(pyLi))
895 Py_ssize_t sz=PyTuple_Size(pyLi);
897 for(int i=0;i<sz;i++)
899 PyObject *o=PyTuple_GetItem(pyLi,i);
900 if(PyString_Check(o))
901 vec[i]=PyString_AsString(o);
911 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
913 PyObject *ret=PyList_New(size);
914 for(int i=0;i<size;i++)
915 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
919 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
922 PyObject *ret=PyList_New(size);
923 for(int i=0;i<size;i++)
924 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
928 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
930 PyObject *ret=PyList_New(nbOfTuples);
931 for(int i=0;i<nbOfTuples;i++)
933 PyObject *t=PyTuple_New(nbOfComp);
934 for(int j=0;j<nbOfComp;j++)
935 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
936 PyList_SetItem(ret,i,t);
941 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
943 PyObject *ret=PyList_New(nbOfTuples);
944 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
945 for(int i=0;i<nbOfTuples;i++)
947 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
948 PyList_SetItem(ret,i,PyString_FromString(tmp));
953 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
955 if(PyList_Check(pyLi))
957 *size=PyList_Size(pyLi);
958 double *tmp=(double *)malloc((*size)*sizeof(double));
959 for(int i=0;i<*size;i++)
961 PyObject *o=PyList_GetItem(pyLi,i);
964 double val=PyFloat_AS_DOUBLE(o);
967 else if(PyInt_Check(o))
969 long val0=PyInt_AS_LONG(o);
976 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
981 else if(PyTuple_Check(pyLi))
983 *size=PyTuple_Size(pyLi);
984 double *tmp=(double *)malloc((*size)*sizeof(double));
985 for(int i=0;i<*size;i++)
987 PyObject *o=PyTuple_GetItem(pyLi,i);
990 double val=PyFloat_AS_DOUBLE(o);
993 else if(PyInt_Check(o))
995 long val0=PyInt_AS_LONG(o);
1002 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1008 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1011 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1013 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1014 if(PyFloat_Check(pyLi))
1020 throw INTERP_KERNEL::Exception(MSG);
1021 double val=PyFloat_AS_DOUBLE(pyLi);
1024 else if(PyInt_Check(pyLi))
1026 long val0=PyInt_AS_LONG(pyLi);
1032 throw INTERP_KERNEL::Exception(MSG);
1035 else if(PyList_Check(pyLi))
1037 int size=PyList_Size(pyLi);
1039 for(int i=0;i<size;i++)
1041 PyObject *o=PyList_GetItem(pyLi,i);
1043 fillArrayWithPyListDbl3(o,tmp1,ret);
1051 throw INTERP_KERNEL::Exception(MSG);
1054 else if(PyTuple_Check(pyLi))
1056 int size=PyTuple_Size(pyLi);
1058 for(int i=0;i<size;i++)
1060 PyObject *o=PyTuple_GetItem(pyLi,i);
1062 fillArrayWithPyListDbl3(o,tmp1,ret);
1070 throw INTERP_KERNEL::Exception(MSG);
1074 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1077 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1079 std::vector<double> ret;
1080 int size1=-1,size2=-1;
1081 if(PyList_Check(pyLi))
1083 size1=PyList_Size(pyLi);
1084 for(int i=0;i<size1;i++)
1086 PyObject *o=PyList_GetItem(pyLi,i);
1087 fillArrayWithPyListDbl3(o,size2,ret);
1092 else if(PyTuple_Check(pyLi))
1094 size1=PyTuple_Size(pyLi);
1095 for(int i=0;i<size1;i++)
1097 PyObject *o=PyTuple_GetItem(pyLi,i);
1098 fillArrayWithPyListDbl3(o,size2,ret);
1104 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1106 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1110 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1112 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1115 if(PyList_Check(pyLi))
1117 int size=PyList_Size(pyLi);
1119 for(int i=0;i<size;i++)
1121 PyObject *obj=PyList_GetItem(pyLi,i);
1122 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1123 if(!SWIG_IsOK(status))
1124 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
1125 T arg=reinterpret_cast< T >(argp);
1129 else if(PyTuple_Check(pyLi))
1131 int size=PyTuple_Size(pyLi);
1133 for(int i=0;i<size;i++)
1135 PyObject *obj=PyTuple_GetItem(pyLi,i);
1136 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1137 if(!SWIG_IsOK(status))
1139 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
1140 throw INTERP_KERNEL::Exception(oss.str().c_str());
1142 T arg=reinterpret_cast< T >(argp);
1146 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1149 T arg=reinterpret_cast< T >(argp);
1153 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1157 * if python int -> cpp int sw=1
1158 * if python list[int] -> cpp vector<int> sw=2
1159 * if python tuple[int] -> cpp vector<int> sw=2
1160 * if python DataArrayInt -> cpp DataArrayInt sw=3
1161 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1163 * switch between (int,vector<int>,DataArrayInt)
1165 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1168 if(PyInt_Check(value))
1170 iTyypp=(int)PyInt_AS_LONG(value);
1174 if(PyTuple_Check(value))
1176 int size=PyTuple_Size(value);
1177 stdvecTyypp.resize(size);
1178 for(int i=0;i<size;i++)
1180 PyObject *o=PyTuple_GetItem(value,i);
1182 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1185 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1186 throw INTERP_KERNEL::Exception(oss.str().c_str());
1192 if(PyList_Check(value))
1194 int size=PyList_Size(value);
1195 stdvecTyypp.resize(size);
1196 for(int i=0;i<size;i++)
1198 PyObject *o=PyList_GetItem(value,i);
1200 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1203 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1204 throw INTERP_KERNEL::Exception(oss.str().c_str());
1211 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1212 if(SWIG_IsOK(status))
1214 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1218 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1219 if(SWIG_IsOK(status))
1221 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1225 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1229 * if python double -> cpp double sw=1
1230 * if python int -> cpp double sw=1
1231 * if python list[double] -> cpp vector<double> sw=2
1232 * if python list[int] -> cpp vector<double> sw=2
1233 * if python tuple[double] -> cpp vector<double> sw=2
1234 * if python tuple[int] -> cpp vector<double> sw=2
1235 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1237 * switch between (int,vector<int>,DataArrayInt)
1239 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1242 if(PyFloat_Check(value))
1244 iTyypp=PyFloat_AS_DOUBLE(value);
1248 if(PyInt_Check(value))
1250 iTyypp=(double)PyInt_AS_LONG(value);
1254 if(PyTuple_Check(value))
1256 int size=PyTuple_Size(value);
1257 stdvecTyypp.resize(size);
1258 for(int i=0;i<size;i++)
1260 PyObject *o=PyTuple_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 << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1268 throw INTERP_KERNEL::Exception(oss.str().c_str());
1274 if(PyList_Check(value))
1276 int size=PyList_Size(value);
1277 stdvecTyypp.resize(size);
1278 for(int i=0;i<size;i++)
1280 PyObject *o=PyList_GetItem(value,i);
1281 if(PyFloat_Check(o))
1282 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1283 else if(PyInt_Check(o))
1284 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1287 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1288 throw INTERP_KERNEL::Exception(oss.str().c_str());
1295 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1296 if(!SWIG_IsOK(status))
1297 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1298 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1303 * if python double -> cpp double sw=1
1304 * if python int -> cpp double sw=1
1305 * if python list[double] -> cpp vector<double> sw=2
1306 * if python list[int] -> cpp vector<double> sw=2
1307 * if python tuple[double] -> cpp vector<double> sw=2
1308 * if python tuple[int] -> cpp vector<double> sw=2
1309 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1311 * switch between (int,vector<int>,DataArrayInt)
1313 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1316 if(PyFloat_Check(value))
1318 iTyypp=PyFloat_AS_DOUBLE(value);
1322 if(PyInt_Check(value))
1324 iTyypp=(double)PyInt_AS_LONG(value);
1328 if(PyTuple_Check(value))
1330 int size=PyTuple_Size(value);
1331 stdvecTyypp.resize(size);
1332 for(int i=0;i<size;i++)
1334 PyObject *o=PyTuple_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 << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1342 throw INTERP_KERNEL::Exception(oss.str().c_str());
1348 if(PyList_Check(value))
1350 int size=PyList_Size(value);
1351 stdvecTyypp.resize(size);
1352 for(int i=0;i<size;i++)
1354 PyObject *o=PyList_GetItem(value,i);
1355 if(PyFloat_Check(o))
1356 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1357 else if(PyInt_Check(o))
1358 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1361 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1362 throw INTERP_KERNEL::Exception(oss.str().c_str());
1369 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1370 if(!SWIG_IsOK(status))
1371 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1372 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1377 * if python int -> cpp int sw=1
1378 * if python list[int] -> cpp vector<int> sw=2
1379 * if python tuple[int] -> cpp vector<int> sw=2
1380 * if python slicp -> cpp pair sw=3 (begin,end,step)
1381 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1383 * switch between (int,vector<int>,DataArrayInt)
1385 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)
1387 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1389 if(PyInt_Check(value))
1391 iTyypp=(int)PyInt_AS_LONG(value);
1395 if(PyTuple_Check(value))
1397 int size=PyTuple_Size(value);
1398 stdvecTyypp.resize(size);
1399 for(int i=0;i<size;i++)
1401 PyObject *o=PyTuple_GetItem(value,i);
1403 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1406 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1407 throw INTERP_KERNEL::Exception(oss.str().c_str());
1413 if(PyList_Check(value))
1415 int size=PyList_Size(value);
1416 stdvecTyypp.resize(size);
1417 for(int i=0;i<size;i++)
1419 PyObject *o=PyList_GetItem(value,i);
1421 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1424 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1425 throw INTERP_KERNEL::Exception(oss.str().c_str());
1431 if(PySlice_Check(value))
1433 Py_ssize_t strt=2,stp=2,step=2;
1434 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1435 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1436 if(nbelem!=0 || strt!=0 || stp!=0)
1438 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1439 throw INTERP_KERNEL::Exception(oss.str().c_str());
1443 p.second.second=step;
1448 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1449 if(SWIG_IsOK(status))
1451 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1454 std::ostringstream oss; oss << msg << " Instance in null !";
1455 throw INTERP_KERNEL::Exception(oss.str().c_str());
1460 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1461 if(SWIG_IsOK(status))
1463 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1466 std::ostringstream oss; oss << msg << " Instance in null !";
1467 throw INTERP_KERNEL::Exception(oss.str().c_str());
1469 stdvecTyypp.resize(tmp->getNumberOfCompo());
1470 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1474 throw INTERP_KERNEL::Exception(msg);
1478 * if python int -> cpp int sw=1
1479 * if python tuple[int] -> cpp vector<int> sw=2
1480 * if python list[int] -> cpp vector<int> sw=2
1481 * if python slice -> cpp pair sw=3
1482 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1484 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)
1487 if(PyInt_Check(value))
1489 iTyypp=(int)PyInt_AS_LONG(value);
1493 if(PyTuple_Check(value))
1495 int size=PyTuple_Size(value);
1496 stdvecTyypp.resize(size);
1497 for(int i=0;i<size;i++)
1499 PyObject *o=PyTuple_GetItem(value,i);
1501 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1504 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1505 throw INTERP_KERNEL::Exception(oss.str().c_str());
1511 if(PyList_Check(value))
1513 int size=PyList_Size(value);
1514 stdvecTyypp.resize(size);
1515 for(int i=0;i<size;i++)
1517 PyObject *o=PyList_GetItem(value,i);
1519 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1522 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1523 throw INTERP_KERNEL::Exception(oss.str().c_str());
1529 if(PySlice_Check(value))
1531 Py_ssize_t strt=2,stp=2,step=2;
1532 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1533 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1534 if(nbelem!=0 || strt!=0 || stp!=0)
1536 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1537 throw INTERP_KERNEL::Exception(oss.str().c_str());
1541 p.second.second=step;
1546 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1547 if(!SWIG_IsOK(status))
1548 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1549 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1554 * if python string with size one -> cpp char sw=1
1555 * if python string with size different from one -> cpp string sw=2
1556 * if python tuple[string] or list[string] -> vector<string> sw=3
1557 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1558 * switch between (int,string,vector<string>,DataArrayChar)
1560 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1562 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1564 if(PyString_Check(value))
1566 const char *pt=PyString_AsString(value);
1567 Py_ssize_t sz=PyString_Size(value);
1581 if(PyTuple_Check(value))
1583 int size=PyTuple_Size(value);
1584 vsType.resize(size);
1585 for(int i=0;i<size;i++)
1587 PyObject *o=PyTuple_GetItem(value,i);
1588 if(PyString_Check(o))
1589 vsType[i]=PyString_AsString(o);
1592 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1593 throw INTERP_KERNEL::Exception(oss.str().c_str());
1599 if(PyList_Check(value))
1601 int size=PyList_Size(value);
1602 vsType.resize(size);
1603 for(int i=0;i<size;i++)
1605 PyObject *o=PyList_GetItem(value,i);
1606 if(PyString_Check(o))
1607 vsType[i]=PyString_AsString(o);
1610 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1611 throw INTERP_KERNEL::Exception(oss.str().c_str());
1618 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1619 if(SWIG_IsOK(status))
1621 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1624 std::ostringstream oss; oss << msg << " Instance in null !";
1625 throw INTERP_KERNEL::Exception(oss.str().c_str());
1630 throw INTERP_KERNEL::Exception(msg);
1634 * if value int -> cpp it sw=1
1635 * if value list[int] -> vt sw=2
1636 * if value tuple[int] -> vt sw=2
1637 * if value slice -> pt sw=3
1638 * if value DataArrayInt -> dt sw=4
1639 * if value tuple [int,int] -> cpp it,ip sw=5
1640 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1641 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1642 * if value tuple [slice,int] -> cpp pt,ip sw=7
1643 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1644 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1645 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1646 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1647 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1648 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1649 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1650 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1651 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1652 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1653 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1654 * if value tuple [int,slice] -> cpp it,pc sw=13
1655 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1656 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1657 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1658 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1660 * switch between (int,vector<int>,DataArrayInt)
1662 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1663 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1664 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1666 if(!PyTuple_Check(value))
1668 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1673 int sz=PyTuple_Size(value);
1675 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1676 PyObject *ob0=PyTuple_GetItem(value,0);
1678 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1679 PyObject *ob1=PyTuple_GetItem(value,1);
1680 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1686 * if value int -> cpp val sw=1
1687 * if value double -> cpp val sw=1
1688 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1689 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1690 * if value list[int,double] -> cpp std::vector<double> sw=4
1691 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1693 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1696 if(PyFloat_Check(value))
1698 val=PyFloat_AS_DOUBLE(value);
1702 if(PyInt_Check(value))
1704 val=(double)PyInt_AS_LONG(value);
1708 if(PyTuple_Check(value))
1710 int size=PyTuple_Size(value);
1712 for(int i=0;i<size;i++)
1714 PyObject *o=PyTuple_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 << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1722 throw INTERP_KERNEL::Exception(oss.str().c_str());
1728 if(PyList_Check(value))
1730 int size=PyList_Size(value);
1732 for(int i=0;i<size;i++)
1734 PyObject *o=PyList_GetItem(value,i);
1735 if(PyFloat_Check(o))
1736 f[i]=PyFloat_AS_DOUBLE(o);
1737 else if(PyInt_Check(o))
1738 f[i]=(double)PyInt_AS_LONG(o);
1741 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1742 throw INTERP_KERNEL::Exception(oss.str().c_str());
1749 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1750 if(SWIG_IsOK(status))
1752 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1756 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1757 if(SWIG_IsOK(status))
1759 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1763 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1767 * if value int -> cpp val sw=1
1768 * if value double -> cpp val sw=1
1769 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1770 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1771 * if value list[int,double] -> cpp std::vector<double> sw=4
1772 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1774 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1775 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1778 if(PyFloat_Check(value))
1780 val=PyFloat_AS_DOUBLE(value);
1782 if(nbTuplesExpected*nbCompExpected!=1)
1784 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1785 throw INTERP_KERNEL::Exception(oss.str().c_str());
1789 if(PyInt_Check(value))
1791 val=(double)PyInt_AS_LONG(value);
1793 if(nbTuplesExpected*nbCompExpected!=1)
1795 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1796 throw INTERP_KERNEL::Exception(oss.str().c_str());
1800 if(PyTuple_Check(value) || PyList_Check(value))
1804 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1805 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1810 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1813 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1814 if(SWIG_IsOK(status))
1816 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1820 if(d->getNumberOfTuples()==nbTuplesExpected)
1822 if(d->getNumberOfComponents()==nbCompExpected)
1824 return d->getConstPointer();
1828 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1829 throw INTERP_KERNEL::Exception(oss.str().c_str());
1834 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1835 throw INTERP_KERNEL::Exception(oss.str().c_str());
1842 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1843 throw INTERP_KERNEL::Exception(oss.str().c_str());
1849 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1850 if(SWIG_IsOK(status))
1852 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1854 if(e->getNumberOfCompo()==nbCompExpected)
1856 if(nbTuplesExpected==1)
1857 return e->getConstPointer();
1860 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1861 throw INTERP_KERNEL::Exception(oss.str().c_str());
1866 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1867 throw INTERP_KERNEL::Exception(oss.str().c_str());
1870 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1874 * if value int -> cpp val sw=1
1875 * if value double -> cpp val sw=1
1876 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1877 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1878 * if value list[int,double] -> cpp std::vector<double> sw=4
1879 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1881 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1882 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1885 if(PyFloat_Check(value))
1887 val=PyFloat_AS_DOUBLE(value);
1889 if(nbCompExpected!=1)
1891 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1892 throw INTERP_KERNEL::Exception(oss.str().c_str());
1897 if(PyInt_Check(value))
1899 val=(double)PyInt_AS_LONG(value);
1901 if(nbCompExpected!=1)
1903 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1904 throw INTERP_KERNEL::Exception(oss.str().c_str());
1909 if(PyTuple_Check(value))
1911 int size=PyTuple_Size(value);
1913 for(int i=0;i<size;i++)
1915 PyObject *o=PyTuple_GetItem(value,i);
1916 if(PyFloat_Check(o))
1917 f[i]=PyFloat_AS_DOUBLE(o);
1918 else if(PyInt_Check(o))
1919 f[i]=(double)PyInt_AS_LONG(o);
1922 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1923 throw INTERP_KERNEL::Exception(oss.str().c_str());
1927 if(size%nbCompExpected!=0)
1929 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1930 throw INTERP_KERNEL::Exception(oss.str().c_str());
1932 nbTuples=size/nbCompExpected;
1935 if(PyList_Check(value))
1937 int size=PyList_Size(value);
1939 for(int i=0;i<size;i++)
1941 PyObject *o=PyList_GetItem(value,i);
1942 if(PyFloat_Check(o))
1943 f[i]=PyFloat_AS_DOUBLE(o);
1944 else if(PyInt_Check(o))
1945 f[i]=(double)PyInt_AS_LONG(o);
1948 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1949 throw INTERP_KERNEL::Exception(oss.str().c_str());
1953 if(size%nbCompExpected!=0)
1955 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1956 throw INTERP_KERNEL::Exception(oss.str().c_str());
1958 nbTuples=size/nbCompExpected;
1962 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1963 if(SWIG_IsOK(status))
1965 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1969 if(d->getNumberOfComponents()==nbCompExpected)
1971 nbTuples=d->getNumberOfTuples();
1972 return d->getConstPointer();
1976 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1977 throw INTERP_KERNEL::Exception(oss.str().c_str());
1984 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1985 throw INTERP_KERNEL::Exception(oss.str().c_str());
1988 { nbTuples=0; return 0; }
1991 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1992 if(SWIG_IsOK(status))
1994 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1998 if(e->getNumberOfCompo()==nbCompExpected)
2001 return e->getConstPointer();
2005 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2006 throw INTERP_KERNEL::Exception(oss.str().c_str());
2013 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2014 throw INTERP_KERNEL::Exception(oss.str().c_str());
2017 { nbTuples=0; return 0; }
2020 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2024 * if value int -> cpp val sw=1
2025 * if value double -> cpp val sw=1
2026 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2027 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2028 * if value list[int,double] -> cpp std::vector<double> sw=4
2029 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2031 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2032 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2034 ParaMEDMEM::DataArrayDouble *d=0;
2035 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2037 if(PyFloat_Check(value))
2039 val=PyFloat_AS_DOUBLE(value);
2044 if(PyInt_Check(value))
2046 val=(double)PyInt_AS_LONG(value);
2051 if(PyTuple_Check(value))
2053 int size=PyTuple_Size(value);
2055 for(int i=0;i<size;i++)
2057 PyObject *o=PyTuple_GetItem(value,i);
2058 if(PyFloat_Check(o))
2059 f[i]=PyFloat_AS_DOUBLE(o);
2060 else if(PyInt_Check(o))
2061 f[i]=(double)PyInt_AS_LONG(o);
2064 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2065 throw INTERP_KERNEL::Exception(oss.str().c_str());
2072 if(PyList_Check(value))
2074 int size=PyList_Size(value);
2076 for(int i=0;i<size;i++)
2078 PyObject *o=PyList_GetItem(value,i);
2079 if(PyFloat_Check(o))
2080 f[i]=PyFloat_AS_DOUBLE(o);
2081 else if(PyInt_Check(o))
2082 f[i]=(double)PyInt_AS_LONG(o);
2085 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2086 throw INTERP_KERNEL::Exception(oss.str().c_str());
2094 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2095 if(SWIG_IsOK(status))
2097 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2101 if(d->getNumberOfComponents()==1)
2103 nbTuples=d->getNumberOfTuples();
2104 return d->getConstPointer();
2108 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2109 throw INTERP_KERNEL::Exception(oss.str().c_str());
2116 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2117 throw INTERP_KERNEL::Exception(oss.str().c_str());
2120 { nbTuples=0; return 0; }
2123 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2124 if(SWIG_IsOK(status))
2126 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2130 nbTuples=e->getNumberOfCompo();
2131 return e->getConstPointer();
2137 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2138 throw INTERP_KERNEL::Exception(oss.str().c_str());
2141 { nbTuples=0; return 0; }
2144 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2148 * if python int -> cpp int sw=1
2149 * if python list[int] -> cpp vector<int> sw=2
2150 * if python tuple[int] -> cpp vector<int> sw=2
2151 * if python DataArrayInt -> cpp DataArrayInt sw=3
2152 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2154 * switch between (int,vector<int>,DataArrayInt)
2156 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2159 if(PyInt_Check(value))
2161 iTyypp=(int)PyInt_AS_LONG(value);
2165 if(PyTuple_Check(value))
2167 int size=PyTuple_Size(value);
2168 stdvecTyypp.resize(size);
2169 for(int i=0;i<size;i++)
2171 PyObject *o=PyTuple_GetItem(value,i);
2173 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2176 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2177 throw INTERP_KERNEL::Exception(oss.str().c_str());
2181 return &stdvecTyypp[0];
2183 if(PyList_Check(value))
2185 int size=PyList_Size(value);
2186 stdvecTyypp.resize(size);
2187 for(int i=0;i<size;i++)
2189 PyObject *o=PyList_GetItem(value,i);
2191 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2194 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2195 throw INTERP_KERNEL::Exception(oss.str().c_str());
2199 return &stdvecTyypp[0];
2202 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2203 if(SWIG_IsOK(status))
2205 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2208 sw=3; sz=daIntTyypp->getNbOfElems();
2209 return daIntTyypp->begin();
2217 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2218 if(SWIG_IsOK(status))
2220 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2221 sw=4; sz=daIntTuple->getNumberOfCompo();
2222 return daIntTuple->getConstPointer();
2224 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2227 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2229 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__add__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2230 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2233 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2235 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2237 return (*self)+(*other);
2239 throw INTERP_KERNEL::Exception(msg);
2243 ParaMEDMEM::DataArrayDouble *a;
2244 ParaMEDMEM::DataArrayDoubleTuple *aa;
2245 std::vector<double> bb;
2247 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2252 if(!self->getArray())
2253 throw INTERP_KERNEL::Exception(msg2);
2254 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2255 ret->applyLin(1.,val);
2256 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2257 ret2->setArray(ret);
2262 if(!self->getArray())
2263 throw INTERP_KERNEL::Exception(msg2);
2264 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2265 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2266 ret2->setArray(ret);
2271 if(!self->getArray())
2272 throw INTERP_KERNEL::Exception(msg2);
2273 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2274 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2275 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2276 ret2->setArray(ret);
2281 if(!self->getArray())
2282 throw INTERP_KERNEL::Exception(msg2);
2283 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2284 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2285 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2286 ret2->setArray(ret);
2290 { throw INTERP_KERNEL::Exception(msg); }
2294 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2296 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2299 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2301 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rsub__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2302 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2305 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2307 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2309 return (*other)-(*self);
2311 throw INTERP_KERNEL::Exception(msg);
2315 ParaMEDMEM::DataArrayDouble *a;
2316 ParaMEDMEM::DataArrayDoubleTuple *aa;
2317 std::vector<double> bb;
2319 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2324 if(!self->getArray())
2325 throw INTERP_KERNEL::Exception(msg2);
2326 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2327 ret->applyLin(-1.,val);
2328 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2329 ret2->setArray(ret);
2334 if(!self->getArray())
2335 throw INTERP_KERNEL::Exception(msg2);
2336 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2337 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2338 ret2->setArray(ret);
2343 if(!self->getArray())
2344 throw INTERP_KERNEL::Exception(msg2);
2345 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2346 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2347 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2348 ret2->setArray(ret);
2353 if(!self->getArray())
2354 throw INTERP_KERNEL::Exception(msg2);
2355 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2356 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2357 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2358 ret2->setArray(ret);
2362 { throw INTERP_KERNEL::Exception(msg); }
2366 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2368 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__mul__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2369 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2372 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2374 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2376 return (*self)*(*other);
2378 throw INTERP_KERNEL::Exception(msg);
2382 ParaMEDMEM::DataArrayDouble *a;
2383 ParaMEDMEM::DataArrayDoubleTuple *aa;
2384 std::vector<double> bb;
2386 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2391 if(!self->getArray())
2392 throw INTERP_KERNEL::Exception(msg2);
2393 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2394 ret->applyLin(val,0.);
2395 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2396 ret2->setArray(ret);
2401 if(!self->getArray())
2402 throw INTERP_KERNEL::Exception(msg2);
2403 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2404 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2405 ret2->setArray(ret);
2410 if(!self->getArray())
2411 throw INTERP_KERNEL::Exception(msg2);
2412 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2413 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2414 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2415 ret2->setArray(ret);
2420 if(!self->getArray())
2421 throw INTERP_KERNEL::Exception(msg2);
2422 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2423 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2424 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2425 ret2->setArray(ret);
2429 { throw INTERP_KERNEL::Exception(msg); }
2433 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2435 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2438 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2440 const char msg[]="Unexpected situation in MEDCouplingFieldDouble.__rdiv__ ! Expecting a not null MEDCouplingFieldDouble or DataArrayDouble or DataArrayDoubleTuple instance, or a list of double, or a double.";
2441 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2444 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2446 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2448 return (*other)/(*self);
2450 throw INTERP_KERNEL::Exception(msg);
2454 ParaMEDMEM::DataArrayDouble *a;
2455 ParaMEDMEM::DataArrayDoubleTuple *aa;
2456 std::vector<double> bb;
2458 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2463 if(!self->getArray())
2464 throw INTERP_KERNEL::Exception(msg2);
2465 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2467 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2468 ret2->setArray(ret);
2473 if(!self->getArray())
2474 throw INTERP_KERNEL::Exception(msg2);
2475 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2476 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2477 ret2->setArray(ret);
2482 if(!self->getArray())
2483 throw INTERP_KERNEL::Exception(msg2);
2484 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2485 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2486 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2487 ret2->setArray(ret);
2492 if(!self->getArray())
2493 throw INTERP_KERNEL::Exception(msg2);
2494 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2495 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2496 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2497 ret2->setArray(ret);
2501 { throw INTERP_KERNEL::Exception(msg); }
2505 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2508 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2509 if(!SWIG_IsOK(status))
2511 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2512 if(!SWIG_IsOK(status))
2514 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2515 if(!SWIG_IsOK(status))
2517 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2518 if(!SWIG_IsOK(status))
2520 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2521 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2522 throw INTERP_KERNEL::Exception(oss.str().c_str());
2527 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);