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::MEDCoupling1DGTUMesh *>(mesh))
423 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1DGTUMesh,owner);
424 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
425 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
426 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
427 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
428 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
429 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
431 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
435 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
443 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
444 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
445 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
446 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
447 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
448 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
449 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
450 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
451 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
452 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
454 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
458 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
466 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
467 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
468 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
469 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
471 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
475 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
483 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
484 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
485 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
486 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
487 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
488 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
489 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
490 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
492 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
496 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
504 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
505 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
507 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
511 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
513 PyObject *ret=PyList_New(size);
514 for(int i=0;i<size;i++)
515 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
519 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
522 PyObject *ret=PyList_New(size);
523 for(int i=0;i<size;i++)
524 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
528 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
531 PyObject *ret=PyList_New(size);
532 std::set<int>::const_iterator it=v.begin();
533 for(int i=0;i<size;i++,it++)
534 PyList_SetItem(ret,i,PyInt_FromLong(*it));
538 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
540 PyObject *ret=PyList_New(nbOfTuples);
541 for(int i=0;i<nbOfTuples;i++)
543 PyObject *t=PyTuple_New(nbOfComp);
544 for(int j=0;j<nbOfComp;j++)
545 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
546 PyList_SetItem(ret,i,t);
551 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
553 if(PyList_Check(pyLi))
555 *size=PyList_Size(pyLi);
556 int *tmp=new int[*size];
557 for(int i=0;i<*size;i++)
559 PyObject *o=PyList_GetItem(pyLi,i);
562 int val=(int)PyInt_AS_LONG(o);
568 throw INTERP_KERNEL::Exception("list must contain integers only");
573 else if(PyTuple_Check(pyLi))
575 *size=PyTuple_Size(pyLi);
576 int *tmp=new int[*size];
577 for(int i=0;i<*size;i++)
579 PyObject *o=PyTuple_GetItem(pyLi,i);
582 int val=(int)PyInt_AS_LONG(o);
588 throw INTERP_KERNEL::Exception("tuple must contain integers only");
595 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
599 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
601 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
602 if(PyList_Check(pyLi))
604 int size=PyList_Size(pyLi);
606 for(int i=0;i<size;i++)
608 PyObject *o=PyList_GetItem(pyLi,i);
611 int sz2=PyTuple_Size(o);
613 throw INTERP_KERNEL::Exception(msg);
614 PyObject *o_0=PyTuple_GetItem(o,0);
615 if(!PyInt_Check(o_0))
616 throw INTERP_KERNEL::Exception(msg);
617 PyObject *o_1=PyTuple_GetItem(o,1);
618 if(!PyInt_Check(o_1))
619 throw INTERP_KERNEL::Exception(msg);
620 arr[i].first=(int)PyInt_AS_LONG(o_0);
621 arr[i].second=(int)PyInt_AS_LONG(o_1);
624 throw INTERP_KERNEL::Exception(msg);
627 else if(PyTuple_Check(pyLi))
629 int size=PyTuple_Size(pyLi);
631 for(int i=0;i<size;i++)
633 PyObject *o=PyTuple_GetItem(pyLi,i);
636 int sz2=PyTuple_Size(o);
638 throw INTERP_KERNEL::Exception(msg);
639 PyObject *o_0=PyTuple_GetItem(o,0);
640 if(!PyInt_Check(o_0))
641 throw INTERP_KERNEL::Exception(msg);
642 PyObject *o_1=PyTuple_GetItem(o,1);
643 if(!PyInt_Check(o_1))
644 throw INTERP_KERNEL::Exception(msg);
645 arr[i].first=(int)PyInt_AS_LONG(o_0);
646 arr[i].second=(int)PyInt_AS_LONG(o_1);
649 throw INTERP_KERNEL::Exception(msg);
653 throw INTERP_KERNEL::Exception(msg);
656 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
658 if(PyList_Check(pyLi))
660 int size=PyList_Size(pyLi);
662 for(int i=0;i<size;i++)
664 PyObject *o=PyList_GetItem(pyLi,i);
667 int val=(int)PyInt_AS_LONG(o);
671 throw INTERP_KERNEL::Exception("list must contain integers only");
674 else if(PyTuple_Check(pyLi))
676 int size=PyTuple_Size(pyLi);
678 for(int i=0;i<size;i++)
680 PyObject *o=PyTuple_GetItem(pyLi,i);
683 int val=(int)PyInt_AS_LONG(o);
687 throw INTERP_KERNEL::Exception("tuple must contain integers only");
692 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
696 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
699 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
701 if(PyList_Check(pyLi))
703 int size=PyList_Size(pyLi);
704 for(int i=0;i<size;i++)
706 PyObject *o=PyList_GetItem(pyLi,i);
709 int val=(int)PyInt_AS_LONG(o);
714 std::vector<int> arr2;
715 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
716 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
718 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
719 throw INTERP_KERNEL::Exception(oss.str().c_str());
721 arr.insert(arr.end(),arr2.begin(),arr2.end());
725 else if(PyTuple_Check(pyLi))
727 int size=PyTuple_Size(pyLi);
728 for(int i=0;i<size;i++)
730 PyObject *o=PyTuple_GetItem(pyLi,i);
733 int val=(int)PyInt_AS_LONG(o);
738 std::vector<int> arr2;
739 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
740 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
742 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
743 throw INTERP_KERNEL::Exception(oss.str().c_str());
745 arr.insert(arr.end(),arr2.begin(),arr2.end());
750 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
753 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
757 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
758 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
760 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
761 oss << " whereas nb of components expected is " << nbOfComp << " !";
762 throw INTERP_KERNEL::Exception(oss.str().c_str());
769 if((nbOfTuples!=size1 || nbOfComp!=size2))
771 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
773 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
774 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
775 throw INTERP_KERNEL::Exception(oss.str().c_str());
781 if(nbOfTuples==size1)
785 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
786 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
787 throw INTERP_KERNEL::Exception(oss.str().c_str());
793 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
795 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
796 if(PyInt_Check(pyLi))
798 long val=PyInt_AS_LONG(pyLi);
803 throw INTERP_KERNEL::Exception(MSG);
806 else if(PyList_Check(pyLi))
808 int size=PyList_Size(pyLi);
810 for(int i=0;i<size;i++)
812 PyObject *o=PyList_GetItem(pyLi,i);
814 fillArrayWithPyListInt3(o,tmp1,ret);
822 throw INTERP_KERNEL::Exception(MSG);
825 else if(PyTuple_Check(pyLi))
827 int size=PyTuple_Size(pyLi);
829 for(int i=0;i<size;i++)
831 PyObject *o=PyTuple_GetItem(pyLi,i);
833 fillArrayWithPyListInt3(o,tmp1,ret);
841 throw INTERP_KERNEL::Exception(MSG);
845 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
848 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
850 std::vector<int> ret;
851 int size1=-1,size2=-1;
852 if(PyList_Check(pyLi))
854 size1=PyList_Size(pyLi);
855 for(int i=0;i<size1;i++)
857 PyObject *o=PyList_GetItem(pyLi,i);
858 fillArrayWithPyListInt3(o,size2,ret);
863 else if(PyTuple_Check(pyLi))
865 size1=PyTuple_Size(pyLi);
866 for(int i=0;i<size1;i++)
868 PyObject *o=PyTuple_GetItem(pyLi,i);
869 fillArrayWithPyListInt3(o,size2,ret);
875 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
877 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
881 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
883 if(PyList_Check(pyLi))
885 Py_ssize_t sz=PyList_Size(pyLi);
887 for(int i=0;i<sz;i++)
889 PyObject *o=PyList_GetItem(pyLi,i);
890 if(PyString_Check(o))
891 vec[i]=PyString_AsString(o);
897 else if(PyTuple_Check(pyLi))
899 Py_ssize_t sz=PyTuple_Size(pyLi);
901 for(int i=0;i<sz;i++)
903 PyObject *o=PyTuple_GetItem(pyLi,i);
904 if(PyString_Check(o))
905 vec[i]=PyString_AsString(o);
915 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
917 PyObject *ret=PyList_New(size);
918 for(int i=0;i<size;i++)
919 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
923 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
926 PyObject *ret=PyList_New(size);
927 for(int i=0;i<size;i++)
928 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
932 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
934 PyObject *ret=PyList_New(nbOfTuples);
935 for(int i=0;i<nbOfTuples;i++)
937 PyObject *t=PyTuple_New(nbOfComp);
938 for(int j=0;j<nbOfComp;j++)
939 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
940 PyList_SetItem(ret,i,t);
945 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
947 PyObject *ret=PyList_New(nbOfTuples);
948 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
949 for(int i=0;i<nbOfTuples;i++)
951 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
952 PyList_SetItem(ret,i,PyString_FromString(tmp));
957 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
959 if(PyList_Check(pyLi))
961 *size=PyList_Size(pyLi);
962 double *tmp=(double *)malloc((*size)*sizeof(double));
963 for(int i=0;i<*size;i++)
965 PyObject *o=PyList_GetItem(pyLi,i);
968 double val=PyFloat_AS_DOUBLE(o);
971 else if(PyInt_Check(o))
973 long val0=PyInt_AS_LONG(o);
980 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
985 else if(PyTuple_Check(pyLi))
987 *size=PyTuple_Size(pyLi);
988 double *tmp=(double *)malloc((*size)*sizeof(double));
989 for(int i=0;i<*size;i++)
991 PyObject *o=PyTuple_GetItem(pyLi,i);
994 double val=PyFloat_AS_DOUBLE(o);
997 else if(PyInt_Check(o))
999 long val0=PyInt_AS_LONG(o);
1006 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1012 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1015 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1017 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1018 if(PyFloat_Check(pyLi))
1024 throw INTERP_KERNEL::Exception(MSG);
1025 double val=PyFloat_AS_DOUBLE(pyLi);
1028 else if(PyInt_Check(pyLi))
1030 long val0=PyInt_AS_LONG(pyLi);
1036 throw INTERP_KERNEL::Exception(MSG);
1039 else if(PyList_Check(pyLi))
1041 int size=PyList_Size(pyLi);
1043 for(int i=0;i<size;i++)
1045 PyObject *o=PyList_GetItem(pyLi,i);
1047 fillArrayWithPyListDbl3(o,tmp1,ret);
1055 throw INTERP_KERNEL::Exception(MSG);
1058 else if(PyTuple_Check(pyLi))
1060 int size=PyTuple_Size(pyLi);
1062 for(int i=0;i<size;i++)
1064 PyObject *o=PyTuple_GetItem(pyLi,i);
1066 fillArrayWithPyListDbl3(o,tmp1,ret);
1074 throw INTERP_KERNEL::Exception(MSG);
1078 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1081 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1083 std::vector<double> ret;
1084 int size1=-1,size2=-1;
1085 if(PyList_Check(pyLi))
1087 size1=PyList_Size(pyLi);
1088 for(int i=0;i<size1;i++)
1090 PyObject *o=PyList_GetItem(pyLi,i);
1091 fillArrayWithPyListDbl3(o,size2,ret);
1096 else if(PyTuple_Check(pyLi))
1098 size1=PyTuple_Size(pyLi);
1099 for(int i=0;i<size1;i++)
1101 PyObject *o=PyTuple_GetItem(pyLi,i);
1102 fillArrayWithPyListDbl3(o,size2,ret);
1108 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1110 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1114 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1116 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1119 if(PyList_Check(pyLi))
1121 int size=PyList_Size(pyLi);
1123 for(int i=0;i<size;i++)
1125 PyObject *obj=PyList_GetItem(pyLi,i);
1126 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1127 if(!SWIG_IsOK(status))
1128 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
1129 T arg=reinterpret_cast< T >(argp);
1133 else if(PyTuple_Check(pyLi))
1135 int size=PyTuple_Size(pyLi);
1137 for(int i=0;i<size;i++)
1139 PyObject *obj=PyTuple_GetItem(pyLi,i);
1140 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1141 if(!SWIG_IsOK(status))
1143 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
1144 throw INTERP_KERNEL::Exception(oss.str().c_str());
1146 T arg=reinterpret_cast< T >(argp);
1150 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1153 T arg=reinterpret_cast< T >(argp);
1157 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1161 * if python int -> cpp int sw=1
1162 * if python list[int] -> cpp vector<int> sw=2
1163 * if python tuple[int] -> cpp vector<int> sw=2
1164 * if python DataArrayInt -> cpp DataArrayInt sw=3
1165 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1167 * switch between (int,vector<int>,DataArrayInt)
1169 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1172 if(PyInt_Check(value))
1174 iTyypp=(int)PyInt_AS_LONG(value);
1178 if(PyTuple_Check(value))
1180 int size=PyTuple_Size(value);
1181 stdvecTyypp.resize(size);
1182 for(int i=0;i<size;i++)
1184 PyObject *o=PyTuple_GetItem(value,i);
1186 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1189 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1190 throw INTERP_KERNEL::Exception(oss.str().c_str());
1196 if(PyList_Check(value))
1198 int size=PyList_Size(value);
1199 stdvecTyypp.resize(size);
1200 for(int i=0;i<size;i++)
1202 PyObject *o=PyList_GetItem(value,i);
1204 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1207 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1208 throw INTERP_KERNEL::Exception(oss.str().c_str());
1215 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1216 if(SWIG_IsOK(status))
1218 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1222 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1223 if(SWIG_IsOK(status))
1225 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1229 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1233 * if python double -> cpp double sw=1
1234 * if python int -> cpp double sw=1
1235 * if python list[double] -> cpp vector<double> sw=2
1236 * if python list[int] -> cpp vector<double> sw=2
1237 * if python tuple[double] -> cpp vector<double> sw=2
1238 * if python tuple[int] -> cpp vector<double> sw=2
1239 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1241 * switch between (int,vector<int>,DataArrayInt)
1243 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1246 if(PyFloat_Check(value))
1248 iTyypp=PyFloat_AS_DOUBLE(value);
1252 if(PyInt_Check(value))
1254 iTyypp=(double)PyInt_AS_LONG(value);
1258 if(PyTuple_Check(value))
1260 int size=PyTuple_Size(value);
1261 stdvecTyypp.resize(size);
1262 for(int i=0;i<size;i++)
1264 PyObject *o=PyTuple_GetItem(value,i);
1265 if(PyFloat_Check(o))
1266 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1267 else if(PyInt_Check(o))
1268 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1271 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1272 throw INTERP_KERNEL::Exception(oss.str().c_str());
1278 if(PyList_Check(value))
1280 int size=PyList_Size(value);
1281 stdvecTyypp.resize(size);
1282 for(int i=0;i<size;i++)
1284 PyObject *o=PyList_GetItem(value,i);
1285 if(PyFloat_Check(o))
1286 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1287 else if(PyInt_Check(o))
1288 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1291 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1292 throw INTERP_KERNEL::Exception(oss.str().c_str());
1299 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1300 if(!SWIG_IsOK(status))
1301 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1302 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1307 * if python double -> cpp double sw=1
1308 * if python int -> cpp double sw=1
1309 * if python list[double] -> cpp vector<double> sw=2
1310 * if python list[int] -> cpp vector<double> sw=2
1311 * if python tuple[double] -> cpp vector<double> sw=2
1312 * if python tuple[int] -> cpp vector<double> sw=2
1313 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1315 * switch between (int,vector<int>,DataArrayInt)
1317 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1320 if(PyFloat_Check(value))
1322 iTyypp=PyFloat_AS_DOUBLE(value);
1326 if(PyInt_Check(value))
1328 iTyypp=(double)PyInt_AS_LONG(value);
1332 if(PyTuple_Check(value))
1334 int size=PyTuple_Size(value);
1335 stdvecTyypp.resize(size);
1336 for(int i=0;i<size;i++)
1338 PyObject *o=PyTuple_GetItem(value,i);
1339 if(PyFloat_Check(o))
1340 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1341 else if(PyInt_Check(o))
1342 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1345 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1346 throw INTERP_KERNEL::Exception(oss.str().c_str());
1352 if(PyList_Check(value))
1354 int size=PyList_Size(value);
1355 stdvecTyypp.resize(size);
1356 for(int i=0;i<size;i++)
1358 PyObject *o=PyList_GetItem(value,i);
1359 if(PyFloat_Check(o))
1360 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1361 else if(PyInt_Check(o))
1362 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1365 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1366 throw INTERP_KERNEL::Exception(oss.str().c_str());
1373 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1374 if(!SWIG_IsOK(status))
1375 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1376 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1381 * if python int -> cpp int sw=1
1382 * if python list[int] -> cpp vector<int> sw=2
1383 * if python tuple[int] -> cpp vector<int> sw=2
1384 * if python slicp -> cpp pair sw=3 (begin,end,step)
1385 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1387 * switch between (int,vector<int>,DataArrayInt)
1389 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)
1391 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1393 if(PyInt_Check(value))
1395 iTyypp=(int)PyInt_AS_LONG(value);
1399 if(PyTuple_Check(value))
1401 int size=PyTuple_Size(value);
1402 stdvecTyypp.resize(size);
1403 for(int i=0;i<size;i++)
1405 PyObject *o=PyTuple_GetItem(value,i);
1407 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1410 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1411 throw INTERP_KERNEL::Exception(oss.str().c_str());
1417 if(PyList_Check(value))
1419 int size=PyList_Size(value);
1420 stdvecTyypp.resize(size);
1421 for(int i=0;i<size;i++)
1423 PyObject *o=PyList_GetItem(value,i);
1425 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1428 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1429 throw INTERP_KERNEL::Exception(oss.str().c_str());
1435 if(PySlice_Check(value))
1437 Py_ssize_t strt=2,stp=2,step=2;
1438 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1439 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1440 if(nbelem!=0 || strt!=0 || stp!=0)
1442 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1443 throw INTERP_KERNEL::Exception(oss.str().c_str());
1447 p.second.second=step;
1452 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1453 if(SWIG_IsOK(status))
1455 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1458 std::ostringstream oss; oss << msg << " Instance in null !";
1459 throw INTERP_KERNEL::Exception(oss.str().c_str());
1464 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1465 if(SWIG_IsOK(status))
1467 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1470 std::ostringstream oss; oss << msg << " Instance in null !";
1471 throw INTERP_KERNEL::Exception(oss.str().c_str());
1473 stdvecTyypp.resize(tmp->getNumberOfCompo());
1474 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1478 throw INTERP_KERNEL::Exception(msg);
1482 * if python int -> cpp int sw=1
1483 * if python tuple[int] -> cpp vector<int> sw=2
1484 * if python list[int] -> cpp vector<int> sw=2
1485 * if python slice -> cpp pair sw=3
1486 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1488 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)
1491 if(PyInt_Check(value))
1493 iTyypp=(int)PyInt_AS_LONG(value);
1497 if(PyTuple_Check(value))
1499 int size=PyTuple_Size(value);
1500 stdvecTyypp.resize(size);
1501 for(int i=0;i<size;i++)
1503 PyObject *o=PyTuple_GetItem(value,i);
1505 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1508 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1509 throw INTERP_KERNEL::Exception(oss.str().c_str());
1515 if(PyList_Check(value))
1517 int size=PyList_Size(value);
1518 stdvecTyypp.resize(size);
1519 for(int i=0;i<size;i++)
1521 PyObject *o=PyList_GetItem(value,i);
1523 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1526 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1527 throw INTERP_KERNEL::Exception(oss.str().c_str());
1533 if(PySlice_Check(value))
1535 Py_ssize_t strt=2,stp=2,step=2;
1536 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1537 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1538 if(nbelem!=0 || strt!=0 || stp!=0)
1540 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1541 throw INTERP_KERNEL::Exception(oss.str().c_str());
1545 p.second.second=step;
1550 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1551 if(!SWIG_IsOK(status))
1552 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1553 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1558 * if python string with size one -> cpp char sw=1
1559 * if python string with size different from one -> cpp string sw=2
1560 * if python tuple[string] or list[string] -> vector<string> sw=3
1561 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1562 * switch between (int,string,vector<string>,DataArrayChar)
1564 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1566 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1568 if(PyString_Check(value))
1570 const char *pt=PyString_AsString(value);
1571 Py_ssize_t sz=PyString_Size(value);
1585 if(PyTuple_Check(value))
1587 int size=PyTuple_Size(value);
1588 vsType.resize(size);
1589 for(int i=0;i<size;i++)
1591 PyObject *o=PyTuple_GetItem(value,i);
1592 if(PyString_Check(o))
1593 vsType[i]=PyString_AsString(o);
1596 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1597 throw INTERP_KERNEL::Exception(oss.str().c_str());
1603 if(PyList_Check(value))
1605 int size=PyList_Size(value);
1606 vsType.resize(size);
1607 for(int i=0;i<size;i++)
1609 PyObject *o=PyList_GetItem(value,i);
1610 if(PyString_Check(o))
1611 vsType[i]=PyString_AsString(o);
1614 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1615 throw INTERP_KERNEL::Exception(oss.str().c_str());
1622 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1623 if(SWIG_IsOK(status))
1625 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1628 std::ostringstream oss; oss << msg << " Instance in null !";
1629 throw INTERP_KERNEL::Exception(oss.str().c_str());
1634 throw INTERP_KERNEL::Exception(msg);
1638 * if value int -> cpp it sw=1
1639 * if value list[int] -> vt sw=2
1640 * if value tuple[int] -> vt sw=2
1641 * if value slice -> pt sw=3
1642 * if value DataArrayInt -> dt sw=4
1643 * if value tuple [int,int] -> cpp it,ip sw=5
1644 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1645 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1646 * if value tuple [slice,int] -> cpp pt,ip sw=7
1647 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1648 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1649 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1650 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1651 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1652 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1653 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1654 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1655 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1656 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1657 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1658 * if value tuple [int,slice] -> cpp it,pc sw=13
1659 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1660 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1661 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1662 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1664 * switch between (int,vector<int>,DataArrayInt)
1666 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1667 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1668 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1670 if(!PyTuple_Check(value))
1672 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1677 int sz=PyTuple_Size(value);
1679 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1680 PyObject *ob0=PyTuple_GetItem(value,0);
1682 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1683 PyObject *ob1=PyTuple_GetItem(value,1);
1684 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1690 * if value int -> cpp val sw=1
1691 * if value double -> cpp val sw=1
1692 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1693 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1694 * if value list[int,double] -> cpp std::vector<double> sw=4
1695 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1697 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1700 if(PyFloat_Check(value))
1702 val=PyFloat_AS_DOUBLE(value);
1706 if(PyInt_Check(value))
1708 val=(double)PyInt_AS_LONG(value);
1712 if(PyTuple_Check(value))
1714 int size=PyTuple_Size(value);
1716 for(int i=0;i<size;i++)
1718 PyObject *o=PyTuple_GetItem(value,i);
1719 if(PyFloat_Check(o))
1720 f[i]=PyFloat_AS_DOUBLE(o);
1721 else if(PyInt_Check(o))
1722 f[i]=(double)PyInt_AS_LONG(o);
1725 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1726 throw INTERP_KERNEL::Exception(oss.str().c_str());
1732 if(PyList_Check(value))
1734 int size=PyList_Size(value);
1736 for(int i=0;i<size;i++)
1738 PyObject *o=PyList_GetItem(value,i);
1739 if(PyFloat_Check(o))
1740 f[i]=PyFloat_AS_DOUBLE(o);
1741 else if(PyInt_Check(o))
1742 f[i]=(double)PyInt_AS_LONG(o);
1745 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1746 throw INTERP_KERNEL::Exception(oss.str().c_str());
1753 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1754 if(SWIG_IsOK(status))
1756 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1760 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1761 if(SWIG_IsOK(status))
1763 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1767 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1771 * if value int -> cpp val sw=1
1772 * if value double -> cpp val sw=1
1773 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1774 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1775 * if value list[int,double] -> cpp std::vector<double> sw=4
1776 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1778 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1779 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1782 if(PyFloat_Check(value))
1784 val=PyFloat_AS_DOUBLE(value);
1786 if(nbTuplesExpected*nbCompExpected!=1)
1788 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1789 throw INTERP_KERNEL::Exception(oss.str().c_str());
1793 if(PyInt_Check(value))
1795 val=(double)PyInt_AS_LONG(value);
1797 if(nbTuplesExpected*nbCompExpected!=1)
1799 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1800 throw INTERP_KERNEL::Exception(oss.str().c_str());
1804 if(PyTuple_Check(value) || PyList_Check(value))
1808 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1809 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1814 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1817 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1818 if(SWIG_IsOK(status))
1820 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1824 if(d->getNumberOfTuples()==nbTuplesExpected)
1826 if(d->getNumberOfComponents()==nbCompExpected)
1828 return d->getConstPointer();
1832 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1833 throw INTERP_KERNEL::Exception(oss.str().c_str());
1838 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1839 throw INTERP_KERNEL::Exception(oss.str().c_str());
1846 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1847 throw INTERP_KERNEL::Exception(oss.str().c_str());
1853 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1854 if(SWIG_IsOK(status))
1856 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1858 if(e->getNumberOfCompo()==nbCompExpected)
1860 if(nbTuplesExpected==1)
1861 return e->getConstPointer();
1864 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1865 throw INTERP_KERNEL::Exception(oss.str().c_str());
1870 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1871 throw INTERP_KERNEL::Exception(oss.str().c_str());
1874 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1878 * if value int -> cpp val sw=1
1879 * if value double -> cpp val sw=1
1880 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1881 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1882 * if value list[int,double] -> cpp std::vector<double> sw=4
1883 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1885 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1886 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1889 if(PyFloat_Check(value))
1891 val=PyFloat_AS_DOUBLE(value);
1893 if(nbCompExpected!=1)
1895 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1896 throw INTERP_KERNEL::Exception(oss.str().c_str());
1901 if(PyInt_Check(value))
1903 val=(double)PyInt_AS_LONG(value);
1905 if(nbCompExpected!=1)
1907 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1908 throw INTERP_KERNEL::Exception(oss.str().c_str());
1913 if(PyTuple_Check(value))
1915 int size=PyTuple_Size(value);
1917 for(int i=0;i<size;i++)
1919 PyObject *o=PyTuple_GetItem(value,i);
1920 if(PyFloat_Check(o))
1921 f[i]=PyFloat_AS_DOUBLE(o);
1922 else if(PyInt_Check(o))
1923 f[i]=(double)PyInt_AS_LONG(o);
1926 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1927 throw INTERP_KERNEL::Exception(oss.str().c_str());
1931 if(size%nbCompExpected!=0)
1933 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1934 throw INTERP_KERNEL::Exception(oss.str().c_str());
1936 nbTuples=size/nbCompExpected;
1939 if(PyList_Check(value))
1941 int size=PyList_Size(value);
1943 for(int i=0;i<size;i++)
1945 PyObject *o=PyList_GetItem(value,i);
1946 if(PyFloat_Check(o))
1947 f[i]=PyFloat_AS_DOUBLE(o);
1948 else if(PyInt_Check(o))
1949 f[i]=(double)PyInt_AS_LONG(o);
1952 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1953 throw INTERP_KERNEL::Exception(oss.str().c_str());
1957 if(size%nbCompExpected!=0)
1959 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1960 throw INTERP_KERNEL::Exception(oss.str().c_str());
1962 nbTuples=size/nbCompExpected;
1966 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1967 if(SWIG_IsOK(status))
1969 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1973 if(d->getNumberOfComponents()==nbCompExpected)
1975 nbTuples=d->getNumberOfTuples();
1976 return d->getConstPointer();
1980 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1981 throw INTERP_KERNEL::Exception(oss.str().c_str());
1988 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1989 throw INTERP_KERNEL::Exception(oss.str().c_str());
1992 { nbTuples=0; return 0; }
1995 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1996 if(SWIG_IsOK(status))
1998 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2002 if(e->getNumberOfCompo()==nbCompExpected)
2005 return e->getConstPointer();
2009 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2010 throw INTERP_KERNEL::Exception(oss.str().c_str());
2017 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2018 throw INTERP_KERNEL::Exception(oss.str().c_str());
2021 { nbTuples=0; return 0; }
2024 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2028 * if value int -> cpp val sw=1
2029 * if value double -> cpp val sw=1
2030 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2031 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2032 * if value list[int,double] -> cpp std::vector<double> sw=4
2033 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2035 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2036 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2038 ParaMEDMEM::DataArrayDouble *d=0;
2039 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2041 if(PyFloat_Check(value))
2043 val=PyFloat_AS_DOUBLE(value);
2048 if(PyInt_Check(value))
2050 val=(double)PyInt_AS_LONG(value);
2055 if(PyTuple_Check(value))
2057 int size=PyTuple_Size(value);
2059 for(int i=0;i<size;i++)
2061 PyObject *o=PyTuple_GetItem(value,i);
2062 if(PyFloat_Check(o))
2063 f[i]=PyFloat_AS_DOUBLE(o);
2064 else if(PyInt_Check(o))
2065 f[i]=(double)PyInt_AS_LONG(o);
2068 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2069 throw INTERP_KERNEL::Exception(oss.str().c_str());
2076 if(PyList_Check(value))
2078 int size=PyList_Size(value);
2080 for(int i=0;i<size;i++)
2082 PyObject *o=PyList_GetItem(value,i);
2083 if(PyFloat_Check(o))
2084 f[i]=PyFloat_AS_DOUBLE(o);
2085 else if(PyInt_Check(o))
2086 f[i]=(double)PyInt_AS_LONG(o);
2089 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2090 throw INTERP_KERNEL::Exception(oss.str().c_str());
2098 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2099 if(SWIG_IsOK(status))
2101 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2105 if(d->getNumberOfComponents()==1)
2107 nbTuples=d->getNumberOfTuples();
2108 return d->getConstPointer();
2112 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2113 throw INTERP_KERNEL::Exception(oss.str().c_str());
2120 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2121 throw INTERP_KERNEL::Exception(oss.str().c_str());
2124 { nbTuples=0; return 0; }
2127 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2128 if(SWIG_IsOK(status))
2130 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2134 nbTuples=e->getNumberOfCompo();
2135 return e->getConstPointer();
2141 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2142 throw INTERP_KERNEL::Exception(oss.str().c_str());
2145 { nbTuples=0; return 0; }
2148 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2152 * if python int -> cpp int sw=1
2153 * if python list[int] -> cpp vector<int> sw=2
2154 * if python tuple[int] -> cpp vector<int> sw=2
2155 * if python DataArrayInt -> cpp DataArrayInt sw=3
2156 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2158 * switch between (int,vector<int>,DataArrayInt)
2160 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2163 if(PyInt_Check(value))
2165 iTyypp=(int)PyInt_AS_LONG(value);
2169 if(PyTuple_Check(value))
2171 int size=PyTuple_Size(value);
2172 stdvecTyypp.resize(size);
2173 for(int i=0;i<size;i++)
2175 PyObject *o=PyTuple_GetItem(value,i);
2177 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2180 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2181 throw INTERP_KERNEL::Exception(oss.str().c_str());
2185 return &stdvecTyypp[0];
2187 if(PyList_Check(value))
2189 int size=PyList_Size(value);
2190 stdvecTyypp.resize(size);
2191 for(int i=0;i<size;i++)
2193 PyObject *o=PyList_GetItem(value,i);
2195 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2198 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2199 throw INTERP_KERNEL::Exception(oss.str().c_str());
2203 return &stdvecTyypp[0];
2206 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2207 if(SWIG_IsOK(status))
2209 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2212 sw=3; sz=daIntTyypp->getNbOfElems();
2213 return daIntTyypp->begin();
2221 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2222 if(SWIG_IsOK(status))
2224 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2225 sw=4; sz=daIntTuple->getNumberOfCompo();
2226 return daIntTuple->getConstPointer();
2228 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2231 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2233 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.";
2234 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2237 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2239 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2241 return (*self)+(*other);
2243 throw INTERP_KERNEL::Exception(msg);
2247 ParaMEDMEM::DataArrayDouble *a;
2248 ParaMEDMEM::DataArrayDoubleTuple *aa;
2249 std::vector<double> bb;
2251 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2256 if(!self->getArray())
2257 throw INTERP_KERNEL::Exception(msg2);
2258 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2259 ret->applyLin(1.,val);
2260 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2261 ret2->setArray(ret);
2266 if(!self->getArray())
2267 throw INTERP_KERNEL::Exception(msg2);
2268 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2269 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2270 ret2->setArray(ret);
2275 if(!self->getArray())
2276 throw INTERP_KERNEL::Exception(msg2);
2277 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2278 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2279 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2280 ret2->setArray(ret);
2285 if(!self->getArray())
2286 throw INTERP_KERNEL::Exception(msg2);
2287 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2288 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2289 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2290 ret2->setArray(ret);
2294 { throw INTERP_KERNEL::Exception(msg); }
2298 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2300 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2303 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2305 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.";
2306 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2309 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2311 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2313 return (*other)-(*self);
2315 throw INTERP_KERNEL::Exception(msg);
2319 ParaMEDMEM::DataArrayDouble *a;
2320 ParaMEDMEM::DataArrayDoubleTuple *aa;
2321 std::vector<double> bb;
2323 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2328 if(!self->getArray())
2329 throw INTERP_KERNEL::Exception(msg2);
2330 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2331 ret->applyLin(-1.,val);
2332 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2333 ret2->setArray(ret);
2338 if(!self->getArray())
2339 throw INTERP_KERNEL::Exception(msg2);
2340 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2341 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2342 ret2->setArray(ret);
2347 if(!self->getArray())
2348 throw INTERP_KERNEL::Exception(msg2);
2349 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2350 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2351 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2352 ret2->setArray(ret);
2357 if(!self->getArray())
2358 throw INTERP_KERNEL::Exception(msg2);
2359 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2360 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2361 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2362 ret2->setArray(ret);
2366 { throw INTERP_KERNEL::Exception(msg); }
2370 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2372 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.";
2373 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2376 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2378 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2380 return (*self)*(*other);
2382 throw INTERP_KERNEL::Exception(msg);
2386 ParaMEDMEM::DataArrayDouble *a;
2387 ParaMEDMEM::DataArrayDoubleTuple *aa;
2388 std::vector<double> bb;
2390 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2395 if(!self->getArray())
2396 throw INTERP_KERNEL::Exception(msg2);
2397 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2398 ret->applyLin(val,0.);
2399 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2400 ret2->setArray(ret);
2405 if(!self->getArray())
2406 throw INTERP_KERNEL::Exception(msg2);
2407 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2408 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2409 ret2->setArray(ret);
2414 if(!self->getArray())
2415 throw INTERP_KERNEL::Exception(msg2);
2416 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2417 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2418 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2419 ret2->setArray(ret);
2424 if(!self->getArray())
2425 throw INTERP_KERNEL::Exception(msg2);
2426 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2427 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2428 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2429 ret2->setArray(ret);
2433 { throw INTERP_KERNEL::Exception(msg); }
2437 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2439 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2442 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2444 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.";
2445 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2448 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2450 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2452 return (*other)/(*self);
2454 throw INTERP_KERNEL::Exception(msg);
2458 ParaMEDMEM::DataArrayDouble *a;
2459 ParaMEDMEM::DataArrayDoubleTuple *aa;
2460 std::vector<double> bb;
2462 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2467 if(!self->getArray())
2468 throw INTERP_KERNEL::Exception(msg2);
2469 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2471 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2472 ret2->setArray(ret);
2477 if(!self->getArray())
2478 throw INTERP_KERNEL::Exception(msg2);
2479 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2480 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2481 ret2->setArray(ret);
2486 if(!self->getArray())
2487 throw INTERP_KERNEL::Exception(msg2);
2488 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2489 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2490 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2491 ret2->setArray(ret);
2496 if(!self->getArray())
2497 throw INTERP_KERNEL::Exception(msg2);
2498 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2499 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2500 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2501 ret2->setArray(ret);
2505 { throw INTERP_KERNEL::Exception(msg); }
2509 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2512 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2513 if(!SWIG_IsOK(status))
2515 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2516 if(!SWIG_IsOK(status))
2518 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2519 if(!SWIG_IsOK(status))
2521 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2522 if(!SWIG_IsOK(status))
2524 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2525 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2526 throw INTERP_KERNEL::Exception(oss.str().c_str());
2531 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);