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_DESCR(elt0)->type_num != npyObjectType)
215 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
216 throw INTERP_KERNEL::Exception(oss.str().c_str());
218 npy_intp sz0=PyArray_DIM(elt0,0);
219 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
221 int itemSize=PyArray_ITEMSIZE(elt0);
222 if(itemSize!=sizeof(T))
224 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
225 throw INTERP_KERNEL::Exception(oss.str().c_str());
227 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
228 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
230 if(itemSize!=PyArray_STRIDE(elt0,1))
231 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 !");
232 const char *data=PyArray_BYTES(elt0);
233 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
234 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
236 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
237 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
238 int mask=NPY_OWNDATA; mask=~mask;
240 PyObject *deepestObj=elt0;
241 PyObject *base=elt0C->base;
242 if(base) deepestObj=base;
245 if(PyArray_Check(base))
247 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
248 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
251 if(base) deepestObj=base;
256 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
259 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
261 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
262 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
263 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
264 mma.setParameterForDeallocator(objs);
265 mma.setSpecificDeallocator(numarrdeal2<MCData>);
266 //"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 !");
270 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
271 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
272 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
273 mma.setParameterForDeallocator(objs);
274 mma.setSpecificDeallocator(numarrdeal);
277 else if(PyArray_ISBEHAVED_RO(elt0))
278 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
283 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
286 PyErr_SetString(PyExc_ValueError,
287 "Cannot set the NumPy array 'base' "
288 "dependency to NULL after initialization");
292 * Allow the base to be set only once. Once the object which
293 * owns the data is set, it doesn't make sense to change it.
295 if (PyArray_BASE(arr) != NULL) {
297 PyErr_SetString(PyExc_ValueError,
298 "Cannot set the NumPy array 'base' "
299 "dependency more than once");
304 * Don't allow infinite chains of views, always set the base
305 * to the first owner of the data.
306 * That is, either the first object which isn't an array,
307 * or the first object which owns its own data.
310 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
311 PyArrayObject *obj_arr = (PyArrayObject *)obj;
315 /* If this array owns its own data, stop collapsing */
316 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
320 tmp = PyArray_BASE(obj_arr);
321 /* If there's no base, stop collapsing */
325 /* Stop the collapse new base when the would not be of the same
326 * type (i.e. different subclass).
328 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
338 /* Disallow circular references */
339 if ((PyObject *)arr == obj) {
341 PyErr_SetString(PyExc_ValueError,
342 "Cannot create a circular NumPy array 'base' dependency");
351 template<class MCData, class T>
352 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
354 if(!self->isAllocated())
356 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
357 throw INTERP_KERNEL::Exception(oss.str().c_str());
359 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
360 int nbComp=self->getNumberOfComponents();
363 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
364 throw INTERP_KERNEL::Exception(oss.str().c_str());
366 int nbDims=nbComp==1?1:2;
368 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
369 const T *bg=self->getConstPointer();
370 PyObject *ret=PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg));
371 if(mem.isDeallocatorCalled())
373 if(mem.getDeallocator()!=numarrdeal)
374 {// case for the first call of toNumPyArray
375 PyObject *ref=PyWeakref_NewRef(ret,NULL);
376 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) mem.getDeallocator();
377 mem.setParameterForDeallocator(objs);
378 mem.setSpecificDeallocator(numarrdeal);
382 {// case for the second and other call of toNumPyArray
383 void **objs=(void **)mem.getParameterForDeallocator();
384 PyObject *weakRefOnOwner=(PyObject *)objs[0];
385 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
387 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
389 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
392 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
393 Py_XDECREF(weakRefOnOwner);
394 PyObject *ref=PyWeakref_NewRef(ret,NULL);
404 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
412 if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
413 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
414 if(dynamic_cast<ParaMEDMEM::MEDCoupling1SGTUMesh *>(mesh))
415 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1SGTUMesh,owner);
416 if(dynamic_cast<ParaMEDMEM::MEDCoupling1DGTUMesh *>(mesh))
417 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1DGTUMesh,owner);
418 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
419 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
420 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
421 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
422 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
423 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
425 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
429 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
437 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
438 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
439 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
440 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
441 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
442 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
443 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
444 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
445 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
446 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
448 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
452 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
460 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
461 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
462 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
463 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
465 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
469 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
477 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
478 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
479 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
480 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
481 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
482 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
483 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
484 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
486 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
490 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
498 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
499 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
501 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
505 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
507 PyObject *ret=PyList_New(size);
508 for(int i=0;i<size;i++)
509 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
513 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
516 PyObject *ret=PyList_New(size);
517 for(int i=0;i<size;i++)
518 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
522 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
525 PyObject *ret=PyList_New(size);
526 std::set<int>::const_iterator it=v.begin();
527 for(int i=0;i<size;i++,it++)
528 PyList_SetItem(ret,i,PyInt_FromLong(*it));
532 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
534 PyObject *ret=PyList_New(nbOfTuples);
535 for(int i=0;i<nbOfTuples;i++)
537 PyObject *t=PyTuple_New(nbOfComp);
538 for(int j=0;j<nbOfComp;j++)
539 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
540 PyList_SetItem(ret,i,t);
545 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
547 if(PyList_Check(pyLi))
549 *size=PyList_Size(pyLi);
550 int *tmp=new int[*size];
551 for(int i=0;i<*size;i++)
553 PyObject *o=PyList_GetItem(pyLi,i);
556 int val=(int)PyInt_AS_LONG(o);
562 throw INTERP_KERNEL::Exception("list must contain integers only");
567 else if(PyTuple_Check(pyLi))
569 *size=PyTuple_Size(pyLi);
570 int *tmp=new int[*size];
571 for(int i=0;i<*size;i++)
573 PyObject *o=PyTuple_GetItem(pyLi,i);
576 int val=(int)PyInt_AS_LONG(o);
582 throw INTERP_KERNEL::Exception("tuple must contain integers only");
589 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
593 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
595 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
596 if(PyList_Check(pyLi))
598 int size=PyList_Size(pyLi);
600 for(int i=0;i<size;i++)
602 PyObject *o=PyList_GetItem(pyLi,i);
605 int sz2=PyTuple_Size(o);
607 throw INTERP_KERNEL::Exception(msg);
608 PyObject *o_0=PyTuple_GetItem(o,0);
609 if(!PyInt_Check(o_0))
610 throw INTERP_KERNEL::Exception(msg);
611 PyObject *o_1=PyTuple_GetItem(o,1);
612 if(!PyInt_Check(o_1))
613 throw INTERP_KERNEL::Exception(msg);
614 arr[i].first=(int)PyInt_AS_LONG(o_0);
615 arr[i].second=(int)PyInt_AS_LONG(o_1);
618 throw INTERP_KERNEL::Exception(msg);
621 else if(PyTuple_Check(pyLi))
623 int size=PyTuple_Size(pyLi);
625 for(int i=0;i<size;i++)
627 PyObject *o=PyTuple_GetItem(pyLi,i);
630 int sz2=PyTuple_Size(o);
632 throw INTERP_KERNEL::Exception(msg);
633 PyObject *o_0=PyTuple_GetItem(o,0);
634 if(!PyInt_Check(o_0))
635 throw INTERP_KERNEL::Exception(msg);
636 PyObject *o_1=PyTuple_GetItem(o,1);
637 if(!PyInt_Check(o_1))
638 throw INTERP_KERNEL::Exception(msg);
639 arr[i].first=(int)PyInt_AS_LONG(o_0);
640 arr[i].second=(int)PyInt_AS_LONG(o_1);
643 throw INTERP_KERNEL::Exception(msg);
647 throw INTERP_KERNEL::Exception(msg);
650 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
652 if(PyList_Check(pyLi))
654 int size=PyList_Size(pyLi);
656 for(int i=0;i<size;i++)
658 PyObject *o=PyList_GetItem(pyLi,i);
661 int val=(int)PyInt_AS_LONG(o);
665 throw INTERP_KERNEL::Exception("list must contain integers only");
668 else if(PyTuple_Check(pyLi))
670 int size=PyTuple_Size(pyLi);
672 for(int i=0;i<size;i++)
674 PyObject *o=PyTuple_GetItem(pyLi,i);
677 int val=(int)PyInt_AS_LONG(o);
681 throw INTERP_KERNEL::Exception("tuple must contain integers only");
686 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
690 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
693 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
695 if(PyList_Check(pyLi))
697 int size=PyList_Size(pyLi);
698 for(int i=0;i<size;i++)
700 PyObject *o=PyList_GetItem(pyLi,i);
703 int val=(int)PyInt_AS_LONG(o);
708 std::vector<int> arr2;
709 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
710 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
712 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
713 throw INTERP_KERNEL::Exception(oss.str().c_str());
715 arr.insert(arr.end(),arr2.begin(),arr2.end());
719 else if(PyTuple_Check(pyLi))
721 int size=PyTuple_Size(pyLi);
722 for(int i=0;i<size;i++)
724 PyObject *o=PyTuple_GetItem(pyLi,i);
727 int val=(int)PyInt_AS_LONG(o);
732 std::vector<int> arr2;
733 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
734 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
736 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
737 throw INTERP_KERNEL::Exception(oss.str().c_str());
739 arr.insert(arr.end(),arr2.begin(),arr2.end());
744 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
747 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
751 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
752 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
754 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
755 oss << " whereas nb of components expected is " << nbOfComp << " !";
756 throw INTERP_KERNEL::Exception(oss.str().c_str());
763 if((nbOfTuples!=size1 || nbOfComp!=size2))
765 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
767 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
768 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
769 throw INTERP_KERNEL::Exception(oss.str().c_str());
775 if(nbOfTuples==size1)
779 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
780 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
781 throw INTERP_KERNEL::Exception(oss.str().c_str());
787 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
789 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
790 if(PyInt_Check(pyLi))
792 long val=PyInt_AS_LONG(pyLi);
797 throw INTERP_KERNEL::Exception(MSG);
800 else if(PyList_Check(pyLi))
802 int size=PyList_Size(pyLi);
804 for(int i=0;i<size;i++)
806 PyObject *o=PyList_GetItem(pyLi,i);
808 fillArrayWithPyListInt3(o,tmp1,ret);
816 throw INTERP_KERNEL::Exception(MSG);
819 else if(PyTuple_Check(pyLi))
821 int size=PyTuple_Size(pyLi);
823 for(int i=0;i<size;i++)
825 PyObject *o=PyTuple_GetItem(pyLi,i);
827 fillArrayWithPyListInt3(o,tmp1,ret);
835 throw INTERP_KERNEL::Exception(MSG);
839 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
842 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
844 std::vector<int> ret;
845 int size1=-1,size2=-1;
846 if(PyList_Check(pyLi))
848 size1=PyList_Size(pyLi);
849 for(int i=0;i<size1;i++)
851 PyObject *o=PyList_GetItem(pyLi,i);
852 fillArrayWithPyListInt3(o,size2,ret);
857 else if(PyTuple_Check(pyLi))
859 size1=PyTuple_Size(pyLi);
860 for(int i=0;i<size1;i++)
862 PyObject *o=PyTuple_GetItem(pyLi,i);
863 fillArrayWithPyListInt3(o,size2,ret);
869 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
871 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
875 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
877 if(PyList_Check(pyLi))
879 Py_ssize_t sz=PyList_Size(pyLi);
881 for(int i=0;i<sz;i++)
883 PyObject *o=PyList_GetItem(pyLi,i);
884 if(PyString_Check(o))
885 vec[i]=PyString_AsString(o);
891 else if(PyTuple_Check(pyLi))
893 Py_ssize_t sz=PyTuple_Size(pyLi);
895 for(int i=0;i<sz;i++)
897 PyObject *o=PyTuple_GetItem(pyLi,i);
898 if(PyString_Check(o))
899 vec[i]=PyString_AsString(o);
909 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
911 PyObject *ret=PyList_New(size);
912 for(int i=0;i<size;i++)
913 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
917 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
920 PyObject *ret=PyList_New(size);
921 for(int i=0;i<size;i++)
922 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
926 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
928 PyObject *ret=PyList_New(nbOfTuples);
929 for(int i=0;i<nbOfTuples;i++)
931 PyObject *t=PyTuple_New(nbOfComp);
932 for(int j=0;j<nbOfComp;j++)
933 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
934 PyList_SetItem(ret,i,t);
939 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
941 PyObject *ret=PyList_New(nbOfTuples);
942 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
943 for(int i=0;i<nbOfTuples;i++)
945 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
946 PyList_SetItem(ret,i,PyString_FromString(tmp));
951 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
953 if(PyList_Check(pyLi))
955 *size=PyList_Size(pyLi);
956 double *tmp=(double *)malloc((*size)*sizeof(double));
957 for(int i=0;i<*size;i++)
959 PyObject *o=PyList_GetItem(pyLi,i);
962 double val=PyFloat_AS_DOUBLE(o);
965 else if(PyInt_Check(o))
967 long val0=PyInt_AS_LONG(o);
974 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
979 else if(PyTuple_Check(pyLi))
981 *size=PyTuple_Size(pyLi);
982 double *tmp=(double *)malloc((*size)*sizeof(double));
983 for(int i=0;i<*size;i++)
985 PyObject *o=PyTuple_GetItem(pyLi,i);
988 double val=PyFloat_AS_DOUBLE(o);
991 else if(PyInt_Check(o))
993 long val0=PyInt_AS_LONG(o);
1000 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1006 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1009 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1011 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1012 if(PyFloat_Check(pyLi))
1018 throw INTERP_KERNEL::Exception(MSG);
1019 double val=PyFloat_AS_DOUBLE(pyLi);
1022 else if(PyInt_Check(pyLi))
1024 long val0=PyInt_AS_LONG(pyLi);
1030 throw INTERP_KERNEL::Exception(MSG);
1033 else if(PyList_Check(pyLi))
1035 int size=PyList_Size(pyLi);
1037 for(int i=0;i<size;i++)
1039 PyObject *o=PyList_GetItem(pyLi,i);
1041 fillArrayWithPyListDbl3(o,tmp1,ret);
1049 throw INTERP_KERNEL::Exception(MSG);
1052 else if(PyTuple_Check(pyLi))
1054 int size=PyTuple_Size(pyLi);
1056 for(int i=0;i<size;i++)
1058 PyObject *o=PyTuple_GetItem(pyLi,i);
1060 fillArrayWithPyListDbl3(o,tmp1,ret);
1068 throw INTERP_KERNEL::Exception(MSG);
1072 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1075 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1077 std::vector<double> ret;
1078 int size1=-1,size2=-1;
1079 if(PyList_Check(pyLi))
1081 size1=PyList_Size(pyLi);
1082 for(int i=0;i<size1;i++)
1084 PyObject *o=PyList_GetItem(pyLi,i);
1085 fillArrayWithPyListDbl3(o,size2,ret);
1090 else if(PyTuple_Check(pyLi))
1092 size1=PyTuple_Size(pyLi);
1093 for(int i=0;i<size1;i++)
1095 PyObject *o=PyTuple_GetItem(pyLi,i);
1096 fillArrayWithPyListDbl3(o,size2,ret);
1102 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1104 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1108 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1110 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1113 if(PyList_Check(pyLi))
1115 int size=PyList_Size(pyLi);
1117 for(int i=0;i<size;i++)
1119 PyObject *obj=PyList_GetItem(pyLi,i);
1120 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1121 if(!SWIG_IsOK(status))
1123 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1124 throw INTERP_KERNEL::Exception(oss.str().c_str());
1126 T arg=reinterpret_cast< T >(argp);
1130 else if(PyTuple_Check(pyLi))
1132 int size=PyTuple_Size(pyLi);
1134 for(int i=0;i<size;i++)
1136 PyObject *obj=PyTuple_GetItem(pyLi,i);
1137 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1138 if(!SWIG_IsOK(status))
1140 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1141 throw INTERP_KERNEL::Exception(oss.str().c_str());
1143 T arg=reinterpret_cast< T >(argp);
1147 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1150 T arg=reinterpret_cast< T >(argp);
1154 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1158 * if python int -> cpp int sw=1
1159 * if python list[int] -> cpp vector<int> sw=2
1160 * if python tuple[int] -> cpp vector<int> sw=2
1161 * if python DataArrayInt -> cpp DataArrayInt sw=3
1162 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1164 * switch between (int,vector<int>,DataArrayInt)
1166 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1169 if(PyInt_Check(value))
1171 iTyypp=(int)PyInt_AS_LONG(value);
1175 if(PyTuple_Check(value))
1177 int size=PyTuple_Size(value);
1178 stdvecTyypp.resize(size);
1179 for(int i=0;i<size;i++)
1181 PyObject *o=PyTuple_GetItem(value,i);
1183 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1186 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1187 throw INTERP_KERNEL::Exception(oss.str().c_str());
1193 if(PyList_Check(value))
1195 int size=PyList_Size(value);
1196 stdvecTyypp.resize(size);
1197 for(int i=0;i<size;i++)
1199 PyObject *o=PyList_GetItem(value,i);
1201 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1204 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1205 throw INTERP_KERNEL::Exception(oss.str().c_str());
1212 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1213 if(SWIG_IsOK(status))
1215 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1219 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1220 if(SWIG_IsOK(status))
1222 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1226 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1230 * if python double -> cpp double sw=1
1231 * if python int -> cpp double sw=1
1232 * if python list[double] -> cpp vector<double> sw=2
1233 * if python list[int] -> cpp vector<double> sw=2
1234 * if python tuple[double] -> cpp vector<double> sw=2
1235 * if python tuple[int] -> cpp vector<double> sw=2
1236 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1238 * switch between (int,vector<int>,DataArrayInt)
1240 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1243 if(PyFloat_Check(value))
1245 iTyypp=PyFloat_AS_DOUBLE(value);
1249 if(PyInt_Check(value))
1251 iTyypp=(double)PyInt_AS_LONG(value);
1255 if(PyTuple_Check(value))
1257 int size=PyTuple_Size(value);
1258 stdvecTyypp.resize(size);
1259 for(int i=0;i<size;i++)
1261 PyObject *o=PyTuple_GetItem(value,i);
1262 if(PyFloat_Check(o))
1263 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1264 else if(PyInt_Check(o))
1265 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1268 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1269 throw INTERP_KERNEL::Exception(oss.str().c_str());
1275 if(PyList_Check(value))
1277 int size=PyList_Size(value);
1278 stdvecTyypp.resize(size);
1279 for(int i=0;i<size;i++)
1281 PyObject *o=PyList_GetItem(value,i);
1282 if(PyFloat_Check(o))
1283 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1284 else if(PyInt_Check(o))
1285 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1288 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1289 throw INTERP_KERNEL::Exception(oss.str().c_str());
1296 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1297 if(!SWIG_IsOK(status))
1298 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1299 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1304 * if python double -> cpp double sw=1
1305 * if python int -> cpp double sw=1
1306 * if python list[double] -> cpp vector<double> sw=2
1307 * if python list[int] -> cpp vector<double> sw=2
1308 * if python tuple[double] -> cpp vector<double> sw=2
1309 * if python tuple[int] -> cpp vector<double> sw=2
1310 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1312 * switch between (int,vector<int>,DataArrayInt)
1314 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1317 if(PyFloat_Check(value))
1319 iTyypp=PyFloat_AS_DOUBLE(value);
1323 if(PyInt_Check(value))
1325 iTyypp=(double)PyInt_AS_LONG(value);
1329 if(PyTuple_Check(value))
1331 int size=PyTuple_Size(value);
1332 stdvecTyypp.resize(size);
1333 for(int i=0;i<size;i++)
1335 PyObject *o=PyTuple_GetItem(value,i);
1336 if(PyFloat_Check(o))
1337 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1338 else if(PyInt_Check(o))
1339 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1342 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1343 throw INTERP_KERNEL::Exception(oss.str().c_str());
1349 if(PyList_Check(value))
1351 int size=PyList_Size(value);
1352 stdvecTyypp.resize(size);
1353 for(int i=0;i<size;i++)
1355 PyObject *o=PyList_GetItem(value,i);
1356 if(PyFloat_Check(o))
1357 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1358 else if(PyInt_Check(o))
1359 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1362 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1363 throw INTERP_KERNEL::Exception(oss.str().c_str());
1370 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1371 if(!SWIG_IsOK(status))
1372 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1373 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1378 * if python int -> cpp int sw=1
1379 * if python list[int] -> cpp vector<int> sw=2
1380 * if python tuple[int] -> cpp vector<int> sw=2
1381 * if python slicp -> cpp pair sw=3 (begin,end,step)
1382 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1384 * switch between (int,vector<int>,DataArrayInt)
1386 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)
1388 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1390 if(PyInt_Check(value))
1392 iTyypp=(int)PyInt_AS_LONG(value);
1396 if(PyTuple_Check(value))
1398 int size=PyTuple_Size(value);
1399 stdvecTyypp.resize(size);
1400 for(int i=0;i<size;i++)
1402 PyObject *o=PyTuple_GetItem(value,i);
1404 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1407 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1408 throw INTERP_KERNEL::Exception(oss.str().c_str());
1414 if(PyList_Check(value))
1416 int size=PyList_Size(value);
1417 stdvecTyypp.resize(size);
1418 for(int i=0;i<size;i++)
1420 PyObject *o=PyList_GetItem(value,i);
1422 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1425 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1426 throw INTERP_KERNEL::Exception(oss.str().c_str());
1432 if(PySlice_Check(value))
1434 Py_ssize_t strt=2,stp=2,step=2;
1435 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1436 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1437 if(nbelem!=0 || strt!=0 || stp!=0)
1439 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1440 throw INTERP_KERNEL::Exception(oss.str().c_str());
1444 p.second.second=step;
1449 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1450 if(SWIG_IsOK(status))
1452 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1455 std::ostringstream oss; oss << msg << " Instance in null !";
1456 throw INTERP_KERNEL::Exception(oss.str().c_str());
1461 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1462 if(SWIG_IsOK(status))
1464 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1467 std::ostringstream oss; oss << msg << " Instance in null !";
1468 throw INTERP_KERNEL::Exception(oss.str().c_str());
1470 stdvecTyypp.resize(tmp->getNumberOfCompo());
1471 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1475 throw INTERP_KERNEL::Exception(msg);
1479 * if python int -> cpp int sw=1
1480 * if python tuple[int] -> cpp vector<int> sw=2
1481 * if python list[int] -> cpp vector<int> sw=2
1482 * if python slice -> cpp pair sw=3
1483 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1485 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)
1488 if(PyInt_Check(value))
1490 iTyypp=(int)PyInt_AS_LONG(value);
1494 if(PyTuple_Check(value))
1496 int size=PyTuple_Size(value);
1497 stdvecTyypp.resize(size);
1498 for(int i=0;i<size;i++)
1500 PyObject *o=PyTuple_GetItem(value,i);
1502 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1505 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1506 throw INTERP_KERNEL::Exception(oss.str().c_str());
1512 if(PyList_Check(value))
1514 int size=PyList_Size(value);
1515 stdvecTyypp.resize(size);
1516 for(int i=0;i<size;i++)
1518 PyObject *o=PyList_GetItem(value,i);
1520 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1523 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1524 throw INTERP_KERNEL::Exception(oss.str().c_str());
1530 if(PySlice_Check(value))
1532 Py_ssize_t strt=2,stp=2,step=2;
1533 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1534 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1535 if(nbelem!=0 || strt!=0 || stp!=0)
1537 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1538 throw INTERP_KERNEL::Exception(oss.str().c_str());
1542 p.second.second=step;
1547 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1548 if(!SWIG_IsOK(status))
1549 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1550 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1555 * if python string with size one -> cpp char sw=1
1556 * if python string with size different from one -> cpp string sw=2
1557 * if python tuple[string] or list[string] -> vector<string> sw=3
1558 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1559 * switch between (int,string,vector<string>,DataArrayChar)
1561 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1563 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1565 if(PyString_Check(value))
1567 const char *pt=PyString_AsString(value);
1568 Py_ssize_t sz=PyString_Size(value);
1582 if(PyTuple_Check(value))
1584 int size=PyTuple_Size(value);
1585 vsType.resize(size);
1586 for(int i=0;i<size;i++)
1588 PyObject *o=PyTuple_GetItem(value,i);
1589 if(PyString_Check(o))
1590 vsType[i]=PyString_AsString(o);
1593 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1594 throw INTERP_KERNEL::Exception(oss.str().c_str());
1600 if(PyList_Check(value))
1602 int size=PyList_Size(value);
1603 vsType.resize(size);
1604 for(int i=0;i<size;i++)
1606 PyObject *o=PyList_GetItem(value,i);
1607 if(PyString_Check(o))
1608 vsType[i]=PyString_AsString(o);
1611 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1612 throw INTERP_KERNEL::Exception(oss.str().c_str());
1619 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1620 if(SWIG_IsOK(status))
1622 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1625 std::ostringstream oss; oss << msg << " Instance in null !";
1626 throw INTERP_KERNEL::Exception(oss.str().c_str());
1631 throw INTERP_KERNEL::Exception(msg);
1635 * if value int -> cpp it sw=1
1636 * if value list[int] -> vt sw=2
1637 * if value tuple[int] -> vt sw=2
1638 * if value slice -> pt sw=3
1639 * if value DataArrayInt -> dt sw=4
1640 * if value tuple [int,int] -> cpp it,ip sw=5
1641 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1642 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1643 * if value tuple [slice,int] -> cpp pt,ip sw=7
1644 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1645 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1646 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1647 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1648 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1649 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1650 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1651 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1652 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1653 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1654 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1655 * if value tuple [int,slice] -> cpp it,pc sw=13
1656 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1657 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1658 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1659 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1661 * switch between (int,vector<int>,DataArrayInt)
1663 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1664 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1665 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1667 if(!PyTuple_Check(value))
1669 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1674 int sz=PyTuple_Size(value);
1676 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1677 PyObject *ob0=PyTuple_GetItem(value,0);
1679 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1680 PyObject *ob1=PyTuple_GetItem(value,1);
1681 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1687 * if value int -> cpp val sw=1
1688 * if value double -> cpp val sw=1
1689 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1690 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1691 * if value list[int,double] -> cpp std::vector<double> sw=4
1692 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1694 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1697 if(PyFloat_Check(value))
1699 val=PyFloat_AS_DOUBLE(value);
1703 if(PyInt_Check(value))
1705 val=(double)PyInt_AS_LONG(value);
1709 if(PyTuple_Check(value))
1711 int size=PyTuple_Size(value);
1713 for(int i=0;i<size;i++)
1715 PyObject *o=PyTuple_GetItem(value,i);
1716 if(PyFloat_Check(o))
1717 f[i]=PyFloat_AS_DOUBLE(o);
1718 else if(PyInt_Check(o))
1719 f[i]=(double)PyInt_AS_LONG(o);
1722 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1723 throw INTERP_KERNEL::Exception(oss.str().c_str());
1729 if(PyList_Check(value))
1731 int size=PyList_Size(value);
1733 for(int i=0;i<size;i++)
1735 PyObject *o=PyList_GetItem(value,i);
1736 if(PyFloat_Check(o))
1737 f[i]=PyFloat_AS_DOUBLE(o);
1738 else if(PyInt_Check(o))
1739 f[i]=(double)PyInt_AS_LONG(o);
1742 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1743 throw INTERP_KERNEL::Exception(oss.str().c_str());
1750 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1751 if(SWIG_IsOK(status))
1753 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1757 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1758 if(SWIG_IsOK(status))
1760 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1764 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1768 * if value int -> cpp val sw=1
1769 * if value double -> cpp val sw=1
1770 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1771 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1772 * if value list[int,double] -> cpp std::vector<double> sw=4
1773 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1775 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1776 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1779 if(PyFloat_Check(value))
1781 val=PyFloat_AS_DOUBLE(value);
1783 if(nbTuplesExpected*nbCompExpected!=1)
1785 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1786 throw INTERP_KERNEL::Exception(oss.str().c_str());
1790 if(PyInt_Check(value))
1792 val=(double)PyInt_AS_LONG(value);
1794 if(nbTuplesExpected*nbCompExpected!=1)
1796 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1797 throw INTERP_KERNEL::Exception(oss.str().c_str());
1801 if(PyTuple_Check(value) || PyList_Check(value))
1805 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1806 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1811 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1814 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1815 if(SWIG_IsOK(status))
1817 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1821 if(d->getNumberOfTuples()==nbTuplesExpected)
1823 if(d->getNumberOfComponents()==nbCompExpected)
1825 return d->getConstPointer();
1829 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1830 throw INTERP_KERNEL::Exception(oss.str().c_str());
1835 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1836 throw INTERP_KERNEL::Exception(oss.str().c_str());
1843 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1844 throw INTERP_KERNEL::Exception(oss.str().c_str());
1850 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1851 if(SWIG_IsOK(status))
1853 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1855 if(e->getNumberOfCompo()==nbCompExpected)
1857 if(nbTuplesExpected==1)
1858 return e->getConstPointer();
1861 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1862 throw INTERP_KERNEL::Exception(oss.str().c_str());
1867 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1868 throw INTERP_KERNEL::Exception(oss.str().c_str());
1871 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1875 * if value int -> cpp val sw=1
1876 * if value double -> cpp val sw=1
1877 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1878 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1879 * if value list[int,double] -> cpp std::vector<double> sw=4
1880 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1882 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1883 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1886 if(PyFloat_Check(value))
1888 val=PyFloat_AS_DOUBLE(value);
1890 if(nbCompExpected!=1)
1892 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1893 throw INTERP_KERNEL::Exception(oss.str().c_str());
1898 if(PyInt_Check(value))
1900 val=(double)PyInt_AS_LONG(value);
1902 if(nbCompExpected!=1)
1904 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1905 throw INTERP_KERNEL::Exception(oss.str().c_str());
1910 if(PyTuple_Check(value))
1912 int size=PyTuple_Size(value);
1914 for(int i=0;i<size;i++)
1916 PyObject *o=PyTuple_GetItem(value,i);
1917 if(PyFloat_Check(o))
1918 f[i]=PyFloat_AS_DOUBLE(o);
1919 else if(PyInt_Check(o))
1920 f[i]=(double)PyInt_AS_LONG(o);
1923 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1924 throw INTERP_KERNEL::Exception(oss.str().c_str());
1928 if(size%nbCompExpected!=0)
1930 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1931 throw INTERP_KERNEL::Exception(oss.str().c_str());
1933 nbTuples=size/nbCompExpected;
1936 if(PyList_Check(value))
1938 int size=PyList_Size(value);
1940 for(int i=0;i<size;i++)
1942 PyObject *o=PyList_GetItem(value,i);
1943 if(PyFloat_Check(o))
1944 f[i]=PyFloat_AS_DOUBLE(o);
1945 else if(PyInt_Check(o))
1946 f[i]=(double)PyInt_AS_LONG(o);
1949 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1950 throw INTERP_KERNEL::Exception(oss.str().c_str());
1954 if(size%nbCompExpected!=0)
1956 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1957 throw INTERP_KERNEL::Exception(oss.str().c_str());
1959 nbTuples=size/nbCompExpected;
1963 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1964 if(SWIG_IsOK(status))
1966 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1970 if(d->getNumberOfComponents()==nbCompExpected)
1972 nbTuples=d->getNumberOfTuples();
1973 return d->getConstPointer();
1977 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1978 throw INTERP_KERNEL::Exception(oss.str().c_str());
1985 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1986 throw INTERP_KERNEL::Exception(oss.str().c_str());
1989 { nbTuples=0; return 0; }
1992 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1993 if(SWIG_IsOK(status))
1995 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1999 if(e->getNumberOfCompo()==nbCompExpected)
2002 return e->getConstPointer();
2006 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2007 throw INTERP_KERNEL::Exception(oss.str().c_str());
2014 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2015 throw INTERP_KERNEL::Exception(oss.str().c_str());
2018 { nbTuples=0; return 0; }
2021 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2025 * if value int -> cpp val sw=1
2026 * if value double -> cpp val sw=1
2027 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2028 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2029 * if value list[int,double] -> cpp std::vector<double> sw=4
2030 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2032 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2033 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2035 ParaMEDMEM::DataArrayDouble *d=0;
2036 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2038 if(PyFloat_Check(value))
2040 val=PyFloat_AS_DOUBLE(value);
2045 if(PyInt_Check(value))
2047 val=(double)PyInt_AS_LONG(value);
2052 if(PyTuple_Check(value))
2054 int size=PyTuple_Size(value);
2056 for(int i=0;i<size;i++)
2058 PyObject *o=PyTuple_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 << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2066 throw INTERP_KERNEL::Exception(oss.str().c_str());
2073 if(PyList_Check(value))
2075 int size=PyList_Size(value);
2077 for(int i=0;i<size;i++)
2079 PyObject *o=PyList_GetItem(value,i);
2080 if(PyFloat_Check(o))
2081 f[i]=PyFloat_AS_DOUBLE(o);
2082 else if(PyInt_Check(o))
2083 f[i]=(double)PyInt_AS_LONG(o);
2086 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2087 throw INTERP_KERNEL::Exception(oss.str().c_str());
2095 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2096 if(SWIG_IsOK(status))
2098 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2102 if(d->getNumberOfComponents()==1)
2104 nbTuples=d->getNumberOfTuples();
2105 return d->getConstPointer();
2109 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2110 throw INTERP_KERNEL::Exception(oss.str().c_str());
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 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2125 if(SWIG_IsOK(status))
2127 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2131 nbTuples=e->getNumberOfCompo();
2132 return e->getConstPointer();
2138 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2139 throw INTERP_KERNEL::Exception(oss.str().c_str());
2142 { nbTuples=0; return 0; }
2145 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2149 * if python int -> cpp int sw=1
2150 * if python list[int] -> cpp vector<int> sw=2
2151 * if python tuple[int] -> cpp vector<int> sw=2
2152 * if python DataArrayInt -> cpp DataArrayInt sw=3
2153 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2155 * switch between (int,vector<int>,DataArrayInt)
2157 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2160 if(PyInt_Check(value))
2162 iTyypp=(int)PyInt_AS_LONG(value);
2166 if(PyTuple_Check(value))
2168 int size=PyTuple_Size(value);
2169 stdvecTyypp.resize(size);
2170 for(int i=0;i<size;i++)
2172 PyObject *o=PyTuple_GetItem(value,i);
2174 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2177 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2178 throw INTERP_KERNEL::Exception(oss.str().c_str());
2182 return &stdvecTyypp[0];
2184 if(PyList_Check(value))
2186 int size=PyList_Size(value);
2187 stdvecTyypp.resize(size);
2188 for(int i=0;i<size;i++)
2190 PyObject *o=PyList_GetItem(value,i);
2192 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2195 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2196 throw INTERP_KERNEL::Exception(oss.str().c_str());
2200 return &stdvecTyypp[0];
2203 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2204 if(SWIG_IsOK(status))
2206 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2209 sw=3; sz=daIntTyypp->getNbOfElems();
2210 return daIntTyypp->begin();
2218 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2219 if(SWIG_IsOK(status))
2221 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2222 sw=4; sz=daIntTuple->getNumberOfCompo();
2223 return daIntTuple->getConstPointer();
2225 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2228 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2230 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.";
2231 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2234 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2236 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2238 return (*self)+(*other);
2240 throw INTERP_KERNEL::Exception(msg);
2244 ParaMEDMEM::DataArrayDouble *a;
2245 ParaMEDMEM::DataArrayDoubleTuple *aa;
2246 std::vector<double> bb;
2248 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2253 if(!self->getArray())
2254 throw INTERP_KERNEL::Exception(msg2);
2255 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2256 ret->applyLin(1.,val);
2257 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2258 ret2->setArray(ret);
2263 if(!self->getArray())
2264 throw INTERP_KERNEL::Exception(msg2);
2265 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2266 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2267 ret2->setArray(ret);
2272 if(!self->getArray())
2273 throw INTERP_KERNEL::Exception(msg2);
2274 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2275 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2276 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2277 ret2->setArray(ret);
2282 if(!self->getArray())
2283 throw INTERP_KERNEL::Exception(msg2);
2284 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2285 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2286 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2287 ret2->setArray(ret);
2291 { throw INTERP_KERNEL::Exception(msg); }
2295 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2297 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2300 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2302 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.";
2303 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2306 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2308 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2310 return (*other)-(*self);
2312 throw INTERP_KERNEL::Exception(msg);
2316 ParaMEDMEM::DataArrayDouble *a;
2317 ParaMEDMEM::DataArrayDoubleTuple *aa;
2318 std::vector<double> bb;
2320 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2325 if(!self->getArray())
2326 throw INTERP_KERNEL::Exception(msg2);
2327 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2328 ret->applyLin(-1.,val);
2329 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2330 ret2->setArray(ret);
2335 if(!self->getArray())
2336 throw INTERP_KERNEL::Exception(msg2);
2337 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2338 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2339 ret2->setArray(ret);
2344 if(!self->getArray())
2345 throw INTERP_KERNEL::Exception(msg2);
2346 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2347 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2348 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2349 ret2->setArray(ret);
2354 if(!self->getArray())
2355 throw INTERP_KERNEL::Exception(msg2);
2356 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2357 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2358 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2359 ret2->setArray(ret);
2363 { throw INTERP_KERNEL::Exception(msg); }
2367 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2369 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.";
2370 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2373 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2375 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2377 return (*self)*(*other);
2379 throw INTERP_KERNEL::Exception(msg);
2383 ParaMEDMEM::DataArrayDouble *a;
2384 ParaMEDMEM::DataArrayDoubleTuple *aa;
2385 std::vector<double> bb;
2387 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2392 if(!self->getArray())
2393 throw INTERP_KERNEL::Exception(msg2);
2394 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2395 ret->applyLin(val,0.);
2396 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2397 ret2->setArray(ret);
2402 if(!self->getArray())
2403 throw INTERP_KERNEL::Exception(msg2);
2404 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2405 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2406 ret2->setArray(ret);
2411 if(!self->getArray())
2412 throw INTERP_KERNEL::Exception(msg2);
2413 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2414 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2415 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2416 ret2->setArray(ret);
2421 if(!self->getArray())
2422 throw INTERP_KERNEL::Exception(msg2);
2423 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2424 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2425 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2426 ret2->setArray(ret);
2430 { throw INTERP_KERNEL::Exception(msg); }
2434 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2436 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2439 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2441 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.";
2442 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2445 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2447 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2449 return (*other)/(*self);
2451 throw INTERP_KERNEL::Exception(msg);
2455 ParaMEDMEM::DataArrayDouble *a;
2456 ParaMEDMEM::DataArrayDoubleTuple *aa;
2457 std::vector<double> bb;
2459 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2464 if(!self->getArray())
2465 throw INTERP_KERNEL::Exception(msg2);
2466 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2468 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2469 ret2->setArray(ret);
2474 if(!self->getArray())
2475 throw INTERP_KERNEL::Exception(msg2);
2476 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2477 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2478 ret2->setArray(ret);
2483 if(!self->getArray())
2484 throw INTERP_KERNEL::Exception(msg2);
2485 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2486 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2487 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2488 ret2->setArray(ret);
2493 if(!self->getArray())
2494 throw INTERP_KERNEL::Exception(msg2);
2495 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2496 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2497 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2498 ret2->setArray(ret);
2502 { throw INTERP_KERNEL::Exception(msg); }
2506 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2509 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2510 if(!SWIG_IsOK(status))
2512 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2513 if(!SWIG_IsOK(status))
2515 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2516 if(!SWIG_IsOK(status))
2518 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2519 if(!SWIG_IsOK(status))
2521 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2522 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2523 throw INTERP_KERNEL::Exception(oss.str().c_str());
2528 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);