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))
1129 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1130 throw INTERP_KERNEL::Exception(oss.str().c_str());
1132 T arg=reinterpret_cast< T >(argp);
1136 else if(PyTuple_Check(pyLi))
1138 int size=PyTuple_Size(pyLi);
1140 for(int i=0;i<size;i++)
1142 PyObject *obj=PyTuple_GetItem(pyLi,i);
1143 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1144 if(!SWIG_IsOK(status))
1146 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1147 throw INTERP_KERNEL::Exception(oss.str().c_str());
1149 T arg=reinterpret_cast< T >(argp);
1153 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1156 T arg=reinterpret_cast< T >(argp);
1160 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1164 * if python int -> cpp int sw=1
1165 * if python list[int] -> cpp vector<int> sw=2
1166 * if python tuple[int] -> cpp vector<int> sw=2
1167 * if python DataArrayInt -> cpp DataArrayInt sw=3
1168 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1170 * switch between (int,vector<int>,DataArrayInt)
1172 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1175 if(PyInt_Check(value))
1177 iTyypp=(int)PyInt_AS_LONG(value);
1181 if(PyTuple_Check(value))
1183 int size=PyTuple_Size(value);
1184 stdvecTyypp.resize(size);
1185 for(int i=0;i<size;i++)
1187 PyObject *o=PyTuple_GetItem(value,i);
1189 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1192 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1193 throw INTERP_KERNEL::Exception(oss.str().c_str());
1199 if(PyList_Check(value))
1201 int size=PyList_Size(value);
1202 stdvecTyypp.resize(size);
1203 for(int i=0;i<size;i++)
1205 PyObject *o=PyList_GetItem(value,i);
1207 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1210 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1211 throw INTERP_KERNEL::Exception(oss.str().c_str());
1218 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1219 if(SWIG_IsOK(status))
1221 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1225 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1226 if(SWIG_IsOK(status))
1228 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1232 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1236 * if python double -> cpp double sw=1
1237 * if python int -> cpp double sw=1
1238 * if python list[double] -> cpp vector<double> sw=2
1239 * if python list[int] -> cpp vector<double> sw=2
1240 * if python tuple[double] -> cpp vector<double> sw=2
1241 * if python tuple[int] -> cpp vector<double> sw=2
1242 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1244 * switch between (int,vector<int>,DataArrayInt)
1246 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1249 if(PyFloat_Check(value))
1251 iTyypp=PyFloat_AS_DOUBLE(value);
1255 if(PyInt_Check(value))
1257 iTyypp=(double)PyInt_AS_LONG(value);
1261 if(PyTuple_Check(value))
1263 int size=PyTuple_Size(value);
1264 stdvecTyypp.resize(size);
1265 for(int i=0;i<size;i++)
1267 PyObject *o=PyTuple_GetItem(value,i);
1268 if(PyFloat_Check(o))
1269 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1270 else if(PyInt_Check(o))
1271 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1274 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1275 throw INTERP_KERNEL::Exception(oss.str().c_str());
1281 if(PyList_Check(value))
1283 int size=PyList_Size(value);
1284 stdvecTyypp.resize(size);
1285 for(int i=0;i<size;i++)
1287 PyObject *o=PyList_GetItem(value,i);
1288 if(PyFloat_Check(o))
1289 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1290 else if(PyInt_Check(o))
1291 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1294 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1295 throw INTERP_KERNEL::Exception(oss.str().c_str());
1302 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1303 if(!SWIG_IsOK(status))
1304 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1305 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1310 * if python double -> cpp double sw=1
1311 * if python int -> cpp double sw=1
1312 * if python list[double] -> cpp vector<double> sw=2
1313 * if python list[int] -> cpp vector<double> sw=2
1314 * if python tuple[double] -> cpp vector<double> sw=2
1315 * if python tuple[int] -> cpp vector<double> sw=2
1316 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1318 * switch between (int,vector<int>,DataArrayInt)
1320 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1323 if(PyFloat_Check(value))
1325 iTyypp=PyFloat_AS_DOUBLE(value);
1329 if(PyInt_Check(value))
1331 iTyypp=(double)PyInt_AS_LONG(value);
1335 if(PyTuple_Check(value))
1337 int size=PyTuple_Size(value);
1338 stdvecTyypp.resize(size);
1339 for(int i=0;i<size;i++)
1341 PyObject *o=PyTuple_GetItem(value,i);
1342 if(PyFloat_Check(o))
1343 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1344 else if(PyInt_Check(o))
1345 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1348 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1349 throw INTERP_KERNEL::Exception(oss.str().c_str());
1355 if(PyList_Check(value))
1357 int size=PyList_Size(value);
1358 stdvecTyypp.resize(size);
1359 for(int i=0;i<size;i++)
1361 PyObject *o=PyList_GetItem(value,i);
1362 if(PyFloat_Check(o))
1363 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1364 else if(PyInt_Check(o))
1365 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1368 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1369 throw INTERP_KERNEL::Exception(oss.str().c_str());
1376 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1377 if(!SWIG_IsOK(status))
1378 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1379 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1384 * if python int -> cpp int sw=1
1385 * if python list[int] -> cpp vector<int> sw=2
1386 * if python tuple[int] -> cpp vector<int> sw=2
1387 * if python slicp -> cpp pair sw=3 (begin,end,step)
1388 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1390 * switch between (int,vector<int>,DataArrayInt)
1392 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)
1394 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1396 if(PyInt_Check(value))
1398 iTyypp=(int)PyInt_AS_LONG(value);
1402 if(PyTuple_Check(value))
1404 int size=PyTuple_Size(value);
1405 stdvecTyypp.resize(size);
1406 for(int i=0;i<size;i++)
1408 PyObject *o=PyTuple_GetItem(value,i);
1410 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1413 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1414 throw INTERP_KERNEL::Exception(oss.str().c_str());
1420 if(PyList_Check(value))
1422 int size=PyList_Size(value);
1423 stdvecTyypp.resize(size);
1424 for(int i=0;i<size;i++)
1426 PyObject *o=PyList_GetItem(value,i);
1428 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1431 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1432 throw INTERP_KERNEL::Exception(oss.str().c_str());
1438 if(PySlice_Check(value))
1440 Py_ssize_t strt=2,stp=2,step=2;
1441 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1442 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1443 if(nbelem!=0 || strt!=0 || stp!=0)
1445 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1446 throw INTERP_KERNEL::Exception(oss.str().c_str());
1450 p.second.second=step;
1455 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1456 if(SWIG_IsOK(status))
1458 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1461 std::ostringstream oss; oss << msg << " Instance in null !";
1462 throw INTERP_KERNEL::Exception(oss.str().c_str());
1467 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1468 if(SWIG_IsOK(status))
1470 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1473 std::ostringstream oss; oss << msg << " Instance in null !";
1474 throw INTERP_KERNEL::Exception(oss.str().c_str());
1476 stdvecTyypp.resize(tmp->getNumberOfCompo());
1477 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1481 throw INTERP_KERNEL::Exception(msg);
1485 * if python int -> cpp int sw=1
1486 * if python tuple[int] -> cpp vector<int> sw=2
1487 * if python list[int] -> cpp vector<int> sw=2
1488 * if python slice -> cpp pair sw=3
1489 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1491 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)
1494 if(PyInt_Check(value))
1496 iTyypp=(int)PyInt_AS_LONG(value);
1500 if(PyTuple_Check(value))
1502 int size=PyTuple_Size(value);
1503 stdvecTyypp.resize(size);
1504 for(int i=0;i<size;i++)
1506 PyObject *o=PyTuple_GetItem(value,i);
1508 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1511 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1512 throw INTERP_KERNEL::Exception(oss.str().c_str());
1518 if(PyList_Check(value))
1520 int size=PyList_Size(value);
1521 stdvecTyypp.resize(size);
1522 for(int i=0;i<size;i++)
1524 PyObject *o=PyList_GetItem(value,i);
1526 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1529 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1530 throw INTERP_KERNEL::Exception(oss.str().c_str());
1536 if(PySlice_Check(value))
1538 Py_ssize_t strt=2,stp=2,step=2;
1539 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1540 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1541 if(nbelem!=0 || strt!=0 || stp!=0)
1543 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1544 throw INTERP_KERNEL::Exception(oss.str().c_str());
1548 p.second.second=step;
1553 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1554 if(!SWIG_IsOK(status))
1555 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1556 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1561 * if python string with size one -> cpp char sw=1
1562 * if python string with size different from one -> cpp string sw=2
1563 * if python tuple[string] or list[string] -> vector<string> sw=3
1564 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1565 * switch between (int,string,vector<string>,DataArrayChar)
1567 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1569 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1571 if(PyString_Check(value))
1573 const char *pt=PyString_AsString(value);
1574 Py_ssize_t sz=PyString_Size(value);
1588 if(PyTuple_Check(value))
1590 int size=PyTuple_Size(value);
1591 vsType.resize(size);
1592 for(int i=0;i<size;i++)
1594 PyObject *o=PyTuple_GetItem(value,i);
1595 if(PyString_Check(o))
1596 vsType[i]=PyString_AsString(o);
1599 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1600 throw INTERP_KERNEL::Exception(oss.str().c_str());
1606 if(PyList_Check(value))
1608 int size=PyList_Size(value);
1609 vsType.resize(size);
1610 for(int i=0;i<size;i++)
1612 PyObject *o=PyList_GetItem(value,i);
1613 if(PyString_Check(o))
1614 vsType[i]=PyString_AsString(o);
1617 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1618 throw INTERP_KERNEL::Exception(oss.str().c_str());
1625 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1626 if(SWIG_IsOK(status))
1628 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1631 std::ostringstream oss; oss << msg << " Instance in null !";
1632 throw INTERP_KERNEL::Exception(oss.str().c_str());
1637 throw INTERP_KERNEL::Exception(msg);
1641 * if value int -> cpp it sw=1
1642 * if value list[int] -> vt sw=2
1643 * if value tuple[int] -> vt sw=2
1644 * if value slice -> pt sw=3
1645 * if value DataArrayInt -> dt sw=4
1646 * if value tuple [int,int] -> cpp it,ip sw=5
1647 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1648 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1649 * if value tuple [slice,int] -> cpp pt,ip sw=7
1650 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1651 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1652 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1653 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1654 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1655 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1656 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1657 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1658 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1659 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1660 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1661 * if value tuple [int,slice] -> cpp it,pc sw=13
1662 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1663 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1664 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1665 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1667 * switch between (int,vector<int>,DataArrayInt)
1669 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1670 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1671 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1673 if(!PyTuple_Check(value))
1675 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1680 int sz=PyTuple_Size(value);
1682 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1683 PyObject *ob0=PyTuple_GetItem(value,0);
1685 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1686 PyObject *ob1=PyTuple_GetItem(value,1);
1687 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1693 * if value int -> cpp val sw=1
1694 * if value double -> cpp val sw=1
1695 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1696 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1697 * if value list[int,double] -> cpp std::vector<double> sw=4
1698 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1700 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1703 if(PyFloat_Check(value))
1705 val=PyFloat_AS_DOUBLE(value);
1709 if(PyInt_Check(value))
1711 val=(double)PyInt_AS_LONG(value);
1715 if(PyTuple_Check(value))
1717 int size=PyTuple_Size(value);
1719 for(int i=0;i<size;i++)
1721 PyObject *o=PyTuple_GetItem(value,i);
1722 if(PyFloat_Check(o))
1723 f[i]=PyFloat_AS_DOUBLE(o);
1724 else if(PyInt_Check(o))
1725 f[i]=(double)PyInt_AS_LONG(o);
1728 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1729 throw INTERP_KERNEL::Exception(oss.str().c_str());
1735 if(PyList_Check(value))
1737 int size=PyList_Size(value);
1739 for(int i=0;i<size;i++)
1741 PyObject *o=PyList_GetItem(value,i);
1742 if(PyFloat_Check(o))
1743 f[i]=PyFloat_AS_DOUBLE(o);
1744 else if(PyInt_Check(o))
1745 f[i]=(double)PyInt_AS_LONG(o);
1748 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1749 throw INTERP_KERNEL::Exception(oss.str().c_str());
1756 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1757 if(SWIG_IsOK(status))
1759 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1763 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1764 if(SWIG_IsOK(status))
1766 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1770 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1774 * if value int -> cpp val sw=1
1775 * if value double -> cpp val sw=1
1776 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1777 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1778 * if value list[int,double] -> cpp std::vector<double> sw=4
1779 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1781 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1782 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1785 if(PyFloat_Check(value))
1787 val=PyFloat_AS_DOUBLE(value);
1789 if(nbTuplesExpected*nbCompExpected!=1)
1791 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1792 throw INTERP_KERNEL::Exception(oss.str().c_str());
1796 if(PyInt_Check(value))
1798 val=(double)PyInt_AS_LONG(value);
1800 if(nbTuplesExpected*nbCompExpected!=1)
1802 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1803 throw INTERP_KERNEL::Exception(oss.str().c_str());
1807 if(PyTuple_Check(value) || PyList_Check(value))
1811 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1812 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1817 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1820 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1821 if(SWIG_IsOK(status))
1823 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1827 if(d->getNumberOfTuples()==nbTuplesExpected)
1829 if(d->getNumberOfComponents()==nbCompExpected)
1831 return d->getConstPointer();
1835 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1836 throw INTERP_KERNEL::Exception(oss.str().c_str());
1841 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1842 throw INTERP_KERNEL::Exception(oss.str().c_str());
1849 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1850 throw INTERP_KERNEL::Exception(oss.str().c_str());
1856 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1857 if(SWIG_IsOK(status))
1859 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1861 if(e->getNumberOfCompo()==nbCompExpected)
1863 if(nbTuplesExpected==1)
1864 return e->getConstPointer();
1867 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1868 throw INTERP_KERNEL::Exception(oss.str().c_str());
1873 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1874 throw INTERP_KERNEL::Exception(oss.str().c_str());
1877 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1881 * if value int -> cpp val sw=1
1882 * if value double -> cpp val sw=1
1883 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1884 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1885 * if value list[int,double] -> cpp std::vector<double> sw=4
1886 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1888 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1889 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1892 if(PyFloat_Check(value))
1894 val=PyFloat_AS_DOUBLE(value);
1896 if(nbCompExpected!=1)
1898 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1899 throw INTERP_KERNEL::Exception(oss.str().c_str());
1904 if(PyInt_Check(value))
1906 val=(double)PyInt_AS_LONG(value);
1908 if(nbCompExpected!=1)
1910 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1911 throw INTERP_KERNEL::Exception(oss.str().c_str());
1916 if(PyTuple_Check(value))
1918 int size=PyTuple_Size(value);
1920 for(int i=0;i<size;i++)
1922 PyObject *o=PyTuple_GetItem(value,i);
1923 if(PyFloat_Check(o))
1924 f[i]=PyFloat_AS_DOUBLE(o);
1925 else if(PyInt_Check(o))
1926 f[i]=(double)PyInt_AS_LONG(o);
1929 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1930 throw INTERP_KERNEL::Exception(oss.str().c_str());
1934 if(size%nbCompExpected!=0)
1936 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1937 throw INTERP_KERNEL::Exception(oss.str().c_str());
1939 nbTuples=size/nbCompExpected;
1942 if(PyList_Check(value))
1944 int size=PyList_Size(value);
1946 for(int i=0;i<size;i++)
1948 PyObject *o=PyList_GetItem(value,i);
1949 if(PyFloat_Check(o))
1950 f[i]=PyFloat_AS_DOUBLE(o);
1951 else if(PyInt_Check(o))
1952 f[i]=(double)PyInt_AS_LONG(o);
1955 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1956 throw INTERP_KERNEL::Exception(oss.str().c_str());
1960 if(size%nbCompExpected!=0)
1962 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1963 throw INTERP_KERNEL::Exception(oss.str().c_str());
1965 nbTuples=size/nbCompExpected;
1969 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1970 if(SWIG_IsOK(status))
1972 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1976 if(d->getNumberOfComponents()==nbCompExpected)
1978 nbTuples=d->getNumberOfTuples();
1979 return d->getConstPointer();
1983 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1984 throw INTERP_KERNEL::Exception(oss.str().c_str());
1991 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1992 throw INTERP_KERNEL::Exception(oss.str().c_str());
1995 { nbTuples=0; return 0; }
1998 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1999 if(SWIG_IsOK(status))
2001 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2005 if(e->getNumberOfCompo()==nbCompExpected)
2008 return e->getConstPointer();
2012 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2013 throw INTERP_KERNEL::Exception(oss.str().c_str());
2020 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2021 throw INTERP_KERNEL::Exception(oss.str().c_str());
2024 { nbTuples=0; return 0; }
2027 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2031 * if value int -> cpp val sw=1
2032 * if value double -> cpp val sw=1
2033 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2034 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2035 * if value list[int,double] -> cpp std::vector<double> sw=4
2036 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2038 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2039 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2041 ParaMEDMEM::DataArrayDouble *d=0;
2042 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2044 if(PyFloat_Check(value))
2046 val=PyFloat_AS_DOUBLE(value);
2051 if(PyInt_Check(value))
2053 val=(double)PyInt_AS_LONG(value);
2058 if(PyTuple_Check(value))
2060 int size=PyTuple_Size(value);
2062 for(int i=0;i<size;i++)
2064 PyObject *o=PyTuple_GetItem(value,i);
2065 if(PyFloat_Check(o))
2066 f[i]=PyFloat_AS_DOUBLE(o);
2067 else if(PyInt_Check(o))
2068 f[i]=(double)PyInt_AS_LONG(o);
2071 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2072 throw INTERP_KERNEL::Exception(oss.str().c_str());
2079 if(PyList_Check(value))
2081 int size=PyList_Size(value);
2083 for(int i=0;i<size;i++)
2085 PyObject *o=PyList_GetItem(value,i);
2086 if(PyFloat_Check(o))
2087 f[i]=PyFloat_AS_DOUBLE(o);
2088 else if(PyInt_Check(o))
2089 f[i]=(double)PyInt_AS_LONG(o);
2092 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2093 throw INTERP_KERNEL::Exception(oss.str().c_str());
2101 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2102 if(SWIG_IsOK(status))
2104 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2108 if(d->getNumberOfComponents()==1)
2110 nbTuples=d->getNumberOfTuples();
2111 return d->getConstPointer();
2115 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2116 throw INTERP_KERNEL::Exception(oss.str().c_str());
2123 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2124 throw INTERP_KERNEL::Exception(oss.str().c_str());
2127 { nbTuples=0; return 0; }
2130 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2131 if(SWIG_IsOK(status))
2133 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2137 nbTuples=e->getNumberOfCompo();
2138 return e->getConstPointer();
2144 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2145 throw INTERP_KERNEL::Exception(oss.str().c_str());
2148 { nbTuples=0; return 0; }
2151 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2155 * if python int -> cpp int sw=1
2156 * if python list[int] -> cpp vector<int> sw=2
2157 * if python tuple[int] -> cpp vector<int> sw=2
2158 * if python DataArrayInt -> cpp DataArrayInt sw=3
2159 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2161 * switch between (int,vector<int>,DataArrayInt)
2163 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2166 if(PyInt_Check(value))
2168 iTyypp=(int)PyInt_AS_LONG(value);
2172 if(PyTuple_Check(value))
2174 int size=PyTuple_Size(value);
2175 stdvecTyypp.resize(size);
2176 for(int i=0;i<size;i++)
2178 PyObject *o=PyTuple_GetItem(value,i);
2180 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2183 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2184 throw INTERP_KERNEL::Exception(oss.str().c_str());
2188 return &stdvecTyypp[0];
2190 if(PyList_Check(value))
2192 int size=PyList_Size(value);
2193 stdvecTyypp.resize(size);
2194 for(int i=0;i<size;i++)
2196 PyObject *o=PyList_GetItem(value,i);
2198 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2201 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2202 throw INTERP_KERNEL::Exception(oss.str().c_str());
2206 return &stdvecTyypp[0];
2209 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2210 if(SWIG_IsOK(status))
2212 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2215 sw=3; sz=daIntTyypp->getNbOfElems();
2216 return daIntTyypp->begin();
2224 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2225 if(SWIG_IsOK(status))
2227 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2228 sw=4; sz=daIntTuple->getNumberOfCompo();
2229 return daIntTuple->getConstPointer();
2231 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2234 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2236 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.";
2237 const char msg2[]="in MEDCouplingFieldDouble.__add__ : self field has no Array of values set !";
2240 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2242 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2244 return (*self)+(*other);
2246 throw INTERP_KERNEL::Exception(msg);
2250 ParaMEDMEM::DataArrayDouble *a;
2251 ParaMEDMEM::DataArrayDoubleTuple *aa;
2252 std::vector<double> bb;
2254 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2259 if(!self->getArray())
2260 throw INTERP_KERNEL::Exception(msg2);
2261 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2262 ret->applyLin(1.,val);
2263 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2264 ret2->setArray(ret);
2269 if(!self->getArray())
2270 throw INTERP_KERNEL::Exception(msg2);
2271 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),a);
2272 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2273 ret2->setArray(ret);
2278 if(!self->getArray())
2279 throw INTERP_KERNEL::Exception(msg2);
2280 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2281 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2282 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2283 ret2->setArray(ret);
2288 if(!self->getArray())
2289 throw INTERP_KERNEL::Exception(msg2);
2290 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2291 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Add(self->getArray(),aaa);
2292 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2293 ret2->setArray(ret);
2297 { throw INTERP_KERNEL::Exception(msg); }
2301 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___radd__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2303 return ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(self,obj);
2306 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rsub__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2308 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.";
2309 const char msg2[]="in MEDCouplingFieldDouble.__rsub__ : self field has no Array of values set !";
2312 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2314 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2316 return (*other)-(*self);
2318 throw INTERP_KERNEL::Exception(msg);
2322 ParaMEDMEM::DataArrayDouble *a;
2323 ParaMEDMEM::DataArrayDoubleTuple *aa;
2324 std::vector<double> bb;
2326 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2331 if(!self->getArray())
2332 throw INTERP_KERNEL::Exception(msg2);
2333 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2334 ret->applyLin(-1.,val);
2335 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2336 ret2->setArray(ret);
2341 if(!self->getArray())
2342 throw INTERP_KERNEL::Exception(msg2);
2343 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(a,self->getArray());
2344 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2345 ret2->setArray(ret);
2350 if(!self->getArray())
2351 throw INTERP_KERNEL::Exception(msg2);
2352 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2353 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2354 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2355 ret2->setArray(ret);
2360 if(!self->getArray())
2361 throw INTERP_KERNEL::Exception(msg2);
2362 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2363 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Substract(aaa,self->getArray());
2364 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2365 ret2->setArray(ret);
2369 { throw INTERP_KERNEL::Exception(msg); }
2373 static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2375 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.";
2376 const char msg2[]="in MEDCouplingFieldDouble.__mul__ : self field has no Array of values set !";
2379 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2381 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2383 return (*self)*(*other);
2385 throw INTERP_KERNEL::Exception(msg);
2389 ParaMEDMEM::DataArrayDouble *a;
2390 ParaMEDMEM::DataArrayDoubleTuple *aa;
2391 std::vector<double> bb;
2393 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2398 if(!self->getArray())
2399 throw INTERP_KERNEL::Exception(msg2);
2400 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2401 ret->applyLin(val,0.);
2402 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2403 ret2->setArray(ret);
2408 if(!self->getArray())
2409 throw INTERP_KERNEL::Exception(msg2);
2410 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),a);
2411 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2412 ret2->setArray(ret);
2417 if(!self->getArray())
2418 throw INTERP_KERNEL::Exception(msg2);
2419 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2420 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2421 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2422 ret2->setArray(ret);
2427 if(!self->getArray())
2428 throw INTERP_KERNEL::Exception(msg2);
2429 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2430 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Multiply(self->getArray(),aaa);
2431 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2432 ret2->setArray(ret);
2436 { throw INTERP_KERNEL::Exception(msg); }
2440 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rmul__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2442 return ParaMEDMEM_MEDCouplingFieldDouble___mul__Impl(self,obj);
2445 ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___rdiv__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)
2447 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.";
2448 const char msg2[]="in MEDCouplingFieldDouble.__div__ : self field has no Array of values set !";
2451 if(SWIG_IsOK(SWIG_ConvertPtr(obj,&argp,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDouble,0|0)))
2453 ParaMEDMEM::MEDCouplingFieldDouble *other=reinterpret_cast< ParaMEDMEM::MEDCouplingFieldDouble * >(argp);
2455 return (*other)/(*self);
2457 throw INTERP_KERNEL::Exception(msg);
2461 ParaMEDMEM::DataArrayDouble *a;
2462 ParaMEDMEM::DataArrayDoubleTuple *aa;
2463 std::vector<double> bb;
2465 convertObjToPossibleCpp5(obj,sw,val,a,aa,bb);
2470 if(!self->getArray())
2471 throw INTERP_KERNEL::Exception(msg2);
2472 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=self->getArray()->deepCpy();
2474 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2475 ret2->setArray(ret);
2480 if(!self->getArray())
2481 throw INTERP_KERNEL::Exception(msg2);
2482 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(a,self->getArray());
2483 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2484 ret2->setArray(ret);
2489 if(!self->getArray())
2490 throw INTERP_KERNEL::Exception(msg2);
2491 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=aa->buildDADouble(1,self->getNumberOfComponents());
2492 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2493 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2494 ret2->setArray(ret);
2499 if(!self->getArray())
2500 throw INTERP_KERNEL::Exception(msg2);
2501 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> aaa=ParaMEDMEM::DataArrayDouble::New(); aaa->useArray(&bb[0],false,ParaMEDMEM::CPP_DEALLOC,1,(int)bb.size());
2502 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> ret=ParaMEDMEM::DataArrayDouble::Divide(aaa,self->getArray());
2503 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::MEDCouplingFieldDouble> ret2=self->clone(false);
2504 ret2->setArray(ret);
2508 { throw INTERP_KERNEL::Exception(msg); }
2512 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2515 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2516 if(!SWIG_IsOK(status))
2518 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2519 if(!SWIG_IsOK(status))
2521 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2522 if(!SWIG_IsOK(status))
2524 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2525 if(!SWIG_IsOK(status))
2527 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2528 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2529 throw INTERP_KERNEL::Exception(oss.str().c_str());
2534 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);