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::MEDCoupling1SGTUMesh *>(mesh))
421 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1SGTUMesh,owner);
422 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
423 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
424 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
425 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
426 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
427 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
429 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
433 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
441 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
442 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
443 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
444 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
445 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
446 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
447 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
448 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
449 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
450 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
452 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
456 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
464 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
465 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
466 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
467 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
469 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
473 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
481 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
482 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
483 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
484 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
485 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
486 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
487 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
488 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
490 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
494 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
502 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
503 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
505 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
509 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
511 PyObject *ret=PyList_New(size);
512 for(int i=0;i<size;i++)
513 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
517 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
520 PyObject *ret=PyList_New(size);
521 for(int i=0;i<size;i++)
522 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
526 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
529 PyObject *ret=PyList_New(size);
530 std::set<int>::const_iterator it=v.begin();
531 for(int i=0;i<size;i++,it++)
532 PyList_SetItem(ret,i,PyInt_FromLong(*it));
536 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
538 PyObject *ret=PyList_New(nbOfTuples);
539 for(int i=0;i<nbOfTuples;i++)
541 PyObject *t=PyTuple_New(nbOfComp);
542 for(int j=0;j<nbOfComp;j++)
543 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
544 PyList_SetItem(ret,i,t);
549 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
551 if(PyList_Check(pyLi))
553 *size=PyList_Size(pyLi);
554 int *tmp=new int[*size];
555 for(int i=0;i<*size;i++)
557 PyObject *o=PyList_GetItem(pyLi,i);
560 int val=(int)PyInt_AS_LONG(o);
566 throw INTERP_KERNEL::Exception("list must contain integers only");
571 else if(PyTuple_Check(pyLi))
573 *size=PyTuple_Size(pyLi);
574 int *tmp=new int[*size];
575 for(int i=0;i<*size;i++)
577 PyObject *o=PyTuple_GetItem(pyLi,i);
580 int val=(int)PyInt_AS_LONG(o);
586 throw INTERP_KERNEL::Exception("tuple must contain integers only");
593 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
597 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
599 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
600 if(PyList_Check(pyLi))
602 int size=PyList_Size(pyLi);
604 for(int i=0;i<size;i++)
606 PyObject *o=PyList_GetItem(pyLi,i);
609 int sz2=PyTuple_Size(o);
611 throw INTERP_KERNEL::Exception(msg);
612 PyObject *o_0=PyTuple_GetItem(o,0);
613 if(!PyInt_Check(o_0))
614 throw INTERP_KERNEL::Exception(msg);
615 PyObject *o_1=PyTuple_GetItem(o,1);
616 if(!PyInt_Check(o_1))
617 throw INTERP_KERNEL::Exception(msg);
618 arr[i].first=(int)PyInt_AS_LONG(o_0);
619 arr[i].second=(int)PyInt_AS_LONG(o_1);
622 throw INTERP_KERNEL::Exception(msg);
625 else if(PyTuple_Check(pyLi))
627 int size=PyTuple_Size(pyLi);
629 for(int i=0;i<size;i++)
631 PyObject *o=PyTuple_GetItem(pyLi,i);
634 int sz2=PyTuple_Size(o);
636 throw INTERP_KERNEL::Exception(msg);
637 PyObject *o_0=PyTuple_GetItem(o,0);
638 if(!PyInt_Check(o_0))
639 throw INTERP_KERNEL::Exception(msg);
640 PyObject *o_1=PyTuple_GetItem(o,1);
641 if(!PyInt_Check(o_1))
642 throw INTERP_KERNEL::Exception(msg);
643 arr[i].first=(int)PyInt_AS_LONG(o_0);
644 arr[i].second=(int)PyInt_AS_LONG(o_1);
647 throw INTERP_KERNEL::Exception(msg);
651 throw INTERP_KERNEL::Exception(msg);
654 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
656 if(PyList_Check(pyLi))
658 int size=PyList_Size(pyLi);
660 for(int i=0;i<size;i++)
662 PyObject *o=PyList_GetItem(pyLi,i);
665 int val=(int)PyInt_AS_LONG(o);
669 throw INTERP_KERNEL::Exception("list must contain integers only");
672 else if(PyTuple_Check(pyLi))
674 int size=PyTuple_Size(pyLi);
676 for(int i=0;i<size;i++)
678 PyObject *o=PyTuple_GetItem(pyLi,i);
681 int val=(int)PyInt_AS_LONG(o);
685 throw INTERP_KERNEL::Exception("tuple must contain integers only");
690 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
694 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
697 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
699 if(PyList_Check(pyLi))
701 int size=PyList_Size(pyLi);
702 for(int i=0;i<size;i++)
704 PyObject *o=PyList_GetItem(pyLi,i);
707 int val=(int)PyInt_AS_LONG(o);
712 std::vector<int> arr2;
713 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
714 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
716 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
717 throw INTERP_KERNEL::Exception(oss.str().c_str());
719 arr.insert(arr.end(),arr2.begin(),arr2.end());
723 else if(PyTuple_Check(pyLi))
725 int size=PyTuple_Size(pyLi);
726 for(int i=0;i<size;i++)
728 PyObject *o=PyTuple_GetItem(pyLi,i);
731 int val=(int)PyInt_AS_LONG(o);
736 std::vector<int> arr2;
737 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
738 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
740 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
741 throw INTERP_KERNEL::Exception(oss.str().c_str());
743 arr.insert(arr.end(),arr2.begin(),arr2.end());
748 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
751 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
755 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
756 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
758 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
759 oss << " whereas nb of components expected is " << nbOfComp << " !";
760 throw INTERP_KERNEL::Exception(oss.str().c_str());
767 if((nbOfTuples!=size1 || nbOfComp!=size2))
769 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
771 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
772 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
773 throw INTERP_KERNEL::Exception(oss.str().c_str());
779 if(nbOfTuples==size1)
783 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
784 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
785 throw INTERP_KERNEL::Exception(oss.str().c_str());
791 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
793 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
794 if(PyInt_Check(pyLi))
796 long val=PyInt_AS_LONG(pyLi);
801 throw INTERP_KERNEL::Exception(MSG);
804 else if(PyList_Check(pyLi))
806 int size=PyList_Size(pyLi);
808 for(int i=0;i<size;i++)
810 PyObject *o=PyList_GetItem(pyLi,i);
812 fillArrayWithPyListInt3(o,tmp1,ret);
820 throw INTERP_KERNEL::Exception(MSG);
823 else if(PyTuple_Check(pyLi))
825 int size=PyTuple_Size(pyLi);
827 for(int i=0;i<size;i++)
829 PyObject *o=PyTuple_GetItem(pyLi,i);
831 fillArrayWithPyListInt3(o,tmp1,ret);
839 throw INTERP_KERNEL::Exception(MSG);
843 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
846 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
848 std::vector<int> ret;
849 int size1=-1,size2=-1;
850 if(PyList_Check(pyLi))
852 size1=PyList_Size(pyLi);
853 for(int i=0;i<size1;i++)
855 PyObject *o=PyList_GetItem(pyLi,i);
856 fillArrayWithPyListInt3(o,size2,ret);
861 else if(PyTuple_Check(pyLi))
863 size1=PyTuple_Size(pyLi);
864 for(int i=0;i<size1;i++)
866 PyObject *o=PyTuple_GetItem(pyLi,i);
867 fillArrayWithPyListInt3(o,size2,ret);
873 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
875 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
879 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
881 if(PyList_Check(pyLi))
883 Py_ssize_t sz=PyList_Size(pyLi);
885 for(int i=0;i<sz;i++)
887 PyObject *o=PyList_GetItem(pyLi,i);
888 if(PyString_Check(o))
889 vec[i]=PyString_AsString(o);
895 else if(PyTuple_Check(pyLi))
897 Py_ssize_t sz=PyTuple_Size(pyLi);
899 for(int i=0;i<sz;i++)
901 PyObject *o=PyTuple_GetItem(pyLi,i);
902 if(PyString_Check(o))
903 vec[i]=PyString_AsString(o);
913 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
915 PyObject *ret=PyList_New(size);
916 for(int i=0;i<size;i++)
917 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
921 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
924 PyObject *ret=PyList_New(size);
925 for(int i=0;i<size;i++)
926 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
930 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
932 PyObject *ret=PyList_New(nbOfTuples);
933 for(int i=0;i<nbOfTuples;i++)
935 PyObject *t=PyTuple_New(nbOfComp);
936 for(int j=0;j<nbOfComp;j++)
937 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
938 PyList_SetItem(ret,i,t);
943 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
945 PyObject *ret=PyList_New(nbOfTuples);
946 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
947 for(int i=0;i<nbOfTuples;i++)
949 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
950 PyList_SetItem(ret,i,PyString_FromString(tmp));
955 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
957 if(PyList_Check(pyLi))
959 *size=PyList_Size(pyLi);
960 double *tmp=(double *)malloc((*size)*sizeof(double));
961 for(int i=0;i<*size;i++)
963 PyObject *o=PyList_GetItem(pyLi,i);
966 double val=PyFloat_AS_DOUBLE(o);
969 else if(PyInt_Check(o))
971 long val0=PyInt_AS_LONG(o);
978 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
983 else if(PyTuple_Check(pyLi))
985 *size=PyTuple_Size(pyLi);
986 double *tmp=(double *)malloc((*size)*sizeof(double));
987 for(int i=0;i<*size;i++)
989 PyObject *o=PyTuple_GetItem(pyLi,i);
992 double val=PyFloat_AS_DOUBLE(o);
995 else if(PyInt_Check(o))
997 long val0=PyInt_AS_LONG(o);
1004 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1010 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1013 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1015 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1016 if(PyFloat_Check(pyLi))
1022 throw INTERP_KERNEL::Exception(MSG);
1023 double val=PyFloat_AS_DOUBLE(pyLi);
1026 else if(PyInt_Check(pyLi))
1028 long val0=PyInt_AS_LONG(pyLi);
1034 throw INTERP_KERNEL::Exception(MSG);
1037 else if(PyList_Check(pyLi))
1039 int size=PyList_Size(pyLi);
1041 for(int i=0;i<size;i++)
1043 PyObject *o=PyList_GetItem(pyLi,i);
1045 fillArrayWithPyListDbl3(o,tmp1,ret);
1053 throw INTERP_KERNEL::Exception(MSG);
1056 else if(PyTuple_Check(pyLi))
1058 int size=PyTuple_Size(pyLi);
1060 for(int i=0;i<size;i++)
1062 PyObject *o=PyTuple_GetItem(pyLi,i);
1064 fillArrayWithPyListDbl3(o,tmp1,ret);
1072 throw INTERP_KERNEL::Exception(MSG);
1076 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1079 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1081 std::vector<double> ret;
1082 int size1=-1,size2=-1;
1083 if(PyList_Check(pyLi))
1085 size1=PyList_Size(pyLi);
1086 for(int i=0;i<size1;i++)
1088 PyObject *o=PyList_GetItem(pyLi,i);
1089 fillArrayWithPyListDbl3(o,size2,ret);
1094 else if(PyTuple_Check(pyLi))
1096 size1=PyTuple_Size(pyLi);
1097 for(int i=0;i<size1;i++)
1099 PyObject *o=PyTuple_GetItem(pyLi,i);
1100 fillArrayWithPyListDbl3(o,size2,ret);
1106 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1108 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1112 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1114 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1117 if(PyList_Check(pyLi))
1119 int size=PyList_Size(pyLi);
1121 for(int i=0;i<size;i++)
1123 PyObject *obj=PyList_GetItem(pyLi,i);
1124 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1125 if(!SWIG_IsOK(status))
1126 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
1127 T arg=reinterpret_cast< T >(argp);
1131 else if(PyTuple_Check(pyLi))
1133 int size=PyTuple_Size(pyLi);
1135 for(int i=0;i<size;i++)
1137 PyObject *obj=PyTuple_GetItem(pyLi,i);
1138 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1139 if(!SWIG_IsOK(status))
1141 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
1142 throw INTERP_KERNEL::Exception(oss.str().c_str());
1144 T arg=reinterpret_cast< T >(argp);
1148 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1151 T arg=reinterpret_cast< T >(argp);
1155 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1159 * if python int -> cpp int sw=1
1160 * if python list[int] -> cpp vector<int> sw=2
1161 * if python tuple[int] -> cpp vector<int> sw=2
1162 * if python DataArrayInt -> cpp DataArrayInt sw=3
1163 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1165 * switch between (int,vector<int>,DataArrayInt)
1167 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1170 if(PyInt_Check(value))
1172 iTyypp=(int)PyInt_AS_LONG(value);
1176 if(PyTuple_Check(value))
1178 int size=PyTuple_Size(value);
1179 stdvecTyypp.resize(size);
1180 for(int i=0;i<size;i++)
1182 PyObject *o=PyTuple_GetItem(value,i);
1184 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1187 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1188 throw INTERP_KERNEL::Exception(oss.str().c_str());
1194 if(PyList_Check(value))
1196 int size=PyList_Size(value);
1197 stdvecTyypp.resize(size);
1198 for(int i=0;i<size;i++)
1200 PyObject *o=PyList_GetItem(value,i);
1202 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1205 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1206 throw INTERP_KERNEL::Exception(oss.str().c_str());
1213 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1214 if(SWIG_IsOK(status))
1216 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1220 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1221 if(SWIG_IsOK(status))
1223 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1227 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1231 * if python double -> cpp double sw=1
1232 * if python int -> cpp double sw=1
1233 * if python list[double] -> cpp vector<double> sw=2
1234 * if python list[int] -> cpp vector<double> sw=2
1235 * if python tuple[double] -> cpp vector<double> sw=2
1236 * if python tuple[int] -> cpp vector<double> sw=2
1237 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1239 * switch between (int,vector<int>,DataArrayInt)
1241 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1244 if(PyFloat_Check(value))
1246 iTyypp=PyFloat_AS_DOUBLE(value);
1250 if(PyInt_Check(value))
1252 iTyypp=(double)PyInt_AS_LONG(value);
1256 if(PyTuple_Check(value))
1258 int size=PyTuple_Size(value);
1259 stdvecTyypp.resize(size);
1260 for(int i=0;i<size;i++)
1262 PyObject *o=PyTuple_GetItem(value,i);
1263 if(PyFloat_Check(o))
1264 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1265 else if(PyInt_Check(o))
1266 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1269 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1270 throw INTERP_KERNEL::Exception(oss.str().c_str());
1276 if(PyList_Check(value))
1278 int size=PyList_Size(value);
1279 stdvecTyypp.resize(size);
1280 for(int i=0;i<size;i++)
1282 PyObject *o=PyList_GetItem(value,i);
1283 if(PyFloat_Check(o))
1284 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1285 else if(PyInt_Check(o))
1286 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1289 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1290 throw INTERP_KERNEL::Exception(oss.str().c_str());
1297 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1298 if(!SWIG_IsOK(status))
1299 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1300 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1305 * if python double -> cpp double sw=1
1306 * if python int -> cpp double sw=1
1307 * if python list[double] -> cpp vector<double> sw=2
1308 * if python list[int] -> cpp vector<double> sw=2
1309 * if python tuple[double] -> cpp vector<double> sw=2
1310 * if python tuple[int] -> cpp vector<double> sw=2
1311 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1313 * switch between (int,vector<int>,DataArrayInt)
1315 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1318 if(PyFloat_Check(value))
1320 iTyypp=PyFloat_AS_DOUBLE(value);
1324 if(PyInt_Check(value))
1326 iTyypp=(double)PyInt_AS_LONG(value);
1330 if(PyTuple_Check(value))
1332 int size=PyTuple_Size(value);
1333 stdvecTyypp.resize(size);
1334 for(int i=0;i<size;i++)
1336 PyObject *o=PyTuple_GetItem(value,i);
1337 if(PyFloat_Check(o))
1338 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1339 else if(PyInt_Check(o))
1340 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1343 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1344 throw INTERP_KERNEL::Exception(oss.str().c_str());
1350 if(PyList_Check(value))
1352 int size=PyList_Size(value);
1353 stdvecTyypp.resize(size);
1354 for(int i=0;i<size;i++)
1356 PyObject *o=PyList_GetItem(value,i);
1357 if(PyFloat_Check(o))
1358 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1359 else if(PyInt_Check(o))
1360 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1363 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1364 throw INTERP_KERNEL::Exception(oss.str().c_str());
1371 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1372 if(!SWIG_IsOK(status))
1373 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1374 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1379 * if python int -> cpp int sw=1
1380 * if python list[int] -> cpp vector<int> sw=2
1381 * if python tuple[int] -> cpp vector<int> sw=2
1382 * if python slicp -> cpp pair sw=3 (begin,end,step)
1383 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1385 * switch between (int,vector<int>,DataArrayInt)
1387 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)
1389 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1391 if(PyInt_Check(value))
1393 iTyypp=(int)PyInt_AS_LONG(value);
1397 if(PyTuple_Check(value))
1399 int size=PyTuple_Size(value);
1400 stdvecTyypp.resize(size);
1401 for(int i=0;i<size;i++)
1403 PyObject *o=PyTuple_GetItem(value,i);
1405 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1408 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1409 throw INTERP_KERNEL::Exception(oss.str().c_str());
1415 if(PyList_Check(value))
1417 int size=PyList_Size(value);
1418 stdvecTyypp.resize(size);
1419 for(int i=0;i<size;i++)
1421 PyObject *o=PyList_GetItem(value,i);
1423 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1426 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1427 throw INTERP_KERNEL::Exception(oss.str().c_str());
1433 if(PySlice_Check(value))
1435 Py_ssize_t strt=2,stp=2,step=2;
1436 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1437 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1438 if(nbelem!=0 || strt!=0 || stp!=0)
1440 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1441 throw INTERP_KERNEL::Exception(oss.str().c_str());
1445 p.second.second=step;
1450 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1451 if(SWIG_IsOK(status))
1453 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1456 std::ostringstream oss; oss << msg << " Instance in null !";
1457 throw INTERP_KERNEL::Exception(oss.str().c_str());
1462 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1463 if(SWIG_IsOK(status))
1465 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1468 std::ostringstream oss; oss << msg << " Instance in null !";
1469 throw INTERP_KERNEL::Exception(oss.str().c_str());
1471 stdvecTyypp.resize(tmp->getNumberOfCompo());
1472 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1476 throw INTERP_KERNEL::Exception(msg);
1480 * if python int -> cpp int sw=1
1481 * if python tuple[int] -> cpp vector<int> sw=2
1482 * if python list[int] -> cpp vector<int> sw=2
1483 * if python slice -> cpp pair sw=3
1484 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1486 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)
1489 if(PyInt_Check(value))
1491 iTyypp=(int)PyInt_AS_LONG(value);
1495 if(PyTuple_Check(value))
1497 int size=PyTuple_Size(value);
1498 stdvecTyypp.resize(size);
1499 for(int i=0;i<size;i++)
1501 PyObject *o=PyTuple_GetItem(value,i);
1503 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1506 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1507 throw INTERP_KERNEL::Exception(oss.str().c_str());
1513 if(PyList_Check(value))
1515 int size=PyList_Size(value);
1516 stdvecTyypp.resize(size);
1517 for(int i=0;i<size;i++)
1519 PyObject *o=PyList_GetItem(value,i);
1521 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1524 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1525 throw INTERP_KERNEL::Exception(oss.str().c_str());
1531 if(PySlice_Check(value))
1533 Py_ssize_t strt=2,stp=2,step=2;
1534 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1535 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1536 if(nbelem!=0 || strt!=0 || stp!=0)
1538 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1539 throw INTERP_KERNEL::Exception(oss.str().c_str());
1543 p.second.second=step;
1548 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1549 if(!SWIG_IsOK(status))
1550 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1551 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1556 * if python string with size one -> cpp char sw=1
1557 * if python string with size different from one -> cpp string sw=2
1558 * if python tuple[string] or list[string] -> vector<string> sw=3
1559 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1560 * switch between (int,string,vector<string>,DataArrayChar)
1562 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1564 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1566 if(PyString_Check(value))
1568 const char *pt=PyString_AsString(value);
1569 Py_ssize_t sz=PyString_Size(value);
1583 if(PyTuple_Check(value))
1585 int size=PyTuple_Size(value);
1586 vsType.resize(size);
1587 for(int i=0;i<size;i++)
1589 PyObject *o=PyTuple_GetItem(value,i);
1590 if(PyString_Check(o))
1591 vsType[i]=PyString_AsString(o);
1594 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1595 throw INTERP_KERNEL::Exception(oss.str().c_str());
1601 if(PyList_Check(value))
1603 int size=PyList_Size(value);
1604 vsType.resize(size);
1605 for(int i=0;i<size;i++)
1607 PyObject *o=PyList_GetItem(value,i);
1608 if(PyString_Check(o))
1609 vsType[i]=PyString_AsString(o);
1612 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1613 throw INTERP_KERNEL::Exception(oss.str().c_str());
1620 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1621 if(SWIG_IsOK(status))
1623 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1626 std::ostringstream oss; oss << msg << " Instance in null !";
1627 throw INTERP_KERNEL::Exception(oss.str().c_str());
1632 throw INTERP_KERNEL::Exception(msg);
1636 * if value int -> cpp it sw=1
1637 * if value list[int] -> vt sw=2
1638 * if value tuple[int] -> vt sw=2
1639 * if value slice -> pt sw=3
1640 * if value DataArrayInt -> dt sw=4
1641 * if value tuple [int,int] -> cpp it,ip sw=5
1642 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1643 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1644 * if value tuple [slice,int] -> cpp pt,ip sw=7
1645 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1646 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1647 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1648 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1649 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1650 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1651 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1652 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1653 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1654 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1655 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1656 * if value tuple [int,slice] -> cpp it,pc sw=13
1657 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1658 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1659 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1660 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1662 * switch between (int,vector<int>,DataArrayInt)
1664 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1665 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1666 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1668 if(!PyTuple_Check(value))
1670 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1675 int sz=PyTuple_Size(value);
1677 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1678 PyObject *ob0=PyTuple_GetItem(value,0);
1680 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1681 PyObject *ob1=PyTuple_GetItem(value,1);
1682 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1688 * if value int -> cpp val sw=1
1689 * if value double -> cpp val sw=1
1690 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1691 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1692 * if value list[int,double] -> cpp std::vector<double> sw=4
1693 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1695 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1698 if(PyFloat_Check(value))
1700 val=PyFloat_AS_DOUBLE(value);
1704 if(PyInt_Check(value))
1706 val=(double)PyInt_AS_LONG(value);
1710 if(PyTuple_Check(value))
1712 int size=PyTuple_Size(value);
1714 for(int i=0;i<size;i++)
1716 PyObject *o=PyTuple_GetItem(value,i);
1717 if(PyFloat_Check(o))
1718 f[i]=PyFloat_AS_DOUBLE(o);
1719 else if(PyInt_Check(o))
1720 f[i]=(double)PyInt_AS_LONG(o);
1723 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1724 throw INTERP_KERNEL::Exception(oss.str().c_str());
1730 if(PyList_Check(value))
1732 int size=PyList_Size(value);
1734 for(int i=0;i<size;i++)
1736 PyObject *o=PyList_GetItem(value,i);
1737 if(PyFloat_Check(o))
1738 f[i]=PyFloat_AS_DOUBLE(o);
1739 else if(PyInt_Check(o))
1740 f[i]=(double)PyInt_AS_LONG(o);
1743 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1744 throw INTERP_KERNEL::Exception(oss.str().c_str());
1751 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1752 if(SWIG_IsOK(status))
1754 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1758 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1759 if(SWIG_IsOK(status))
1761 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1765 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1769 * if value int -> cpp val sw=1
1770 * if value double -> cpp val sw=1
1771 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1772 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1773 * if value list[int,double] -> cpp std::vector<double> sw=4
1774 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1776 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1777 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1780 if(PyFloat_Check(value))
1782 val=PyFloat_AS_DOUBLE(value);
1784 if(nbTuplesExpected*nbCompExpected!=1)
1786 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1787 throw INTERP_KERNEL::Exception(oss.str().c_str());
1791 if(PyInt_Check(value))
1793 val=(double)PyInt_AS_LONG(value);
1795 if(nbTuplesExpected*nbCompExpected!=1)
1797 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1798 throw INTERP_KERNEL::Exception(oss.str().c_str());
1802 if(PyTuple_Check(value) || PyList_Check(value))
1806 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1807 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1812 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1815 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1816 if(SWIG_IsOK(status))
1818 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1822 if(d->getNumberOfTuples()==nbTuplesExpected)
1824 if(d->getNumberOfComponents()==nbCompExpected)
1826 return d->getConstPointer();
1830 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1831 throw INTERP_KERNEL::Exception(oss.str().c_str());
1836 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1837 throw INTERP_KERNEL::Exception(oss.str().c_str());
1844 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1845 throw INTERP_KERNEL::Exception(oss.str().c_str());
1851 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1852 if(SWIG_IsOK(status))
1854 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1856 if(e->getNumberOfCompo()==nbCompExpected)
1858 if(nbTuplesExpected==1)
1859 return e->getConstPointer();
1862 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1863 throw INTERP_KERNEL::Exception(oss.str().c_str());
1868 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1869 throw INTERP_KERNEL::Exception(oss.str().c_str());
1872 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1876 * if value int -> cpp val sw=1
1877 * if value double -> cpp val sw=1
1878 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1879 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1880 * if value list[int,double] -> cpp std::vector<double> sw=4
1881 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1883 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1884 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1887 if(PyFloat_Check(value))
1889 val=PyFloat_AS_DOUBLE(value);
1891 if(nbCompExpected!=1)
1893 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1894 throw INTERP_KERNEL::Exception(oss.str().c_str());
1899 if(PyInt_Check(value))
1901 val=(double)PyInt_AS_LONG(value);
1903 if(nbCompExpected!=1)
1905 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1906 throw INTERP_KERNEL::Exception(oss.str().c_str());
1911 if(PyTuple_Check(value))
1913 int size=PyTuple_Size(value);
1915 for(int i=0;i<size;i++)
1917 PyObject *o=PyTuple_GetItem(value,i);
1918 if(PyFloat_Check(o))
1919 f[i]=PyFloat_AS_DOUBLE(o);
1920 else if(PyInt_Check(o))
1921 f[i]=(double)PyInt_AS_LONG(o);
1924 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1925 throw INTERP_KERNEL::Exception(oss.str().c_str());
1929 if(size%nbCompExpected!=0)
1931 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1932 throw INTERP_KERNEL::Exception(oss.str().c_str());
1934 nbTuples=size/nbCompExpected;
1937 if(PyList_Check(value))
1939 int size=PyList_Size(value);
1941 for(int i=0;i<size;i++)
1943 PyObject *o=PyList_GetItem(value,i);
1944 if(PyFloat_Check(o))
1945 f[i]=PyFloat_AS_DOUBLE(o);
1946 else if(PyInt_Check(o))
1947 f[i]=(double)PyInt_AS_LONG(o);
1950 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1951 throw INTERP_KERNEL::Exception(oss.str().c_str());
1955 if(size%nbCompExpected!=0)
1957 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1958 throw INTERP_KERNEL::Exception(oss.str().c_str());
1960 nbTuples=size/nbCompExpected;
1964 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1965 if(SWIG_IsOK(status))
1967 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1971 if(d->getNumberOfComponents()==nbCompExpected)
1973 nbTuples=d->getNumberOfTuples();
1974 return d->getConstPointer();
1978 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1979 throw INTERP_KERNEL::Exception(oss.str().c_str());
1986 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1987 throw INTERP_KERNEL::Exception(oss.str().c_str());
1990 { nbTuples=0; return 0; }
1993 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1994 if(SWIG_IsOK(status))
1996 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2000 if(e->getNumberOfCompo()==nbCompExpected)
2003 return e->getConstPointer();
2007 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2008 throw INTERP_KERNEL::Exception(oss.str().c_str());
2015 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2016 throw INTERP_KERNEL::Exception(oss.str().c_str());
2019 { nbTuples=0; return 0; }
2022 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2026 * if value int -> cpp val sw=1
2027 * if value double -> cpp val sw=1
2028 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2029 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2030 * if value list[int,double] -> cpp std::vector<double> sw=4
2031 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2033 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2034 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2036 ParaMEDMEM::DataArrayDouble *d=0;
2037 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2039 if(PyFloat_Check(value))
2041 val=PyFloat_AS_DOUBLE(value);
2046 if(PyInt_Check(value))
2048 val=(double)PyInt_AS_LONG(value);
2053 if(PyTuple_Check(value))
2055 int size=PyTuple_Size(value);
2057 for(int i=0;i<size;i++)
2059 PyObject *o=PyTuple_GetItem(value,i);
2060 if(PyFloat_Check(o))
2061 f[i]=PyFloat_AS_DOUBLE(o);
2062 else if(PyInt_Check(o))
2063 f[i]=(double)PyInt_AS_LONG(o);
2066 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2067 throw INTERP_KERNEL::Exception(oss.str().c_str());
2074 if(PyList_Check(value))
2076 int size=PyList_Size(value);
2078 for(int i=0;i<size;i++)
2080 PyObject *o=PyList_GetItem(value,i);
2081 if(PyFloat_Check(o))
2082 f[i]=PyFloat_AS_DOUBLE(o);
2083 else if(PyInt_Check(o))
2084 f[i]=(double)PyInt_AS_LONG(o);
2087 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2088 throw INTERP_KERNEL::Exception(oss.str().c_str());
2096 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2097 if(SWIG_IsOK(status))
2099 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2103 if(d->getNumberOfComponents()==1)
2105 nbTuples=d->getNumberOfTuples();
2106 return d->getConstPointer();
2110 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2111 throw INTERP_KERNEL::Exception(oss.str().c_str());
2118 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2119 throw INTERP_KERNEL::Exception(oss.str().c_str());
2122 { nbTuples=0; return 0; }
2125 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2126 if(SWIG_IsOK(status))
2128 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2132 nbTuples=e->getNumberOfCompo();
2133 return e->getConstPointer();
2139 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2140 throw INTERP_KERNEL::Exception(oss.str().c_str());
2143 { nbTuples=0; return 0; }
2146 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2150 * if python int -> cpp int sw=1
2151 * if python list[int] -> cpp vector<int> sw=2
2152 * if python tuple[int] -> cpp vector<int> sw=2
2153 * if python DataArrayInt -> cpp DataArrayInt sw=3
2154 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2156 * switch between (int,vector<int>,DataArrayInt)
2158 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2161 if(PyInt_Check(value))
2163 iTyypp=(int)PyInt_AS_LONG(value);
2167 if(PyTuple_Check(value))
2169 int size=PyTuple_Size(value);
2170 stdvecTyypp.resize(size);
2171 for(int i=0;i<size;i++)
2173 PyObject *o=PyTuple_GetItem(value,i);
2175 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2178 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2179 throw INTERP_KERNEL::Exception(oss.str().c_str());
2183 return &stdvecTyypp[0];
2185 if(PyList_Check(value))
2187 int size=PyList_Size(value);
2188 stdvecTyypp.resize(size);
2189 for(int i=0;i<size;i++)
2191 PyObject *o=PyList_GetItem(value,i);
2193 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2196 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2197 throw INTERP_KERNEL::Exception(oss.str().c_str());
2201 return &stdvecTyypp[0];
2204 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2205 if(SWIG_IsOK(status))
2207 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2210 sw=3; sz=daIntTyypp->getNbOfElems();
2211 return daIntTyypp->begin();
2219 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2220 if(SWIG_IsOK(status))
2222 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2223 sw=4; sz=daIntTuple->getNumberOfCompo();
2224 return daIntTuple->getConstPointer();
2226 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2229 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2231 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.";
2232 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2235 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2237 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2239 return (*self)+(*other);
2241 throw INTERP_KERNEL::Exception(msg);
2245 ParaMEDMEM::DataArrayDouble *a;
2246 ParaMEDMEM::DataArrayDoubleTuple *aa;
2247 std::vector<double> bb;
2249 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2254 if(!self->getArray())
2255 throw INTERP_KERNEL::Exception(msg2);
2256 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2257 ret->applyLin(1.,val);
2258 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2259 ret2->setArray(ret);
2264 if(!self->getArray())
2265 throw INTERP_KERNEL::Exception(msg2);
2266 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2267 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2268 ret2->setArray(ret);
2273 if(!self->getArray())
2274 throw INTERP_KERNEL::Exception(msg2);
2275 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2276 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2277 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2278 ret2->setArray(ret);
2283 if(!self->getArray())
2284 throw INTERP_KERNEL::Exception(msg2);
2285 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2286 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2287 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2288 ret2->setArray(ret);
2292 { throw INTERP_KERNEL::Exception(msg); }
2296 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2298 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2301 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2303 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.";
2304 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2307 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2309 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2311 return (*other)-(*self);
2313 throw INTERP_KERNEL::Exception(msg);
2317 ParaMEDMEM::DataArrayDouble *a;
2318 ParaMEDMEM::DataArrayDoubleTuple *aa;
2319 std::vector<double> bb;
2321 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2326 if(!self->getArray())
2327 throw INTERP_KERNEL::Exception(msg2);
2328 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2329 ret->applyLin(-1.,val);
2330 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2331 ret2->setArray(ret);
2336 if(!self->getArray())
2337 throw INTERP_KERNEL::Exception(msg2);
2338 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2339 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2340 ret2->setArray(ret);
2345 if(!self->getArray())
2346 throw INTERP_KERNEL::Exception(msg2);
2347 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2348 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2349 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2350 ret2->setArray(ret);
2355 if(!self->getArray())
2356 throw INTERP_KERNEL::Exception(msg2);
2357 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2358 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2359 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2360 ret2->setArray(ret);
2364 { throw INTERP_KERNEL::Exception(msg); }
2368 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2370 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.";
2371 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2374 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2376 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2378 return (*self)*(*other);
2380 throw INTERP_KERNEL::Exception(msg);
2384 ParaMEDMEM::DataArrayDouble *a;
2385 ParaMEDMEM::DataArrayDoubleTuple *aa;
2386 std::vector<double> bb;
2388 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2393 if(!self->getArray())
2394 throw INTERP_KERNEL::Exception(msg2);
2395 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2396 ret->applyLin(val,0.);
2397 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2398 ret2->setArray(ret);
2403 if(!self->getArray())
2404 throw INTERP_KERNEL::Exception(msg2);
2405 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2406 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2407 ret2->setArray(ret);
2412 if(!self->getArray())
2413 throw INTERP_KERNEL::Exception(msg2);
2414 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2415 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2416 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2417 ret2->setArray(ret);
2422 if(!self->getArray())
2423 throw INTERP_KERNEL::Exception(msg2);
2424 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2425 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2426 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2427 ret2->setArray(ret);
2431 { throw INTERP_KERNEL::Exception(msg); }
2435 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2437 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2440 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2442 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.";
2443 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2446 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2448 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2450 return (*other)/(*self);
2452 throw INTERP_KERNEL::Exception(msg);
2456 ParaMEDMEM::DataArrayDouble *a;
2457 ParaMEDMEM::DataArrayDoubleTuple *aa;
2458 std::vector<double> bb;
2460 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2465 if(!self->getArray())
2466 throw INTERP_KERNEL::Exception(msg2);
2467 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2469 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2470 ret2->setArray(ret);
2475 if(!self->getArray())
2476 throw INTERP_KERNEL::Exception(msg2);
2477 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2478 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2479 ret2->setArray(ret);
2484 if(!self->getArray())
2485 throw INTERP_KERNEL::Exception(msg2);
2486 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2487 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2488 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2489 ret2->setArray(ret);
2494 if(!self->getArray())
2495 throw INTERP_KERNEL::Exception(msg2);
2496 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2497 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2498 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2499 ret2->setArray(ret);
2503 { throw INTERP_KERNEL::Exception(msg); }
2507 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2510 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2511 if(!SWIG_IsOK(status))
2513 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2514 if(!SWIG_IsOK(status))
2516 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2517 if(!SWIG_IsOK(status))
2519 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2520 if(!SWIG_IsOK(status))
2522 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2523 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2524 throw INTERP_KERNEL::Exception(oss.str().c_str());
2529 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);