1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelAutoPtr.hxx"
24 * This method is an extention of PySlice_GetIndices but less
25 * open than PySlice_GetIndicesEx that accepts too many situations.
27 void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
29 int ret(PySlice_GetIndices(slice,length,start,stop,step));
32 if(*step>0 && *start==*stop && length==*start)
34 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
38 * This method allows to retrieve slice info from \a slice.
40 void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
42 int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
45 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
47 std::ostringstream oss;
48 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
49 throw INTERP_KERNEL::Exception(oss.str().c_str());
51 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
54 int InterpreteNegativeInt(int val, int nbelem)
58 int newVal(nbelem+val);
61 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
62 throw INTERP_KERNEL::Exception(oss.str().c_str());
71 #include <numpy/arrayobject.h>
73 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
74 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
75 // if no more alive the "standart" DataArray deallocator is called.
76 void numarrdeal(void *pt, void *wron)
78 void **wronc=(void **)wron;
79 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
80 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
84 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
85 objC->flags|=NPY_ARRAY_OWNDATA;
86 Py_XDECREF(weakRefOnOwner);
91 typedef void (*MyDeallocator)(void *,void *);
92 MyDeallocator deall=(MyDeallocator)wronc[1];
94 Py_XDECREF(weakRefOnOwner);
99 template<class MCData>
100 struct PyCallBackDataArraySt {
105 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
106 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
110 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
112 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
114 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
115 return (PyObject *)self;
118 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
120 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
121 return (PyObject *)self;
124 static void callbackmcdataarray_dealloc(PyObject *self)
126 Py_TYPE(self)->tp_free(self);
129 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
130 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
131 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
135 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
142 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
143 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
144 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
148 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
156 PyTypeObject PyCallBackDataArrayInt_RefType = {
157 PyVarObject_HEAD_INIT(&PyType_Type, 0)
158 "callbackmcdataarrayint",
159 sizeof(PyCallBackDataArrayInt),
161 callbackmcdataarray_dealloc, /*tp_dealloc*/
168 0, /*tp_as_sequence*/
171 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
176 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
180 0, /*tp_richcompare*/
181 0, /*tp_weaklistoffset*/
192 callbackmcdataarray___init__, /*tp_init*/
193 PyType_GenericAlloc, /*tp_alloc*/
194 callbackmcdataarrayint___new__, /*tp_new*/
195 PyObject_GC_Del, /*tp_free*/
198 PyTypeObject PyCallBackDataArrayDouble_RefType = {
199 PyVarObject_HEAD_INIT(&PyType_Type, 0)
200 "callbackmcdataarraydouble",
201 sizeof(PyCallBackDataArrayDouble),
203 callbackmcdataarray_dealloc, /*tp_dealloc*/
210 0, /*tp_as_sequence*/
213 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
218 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
222 0, /*tp_richcompare*/
223 0, /*tp_weaklistoffset*/
234 callbackmcdataarray___init__, /*tp_init*/
235 PyType_GenericAlloc, /*tp_alloc*/
236 callbackmcdataarraydouble___new__, /*tp_new*/
237 PyObject_GC_Del, /*tp_free*/
240 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
241 // in input when an another DataArray is already client of this.
242 template<class MCData>
243 void numarrdeal2(void *pt, void *obj)
245 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
246 void **obj1=(void **)obj;
247 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
248 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
250 Py_XDECREF(weakRefOnOwner);
255 template<class MCData, class T>
256 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
258 int ndim=PyArray_NDIM(elt0);
259 if(ndim!=1 && ndim!=2)
260 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
261 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
263 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
264 throw INTERP_KERNEL::Exception(oss.str().c_str());
266 npy_intp sz0=PyArray_DIM(elt0,0);
267 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
269 int itemSize=PyArray_ITEMSIZE(elt0);
270 if(itemSize!=sizeof(T))
272 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
273 throw INTERP_KERNEL::Exception(oss.str().c_str());
275 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
276 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
278 if(itemSize!=PyArray_STRIDE(elt0,1))
279 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 !");
280 const char *data=PyArray_BYTES(elt0);
281 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
282 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
284 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
285 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_ARRAY_OWNDATA)?elt0C:NULL;
286 int mask=NPY_ARRAY_OWNDATA; mask=~mask;
288 PyObject *deepestObj=elt0;
289 PyObject *base=elt0C->base;
290 if(base) deepestObj=base;
291 bool isSpetialCase(false);
294 if(PyArray_Check(base))
296 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
297 eltOwning=(PyArray_FLAGS(baseC) & NPY_ARRAY_OWNDATA)?baseC:eltOwning;
300 if(base) deepestObj=base;
309 {// this case is present for numpy arrayint coming from load of pickelized string. The owner of elt0 is not an array -> A copy is requested.
310 std::size_t nbOfElems(sz0*sz1);
311 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
312 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
313 ret->useArray(dataCpy,true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
316 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
319 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
321 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
322 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
323 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
324 mma.setParameterForDeallocator(objs);
325 mma.setSpecificDeallocator(numarrdeal2<MCData>);
326 //"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 !");
330 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
331 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
332 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(ParaMEDMEM::MemArray<T>::CDeallocator);
333 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
334 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
335 mma.setParameterForDeallocator(objs);
336 mma.setSpecificDeallocator(numarrdeal);
339 else if(PyArray_ISBEHAVED_RO(elt0))
340 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
345 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
348 PyErr_SetString(PyExc_ValueError,
349 "Cannot set the NumPy array 'base' "
350 "dependency to NULL after initialization");
354 * Allow the base to be set only once. Once the object which
355 * owns the data is set, it doesn't make sense to change it.
357 if (PyArray_BASE(arr) != NULL) {
359 PyErr_SetString(PyExc_ValueError,
360 "Cannot set the NumPy array 'base' "
361 "dependency more than once");
366 * Don't allow infinite chains of views, always set the base
367 * to the first owner of the data.
368 * That is, either the first object which isn't an array,
369 * or the first object which owns its own data.
372 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
373 PyArrayObject *obj_arr = (PyArrayObject *)obj;
377 /* If this array owns its own data, stop collapsing */
378 if (PyArray_CHKFLAGS(obj_arr, NPY_ARRAY_OWNDATA )) {
382 tmp = PyArray_BASE(obj_arr);
383 /* If there's no base, stop collapsing */
387 /* Stop the collapse new base when the would not be of the same
388 * type (i.e. different subclass).
390 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
400 /* Disallow circular references */
401 if ((PyObject *)arr == obj) {
403 PyErr_SetString(PyExc_ValueError,
404 "Cannot create a circular NumPy array 'base' dependency");
413 template<class MCData, class T>
414 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
416 if(!self->isAllocated())
418 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
419 throw INTERP_KERNEL::Exception(oss.str().c_str());
421 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
424 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
425 throw INTERP_KERNEL::Exception(oss.str().c_str());
427 int nbDims=nbComp==1?1:2;
429 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
430 const T *bg=self->getConstPointer();
431 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
432 if(mem.isDeallocatorCalled())
434 if(mem.getDeallocator()!=numarrdeal)
435 {// case for the first call of toNumPyArray
436 PyObject *ref(PyWeakref_NewRef(ret,NULL));
437 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
438 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
439 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
440 mem.setParameterForDeallocator(objs);
441 mem.setSpecificDeallocator(numarrdeal);
445 {// case for the second and other call of toNumPyArray
446 void **objs=(void **)mem.getParameterForDeallocator();
447 PyObject *weakRefOnOwner=(PyObject *)objs[0];
448 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
450 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
452 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
455 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
456 Py_XDECREF(weakRefOnOwner);
457 PyObject *ref=PyWeakref_NewRef(ret,NULL);
465 template<class MCData, class T>
466 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
468 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
471 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
472 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
474 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
476 int nbRows((int)m.size());
477 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
478 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
479 indPtr->alloc(nbRows+1,1);
480 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
482 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
484 sz2+=(int)(*it0).size();
487 indices->alloc(sz2,1); data->alloc(sz2,1);
488 int *indices_ptr(indices->getPointer());
489 double *data_ptr(data->getPointer());
490 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
491 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
493 *indices_ptr=(*it1).first;
494 *data_ptr=(*it1).second;
496 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
498 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
499 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
500 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
501 PyObject *tmp1(PyString_FromString("shape"));
502 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
503 PyObject* pdict=PyDict_New();
504 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
505 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
507 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
508 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
510 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
511 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
512 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
518 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
526 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
527 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
528 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
529 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
531 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
535 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
543 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
544 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
545 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
546 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
547 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
548 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
549 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
550 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
552 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
556 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
558 PyObject *ret=PyList_New(size);
559 for(int i=0;i<size;i++)
560 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
564 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
567 PyObject *ret=PyList_New(size);
568 for(int i=0;i<size;i++)
569 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
573 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
576 PyObject *ret=PyList_New(size);
577 std::set<int>::const_iterator it=v.begin();
578 for(int i=0;i<size;i++,it++)
579 PyList_SetItem(ret,i,PyInt_FromLong(*it));
583 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
585 PyObject *ret=PyList_New(nbOfTuples);
586 for(int i=0;i<nbOfTuples;i++)
588 PyObject *t=PyTuple_New(nbOfComp);
589 for(int j=0;j<nbOfComp;j++)
590 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
591 PyList_SetItem(ret,i,t);
596 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
598 if(PyList_Check(pyLi))
600 *size=PyList_Size(pyLi);
601 int *tmp=new int[*size];
602 for(int i=0;i<*size;i++)
604 PyObject *o=PyList_GetItem(pyLi,i);
607 int val=(int)PyInt_AS_LONG(o);
613 throw INTERP_KERNEL::Exception("list must contain integers only");
618 else if(PyTuple_Check(pyLi))
620 *size=PyTuple_Size(pyLi);
621 int *tmp=new int[*size];
622 for(int i=0;i<*size;i++)
624 PyObject *o=PyTuple_GetItem(pyLi,i);
627 int val=(int)PyInt_AS_LONG(o);
633 throw INTERP_KERNEL::Exception("tuple must contain integers only");
640 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
644 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
646 PyObject *ret=PyList_New(arr.size());
647 for(std::size_t i=0;i<arr.size();i++)
649 PyObject *t=PyTuple_New(2);
650 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
651 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
652 PyList_SetItem(ret,i,t);
657 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
659 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
660 if(PyList_Check(pyLi))
662 int size=PyList_Size(pyLi);
664 for(int i=0;i<size;i++)
666 PyObject *o=PyList_GetItem(pyLi,i);
669 int sz2=PyTuple_Size(o);
671 throw INTERP_KERNEL::Exception(msg);
672 PyObject *o_0=PyTuple_GetItem(o,0);
673 if(!PyInt_Check(o_0))
674 throw INTERP_KERNEL::Exception(msg);
675 PyObject *o_1=PyTuple_GetItem(o,1);
676 if(!PyInt_Check(o_1))
677 throw INTERP_KERNEL::Exception(msg);
678 arr[i].first=(int)PyInt_AS_LONG(o_0);
679 arr[i].second=(int)PyInt_AS_LONG(o_1);
682 throw INTERP_KERNEL::Exception(msg);
685 else if(PyTuple_Check(pyLi))
687 int size=PyTuple_Size(pyLi);
689 for(int i=0;i<size;i++)
691 PyObject *o=PyTuple_GetItem(pyLi,i);
694 int sz2=PyTuple_Size(o);
696 throw INTERP_KERNEL::Exception(msg);
697 PyObject *o_0=PyTuple_GetItem(o,0);
698 if(!PyInt_Check(o_0))
699 throw INTERP_KERNEL::Exception(msg);
700 PyObject *o_1=PyTuple_GetItem(o,1);
701 if(!PyInt_Check(o_1))
702 throw INTERP_KERNEL::Exception(msg);
703 arr[i].first=(int)PyInt_AS_LONG(o_0);
704 arr[i].second=(int)PyInt_AS_LONG(o_1);
707 throw INTERP_KERNEL::Exception(msg);
711 throw INTERP_KERNEL::Exception(msg);
714 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
716 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
717 if(PyList_Check(pyLi))
719 int size=PyList_Size(pyLi);
721 for(int i=0;i<size;i++)
723 PyObject *o=PyList_GetItem(pyLi,i);
726 int sz2=PyTuple_Size(o);
728 throw INTERP_KERNEL::Exception(msg);
729 PyObject *o_0=PyTuple_GetItem(o,0);
730 if(!PyString_Check(o_0))
731 throw INTERP_KERNEL::Exception(msg);
732 PyObject *o_1=PyTuple_GetItem(o,1);
733 if(!PyInt_Check(o_1))
734 throw INTERP_KERNEL::Exception(msg);
735 arr[i].first=PyString_AsString(o_0);
736 arr[i].second=(int)PyInt_AS_LONG(o_1);
739 throw INTERP_KERNEL::Exception(msg);
742 else if(PyTuple_Check(pyLi))
744 int size=PyTuple_Size(pyLi);
746 for(int i=0;i<size;i++)
748 PyObject *o=PyTuple_GetItem(pyLi,i);
751 int sz2=PyTuple_Size(o);
753 throw INTERP_KERNEL::Exception(msg);
754 PyObject *o_0=PyTuple_GetItem(o,0);
755 if(!PyString_Check(o_0))
756 throw INTERP_KERNEL::Exception(msg);
757 PyObject *o_1=PyTuple_GetItem(o,1);
758 if(!PyInt_Check(o_1))
759 throw INTERP_KERNEL::Exception(msg);
760 arr[i].first=PyString_AsString(o_0);
761 arr[i].second=(int)PyInt_AS_LONG(o_1);
764 throw INTERP_KERNEL::Exception(msg);
768 throw INTERP_KERNEL::Exception(msg);
771 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
773 if(PyList_Check(pyLi))
775 int size=PyList_Size(pyLi);
777 for(int i=0;i<size;i++)
779 PyObject *o=PyList_GetItem(pyLi,i);
782 int val=(int)PyInt_AS_LONG(o);
786 throw INTERP_KERNEL::Exception("list must contain integers only");
789 else if(PyTuple_Check(pyLi))
791 int size=PyTuple_Size(pyLi);
793 for(int i=0;i<size;i++)
795 PyObject *o=PyTuple_GetItem(pyLi,i);
798 int val=(int)PyInt_AS_LONG(o);
802 throw INTERP_KERNEL::Exception("tuple must contain integers only");
807 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
811 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
814 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
816 if(PyList_Check(pyLi))
818 int size=PyList_Size(pyLi);
819 for(int i=0;i<size;i++)
821 PyObject *o=PyList_GetItem(pyLi,i);
824 int val=(int)PyInt_AS_LONG(o);
829 std::vector<int> arr2;
830 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
831 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
833 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
834 throw INTERP_KERNEL::Exception(oss.str().c_str());
836 arr.insert(arr.end(),arr2.begin(),arr2.end());
840 else if(PyTuple_Check(pyLi))
842 int size=PyTuple_Size(pyLi);
843 for(int i=0;i<size;i++)
845 PyObject *o=PyTuple_GetItem(pyLi,i);
848 int val=(int)PyInt_AS_LONG(o);
853 std::vector<int> arr2;
854 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
855 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
857 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
858 throw INTERP_KERNEL::Exception(oss.str().c_str());
860 arr.insert(arr.end(),arr2.begin(),arr2.end());
865 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
868 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
872 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
873 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
875 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
876 oss << " whereas nb of components expected is " << nbOfComp << " !";
877 throw INTERP_KERNEL::Exception(oss.str().c_str());
884 if((nbOfTuples!=size1 || nbOfComp!=size2))
886 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
888 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
889 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
890 throw INTERP_KERNEL::Exception(oss.str().c_str());
896 if(nbOfTuples==size1)
900 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
901 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
902 throw INTERP_KERNEL::Exception(oss.str().c_str());
908 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
910 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
911 if(PyInt_Check(pyLi))
913 long val=PyInt_AS_LONG(pyLi);
918 throw INTERP_KERNEL::Exception(MSG);
921 else if(PyList_Check(pyLi))
923 int size=PyList_Size(pyLi);
925 for(int i=0;i<size;i++)
927 PyObject *o=PyList_GetItem(pyLi,i);
929 fillArrayWithPyListInt3(o,tmp1,ret);
937 throw INTERP_KERNEL::Exception(MSG);
940 else if(PyTuple_Check(pyLi))
942 int size=PyTuple_Size(pyLi);
944 for(int i=0;i<size;i++)
946 PyObject *o=PyTuple_GetItem(pyLi,i);
948 fillArrayWithPyListInt3(o,tmp1,ret);
956 throw INTERP_KERNEL::Exception(MSG);
960 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
963 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
965 std::vector<int> ret;
966 int size1=-1,size2=-1;
967 if(PyList_Check(pyLi))
969 size1=PyList_Size(pyLi);
970 for(int i=0;i<size1;i++)
972 PyObject *o=PyList_GetItem(pyLi,i);
973 fillArrayWithPyListInt3(o,size2,ret);
978 else if(PyTuple_Check(pyLi))
980 size1=PyTuple_Size(pyLi);
981 for(int i=0;i<size1;i++)
983 PyObject *o=PyTuple_GetItem(pyLi,i);
984 fillArrayWithPyListInt3(o,size2,ret);
990 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
992 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
996 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
998 if(PyList_Check(pyLi))
1000 Py_ssize_t sz=PyList_Size(pyLi);
1002 for(int i=0;i<sz;i++)
1004 PyObject *o=PyList_GetItem(pyLi,i);
1005 if(PyString_Check(o))
1006 vec[i]=PyString_AsString(o);
1012 else if(PyTuple_Check(pyLi))
1014 Py_ssize_t sz=PyTuple_Size(pyLi);
1016 for(int i=0;i<sz;i++)
1018 PyObject *o=PyTuple_GetItem(pyLi,i);
1019 if(PyString_Check(o))
1020 vec[i]=PyString_AsString(o);
1029 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
1031 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1032 if(PyList_Check(pyLi))
1034 Py_ssize_t sz=PyList_Size(pyLi);
1036 for(int i=0;i<sz;i++)
1038 PyObject *o=PyList_GetItem(pyLi,i);
1039 if(!fillStringVector(o,arr[i]))
1040 throw INTERP_KERNEL::Exception(msg);
1043 else if(PyTuple_Check(pyLi))
1045 Py_ssize_t sz=PyTuple_Size(pyLi);
1047 for(int i=0;i<sz;i++)
1049 PyObject *o=PyTuple_GetItem(pyLi,i);
1050 if(!fillStringVector(o,arr[i]))
1051 throw INTERP_KERNEL::Exception(msg);
1055 throw INTERP_KERNEL::Exception(msg);
1058 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
1060 if(PyList_Check(pyLi))
1062 Py_ssize_t sz=PyList_Size(pyLi);
1064 for(int i=0;i<sz;i++)
1066 PyObject *o=PyList_GetItem(pyLi,i);
1068 vec[i]=PyInt_AS_LONG(o);
1074 else if(PyTuple_Check(pyLi))
1076 Py_ssize_t sz=PyTuple_Size(pyLi);
1078 for(int i=0;i<sz;i++)
1080 PyObject *o=PyTuple_GetItem(pyLi,i);
1082 vec[i]=PyInt_AS_LONG(o);
1092 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
1094 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1095 if(PyList_Check(pyLi))
1097 Py_ssize_t sz=PyList_Size(pyLi);
1099 for(int i=0;i<sz;i++)
1101 PyObject *o=PyList_GetItem(pyLi,i);
1102 if(!fillIntVector(o,arr[i]))
1103 throw INTERP_KERNEL::Exception(msg);
1106 else if(PyTuple_Check(pyLi))
1108 Py_ssize_t sz=PyTuple_Size(pyLi);
1110 for(int i=0;i<sz;i++)
1112 PyObject *o=PyTuple_GetItem(pyLi,i);
1113 if(!fillIntVector(o,arr[i]))
1114 throw INTERP_KERNEL::Exception(msg);
1118 throw INTERP_KERNEL::Exception(msg);
1121 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1123 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1124 if(PyList_Check(pyLi))
1126 Py_ssize_t sz=PyList_Size(pyLi);
1128 for(int i=0;i<sz;i++)
1130 PyObject *o=PyList_GetItem(pyLi,i);
1131 if(PyTuple_Check(o))
1133 int sz2=PyTuple_Size(o);
1135 throw INTERP_KERNEL::Exception(msg);
1136 std::pair<std::string, std::vector<std::string> > item;
1137 PyObject *o_0=PyTuple_GetItem(o,0);
1138 if(!PyString_Check(o_0))
1139 throw INTERP_KERNEL::Exception(msg);
1140 item.first=PyString_AsString(o_0);
1141 PyObject *o_1=PyTuple_GetItem(o,1);
1142 if(!fillStringVector(o_1,item.second))
1143 throw INTERP_KERNEL::Exception(msg);
1147 throw INTERP_KERNEL::Exception(msg);
1150 else if(PyTuple_Check(pyLi))
1152 Py_ssize_t sz=PyTuple_Size(pyLi);
1154 for(int i=0;i<sz;i++)
1156 PyObject *o=PyTuple_GetItem(pyLi,i);
1157 if(PyTuple_Check(o))
1159 int sz2=PyTuple_Size(o);
1161 throw INTERP_KERNEL::Exception(msg);
1162 std::pair<std::string, std::vector<std::string> > item;
1163 PyObject *o_0=PyTuple_GetItem(o,0);
1164 if(!PyString_Check(o_0))
1165 throw INTERP_KERNEL::Exception(msg);
1166 item.first=PyString_AsString(o_0);
1167 PyObject *o_1=PyTuple_GetItem(o,1);
1168 if(!fillStringVector(o_1,item.second))
1169 throw INTERP_KERNEL::Exception(msg);
1173 throw INTERP_KERNEL::Exception(msg);
1177 throw INTERP_KERNEL::Exception(msg);
1180 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1182 PyObject *ret=PyList_New(size);
1183 for(int i=0;i<size;i++)
1184 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1188 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1191 PyObject *ret=PyList_New(size);
1192 for(int i=0;i<size;i++)
1193 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1197 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1199 PyObject *ret=PyList_New(nbOfTuples);
1200 for(int i=0;i<nbOfTuples;i++)
1202 PyObject *t=PyTuple_New(nbOfComp);
1203 for(int j=0;j<nbOfComp;j++)
1204 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1205 PyList_SetItem(ret,i,t);
1210 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1212 PyObject *ret=PyList_New(nbOfTuples);
1213 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1214 for(int i=0;i<nbOfTuples;i++)
1216 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1217 PyList_SetItem(ret,i,PyString_FromString(tmp));
1222 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1224 if(PyList_Check(pyLi))
1226 *size=PyList_Size(pyLi);
1227 double *tmp=(double *)malloc((*size)*sizeof(double));
1228 for(int i=0;i<*size;i++)
1230 PyObject *o=PyList_GetItem(pyLi,i);
1231 if(PyFloat_Check(o))
1233 double val=PyFloat_AS_DOUBLE(o);
1236 else if(PyInt_Check(o))
1238 long val0=PyInt_AS_LONG(o);
1245 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1250 else if(PyTuple_Check(pyLi))
1252 *size=PyTuple_Size(pyLi);
1253 double *tmp=(double *)malloc((*size)*sizeof(double));
1254 for(int i=0;i<*size;i++)
1256 PyObject *o=PyTuple_GetItem(pyLi,i);
1257 if(PyFloat_Check(o))
1259 double val=PyFloat_AS_DOUBLE(o);
1262 else if(PyInt_Check(o))
1264 long val0=PyInt_AS_LONG(o);
1271 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1277 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1280 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1282 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1283 if(PyFloat_Check(pyLi))
1289 throw INTERP_KERNEL::Exception(MSG);
1290 double val=PyFloat_AS_DOUBLE(pyLi);
1293 else if(PyInt_Check(pyLi))
1295 long val0=PyInt_AS_LONG(pyLi);
1301 throw INTERP_KERNEL::Exception(MSG);
1304 else if(PyList_Check(pyLi))
1306 int size=PyList_Size(pyLi);
1308 for(int i=0;i<size;i++)
1310 PyObject *o=PyList_GetItem(pyLi,i);
1312 fillArrayWithPyListDbl3(o,tmp1,ret);
1320 throw INTERP_KERNEL::Exception(MSG);
1323 else if(PyTuple_Check(pyLi))
1325 int size=PyTuple_Size(pyLi);
1327 for(int i=0;i<size;i++)
1329 PyObject *o=PyTuple_GetItem(pyLi,i);
1331 fillArrayWithPyListDbl3(o,tmp1,ret);
1339 throw INTERP_KERNEL::Exception(MSG);
1343 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1346 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1348 std::vector<double> ret;
1349 int size1=-1,size2=-1;
1350 if(PyList_Check(pyLi))
1352 size1=PyList_Size(pyLi);
1353 for(int i=0;i<size1;i++)
1355 PyObject *o=PyList_GetItem(pyLi,i);
1356 fillArrayWithPyListDbl3(o,size2,ret);
1361 else if(PyTuple_Check(pyLi))
1363 size1=PyTuple_Size(pyLi);
1364 for(int i=0;i<size1;i++)
1366 PyObject *o=PyTuple_GetItem(pyLi,i);
1367 fillArrayWithPyListDbl3(o,size2,ret);
1373 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1375 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1379 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1381 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1384 if(PyList_Check(pyLi))
1386 int size=PyList_Size(pyLi);
1388 for(int i=0;i<size;i++)
1390 PyObject *obj=PyList_GetItem(pyLi,i);
1391 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1392 if(!SWIG_IsOK(status))
1394 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1395 throw INTERP_KERNEL::Exception(oss.str().c_str());
1397 T arg=reinterpret_cast< T >(argp);
1401 else if(PyTuple_Check(pyLi))
1403 int size=PyTuple_Size(pyLi);
1405 for(int i=0;i<size;i++)
1407 PyObject *obj=PyTuple_GetItem(pyLi,i);
1408 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1409 if(!SWIG_IsOK(status))
1411 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1412 throw INTERP_KERNEL::Exception(oss.str().c_str());
1414 T arg=reinterpret_cast< T >(argp);
1418 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1421 T arg=reinterpret_cast< T >(argp);
1425 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1429 * if python int -> cpp int sw=1
1430 * if python list[int] -> cpp vector<int> sw=2
1431 * if python tuple[int] -> cpp vector<int> sw=2
1432 * if python DataArrayInt -> cpp DataArrayInt sw=3
1433 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1435 * switch between (int,vector<int>,DataArrayInt)
1437 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1440 if(PyInt_Check(value))
1442 iTyypp=(int)PyInt_AS_LONG(value);
1446 if(PyTuple_Check(value))
1448 int size=PyTuple_Size(value);
1449 stdvecTyypp.resize(size);
1450 for(int i=0;i<size;i++)
1452 PyObject *o=PyTuple_GetItem(value,i);
1454 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1457 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1458 throw INTERP_KERNEL::Exception(oss.str().c_str());
1464 if(PyList_Check(value))
1466 int size=PyList_Size(value);
1467 stdvecTyypp.resize(size);
1468 for(int i=0;i<size;i++)
1470 PyObject *o=PyList_GetItem(value,i);
1472 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1475 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1476 throw INTERP_KERNEL::Exception(oss.str().c_str());
1483 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1484 if(SWIG_IsOK(status))
1486 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1490 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1491 if(SWIG_IsOK(status))
1493 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1497 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1501 * if python double -> cpp double sw=1
1502 * if python int -> cpp double sw=1
1503 * if python list[double] -> cpp vector<double> sw=2
1504 * if python list[int] -> cpp vector<double> sw=2
1505 * if python tuple[double] -> cpp vector<double> sw=2
1506 * if python tuple[int] -> cpp vector<double> sw=2
1507 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1509 * switch between (int,vector<int>,DataArrayInt)
1511 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1514 if(PyFloat_Check(value))
1516 iTyypp=PyFloat_AS_DOUBLE(value);
1520 if(PyInt_Check(value))
1522 iTyypp=(double)PyInt_AS_LONG(value);
1526 if(PyTuple_Check(value))
1528 int size=PyTuple_Size(value);
1529 stdvecTyypp.resize(size);
1530 for(int i=0;i<size;i++)
1532 PyObject *o=PyTuple_GetItem(value,i);
1533 if(PyFloat_Check(o))
1534 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1535 else if(PyInt_Check(o))
1536 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1539 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1540 throw INTERP_KERNEL::Exception(oss.str().c_str());
1546 if(PyList_Check(value))
1548 int size=PyList_Size(value);
1549 stdvecTyypp.resize(size);
1550 for(int i=0;i<size;i++)
1552 PyObject *o=PyList_GetItem(value,i);
1553 if(PyFloat_Check(o))
1554 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1555 else if(PyInt_Check(o))
1556 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1559 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1560 throw INTERP_KERNEL::Exception(oss.str().c_str());
1567 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1568 if(!SWIG_IsOK(status))
1569 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1570 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1575 * if python double -> cpp double sw=1
1576 * if python int -> cpp double sw=1
1577 * if python list[double] -> cpp vector<double> sw=2
1578 * if python list[int] -> cpp vector<double> sw=2
1579 * if python tuple[double] -> cpp vector<double> sw=2
1580 * if python tuple[int] -> cpp vector<double> sw=2
1581 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1583 * switch between (int,vector<int>,DataArrayInt)
1585 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1588 if(PyFloat_Check(value))
1590 iTyypp=PyFloat_AS_DOUBLE(value);
1594 if(PyInt_Check(value))
1596 iTyypp=(double)PyInt_AS_LONG(value);
1600 if(PyTuple_Check(value))
1602 int size=PyTuple_Size(value);
1603 stdvecTyypp.resize(size);
1604 for(int i=0;i<size;i++)
1606 PyObject *o=PyTuple_GetItem(value,i);
1607 if(PyFloat_Check(o))
1608 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1609 else if(PyInt_Check(o))
1610 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1613 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1614 throw INTERP_KERNEL::Exception(oss.str().c_str());
1620 if(PyList_Check(value))
1622 int size=PyList_Size(value);
1623 stdvecTyypp.resize(size);
1624 for(int i=0;i<size;i++)
1626 PyObject *o=PyList_GetItem(value,i);
1627 if(PyFloat_Check(o))
1628 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1629 else if(PyInt_Check(o))
1630 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1633 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1634 throw INTERP_KERNEL::Exception(oss.str().c_str());
1641 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1642 if(!SWIG_IsOK(status))
1643 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1644 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1649 * if python int -> cpp int sw=1
1650 * if python list[int] -> cpp vector<int> sw=2
1651 * if python tuple[int] -> cpp vector<int> sw=2
1652 * if python slicp -> cpp pair sw=3 (begin,end,step)
1653 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1655 * switch between (int,vector<int>,DataArrayInt)
1657 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)
1659 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1661 if(PyInt_Check(value))
1663 iTyypp=(int)PyInt_AS_LONG(value);
1667 if(PyTuple_Check(value))
1669 int size=PyTuple_Size(value);
1670 stdvecTyypp.resize(size);
1671 for(int i=0;i<size;i++)
1673 PyObject *o=PyTuple_GetItem(value,i);
1675 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1678 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1679 throw INTERP_KERNEL::Exception(oss.str().c_str());
1685 if(PyList_Check(value))
1687 int size=PyList_Size(value);
1688 stdvecTyypp.resize(size);
1689 for(int i=0;i<size;i++)
1691 PyObject *o=PyList_GetItem(value,i);
1693 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1696 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1697 throw INTERP_KERNEL::Exception(oss.str().c_str());
1703 if(PySlice_Check(value))
1705 Py_ssize_t strt=2,stp=2,step=2;
1706 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1707 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1710 p.second.second=step;
1715 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1716 if(SWIG_IsOK(status))
1718 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1721 std::ostringstream oss; oss << msg << " Instance in null !";
1722 throw INTERP_KERNEL::Exception(oss.str().c_str());
1727 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1728 if(SWIG_IsOK(status))
1730 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1733 std::ostringstream oss; oss << msg << " Instance in null !";
1734 throw INTERP_KERNEL::Exception(oss.str().c_str());
1736 stdvecTyypp.resize(tmp->getNumberOfCompo());
1737 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1741 throw INTERP_KERNEL::Exception(msg);
1745 * Idem than convertObjToPossibleCpp2
1747 static void convertObjToPossibleCpp2WithNegIntInterp(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)
1749 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1752 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1757 * if python int -> cpp int sw=1
1758 * if python tuple[int] -> cpp vector<int> sw=2
1759 * if python list[int] -> cpp vector<int> sw=2
1760 * if python slice -> cpp pair sw=3
1761 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1763 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)
1766 if(PyInt_Check(value))
1768 iTyypp=(int)PyInt_AS_LONG(value);
1772 if(PyTuple_Check(value))
1774 int size=PyTuple_Size(value);
1775 stdvecTyypp.resize(size);
1776 for(int i=0;i<size;i++)
1778 PyObject *o=PyTuple_GetItem(value,i);
1780 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1783 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1784 throw INTERP_KERNEL::Exception(oss.str().c_str());
1790 if(PyList_Check(value))
1792 int size=PyList_Size(value);
1793 stdvecTyypp.resize(size);
1794 for(int i=0;i<size;i++)
1796 PyObject *o=PyList_GetItem(value,i);
1798 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1801 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1802 throw INTERP_KERNEL::Exception(oss.str().c_str());
1808 if(PySlice_Check(value))
1810 Py_ssize_t strt=2,stp=2,step=2;
1811 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1812 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1815 p.second.second=step;
1820 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1821 if(!SWIG_IsOK(status))
1822 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1823 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1828 * if python string with size one -> cpp char sw=1
1829 * if python string with size different from one -> cpp string sw=2
1830 * if python tuple[string] or list[string] -> vector<string> sw=3
1831 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1832 * switch between (int,string,vector<string>,DataArrayChar)
1834 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1836 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1838 if(PyString_Check(value))
1840 const char *pt=PyString_AsString(value);
1841 Py_ssize_t sz=PyString_Size(value);
1855 if(PyTuple_Check(value))
1857 int size=PyTuple_Size(value);
1858 vsType.resize(size);
1859 for(int i=0;i<size;i++)
1861 PyObject *o=PyTuple_GetItem(value,i);
1862 if(PyString_Check(o))
1863 vsType[i]=PyString_AsString(o);
1866 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1867 throw INTERP_KERNEL::Exception(oss.str().c_str());
1873 if(PyList_Check(value))
1875 int size=PyList_Size(value);
1876 vsType.resize(size);
1877 for(int i=0;i<size;i++)
1879 PyObject *o=PyList_GetItem(value,i);
1880 if(PyString_Check(o))
1881 vsType[i]=PyString_AsString(o);
1884 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1885 throw INTERP_KERNEL::Exception(oss.str().c_str());
1892 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1893 if(SWIG_IsOK(status))
1895 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1898 std::ostringstream oss; oss << msg << " Instance in null !";
1899 throw INTERP_KERNEL::Exception(oss.str().c_str());
1904 throw INTERP_KERNEL::Exception(msg);
1908 * if value int -> cpp it sw=1
1909 * if value list[int] -> vt sw=2
1910 * if value tuple[int] -> vt sw=2
1911 * if value slice -> pt sw=3
1912 * if value DataArrayInt -> dt sw=4
1913 * if value tuple [int,int] -> cpp it,ip sw=5
1914 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1915 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1916 * if value tuple [slice,int] -> cpp pt,ip sw=7
1917 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1918 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1919 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1920 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1921 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1922 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1923 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1924 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1925 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1926 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1927 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1928 * if value tuple [int,slice] -> cpp it,pc sw=13
1929 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1930 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1931 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1932 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1934 * switch between (int,vector<int>,DataArrayInt)
1936 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1937 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1938 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1940 if(!PyTuple_Check(value))
1942 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1947 int sz=PyTuple_Size(value);
1949 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1950 PyObject *ob0=PyTuple_GetItem(value,0);
1952 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1953 PyObject *ob1=PyTuple_GetItem(value,1);
1954 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1960 * if value int -> cpp val sw=1
1961 * if value double -> cpp val sw=1
1962 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1963 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1964 * if value list[int,double] -> cpp std::vector<double> sw=4
1965 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1967 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1970 if(PyFloat_Check(value))
1972 val=PyFloat_AS_DOUBLE(value);
1976 if(PyInt_Check(value))
1978 val=(double)PyInt_AS_LONG(value);
1982 if(PyTuple_Check(value))
1984 int size=PyTuple_Size(value);
1986 for(int i=0;i<size;i++)
1988 PyObject *o=PyTuple_GetItem(value,i);
1989 if(PyFloat_Check(o))
1990 f[i]=PyFloat_AS_DOUBLE(o);
1991 else if(PyInt_Check(o))
1992 f[i]=(double)PyInt_AS_LONG(o);
1995 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1996 throw INTERP_KERNEL::Exception(oss.str().c_str());
2002 if(PyList_Check(value))
2004 int size=PyList_Size(value);
2006 for(int i=0;i<size;i++)
2008 PyObject *o=PyList_GetItem(value,i);
2009 if(PyFloat_Check(o))
2010 f[i]=PyFloat_AS_DOUBLE(o);
2011 else if(PyInt_Check(o))
2012 f[i]=(double)PyInt_AS_LONG(o);
2015 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2016 throw INTERP_KERNEL::Exception(oss.str().c_str());
2023 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2024 if(SWIG_IsOK(status))
2026 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2030 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2031 if(SWIG_IsOK(status))
2033 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2037 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2041 * if value int -> cpp val sw=1
2042 * if value double -> cpp val sw=1
2043 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2044 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2045 * if value list[int,double] -> cpp std::vector<double> sw=4
2046 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2048 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2049 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
2052 if(PyFloat_Check(value))
2054 val=PyFloat_AS_DOUBLE(value);
2056 if(nbTuplesExpected*nbCompExpected!=1)
2058 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2059 throw INTERP_KERNEL::Exception(oss.str().c_str());
2063 if(PyInt_Check(value))
2065 val=(double)PyInt_AS_LONG(value);
2067 if(nbTuplesExpected*nbCompExpected!=1)
2069 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2070 throw INTERP_KERNEL::Exception(oss.str().c_str());
2074 if(PyTuple_Check(value) || PyList_Check(value))
2078 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2079 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2084 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2087 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2088 if(SWIG_IsOK(status))
2090 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2094 if(d->getNumberOfTuples()==nbTuplesExpected)
2096 if(d->getNumberOfComponents()==nbCompExpected)
2098 return d->getConstPointer();
2102 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2103 throw INTERP_KERNEL::Exception(oss.str().c_str());
2108 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2109 throw INTERP_KERNEL::Exception(oss.str().c_str());
2116 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2117 throw INTERP_KERNEL::Exception(oss.str().c_str());
2123 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2124 if(SWIG_IsOK(status))
2126 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2128 if(e->getNumberOfCompo()==nbCompExpected)
2130 if(nbTuplesExpected==1)
2131 return e->getConstPointer();
2134 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2135 throw INTERP_KERNEL::Exception(oss.str().c_str());
2140 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2141 throw INTERP_KERNEL::Exception(oss.str().c_str());
2144 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2148 * if value int -> cpp val sw=1
2149 * if value double -> cpp val sw=1
2150 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2151 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2152 * if value list[int,double] -> cpp std::vector<double> sw=4
2153 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2155 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2156 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2159 if(PyFloat_Check(value))
2161 val=PyFloat_AS_DOUBLE(value);
2163 if(nbCompExpected!=1)
2165 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2166 throw INTERP_KERNEL::Exception(oss.str().c_str());
2171 if(PyInt_Check(value))
2173 val=(double)PyInt_AS_LONG(value);
2175 if(nbCompExpected!=1)
2177 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2178 throw INTERP_KERNEL::Exception(oss.str().c_str());
2183 if(PyTuple_Check(value))
2185 int size=PyTuple_Size(value);
2187 for(int i=0;i<size;i++)
2189 PyObject *o=PyTuple_GetItem(value,i);
2190 if(PyFloat_Check(o))
2191 f[i]=PyFloat_AS_DOUBLE(o);
2192 else if(PyInt_Check(o))
2193 f[i]=(double)PyInt_AS_LONG(o);
2196 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2197 throw INTERP_KERNEL::Exception(oss.str().c_str());
2201 if(size%nbCompExpected!=0)
2203 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2204 throw INTERP_KERNEL::Exception(oss.str().c_str());
2206 nbTuples=size/nbCompExpected;
2209 if(PyList_Check(value))
2211 int size=PyList_Size(value);
2213 for(int i=0;i<size;i++)
2215 PyObject *o=PyList_GetItem(value,i);
2216 if(PyFloat_Check(o))
2217 f[i]=PyFloat_AS_DOUBLE(o);
2218 else if(PyInt_Check(o))
2219 f[i]=(double)PyInt_AS_LONG(o);
2222 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2223 throw INTERP_KERNEL::Exception(oss.str().c_str());
2227 if(size%nbCompExpected!=0)
2229 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2230 throw INTERP_KERNEL::Exception(oss.str().c_str());
2232 nbTuples=size/nbCompExpected;
2236 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2237 if(SWIG_IsOK(status))
2239 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2243 if(d->getNumberOfComponents()==nbCompExpected)
2245 nbTuples=d->getNumberOfTuples();
2246 return d->getConstPointer();
2250 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2251 throw INTERP_KERNEL::Exception(oss.str().c_str());
2258 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2259 throw INTERP_KERNEL::Exception(oss.str().c_str());
2262 { nbTuples=0; return 0; }
2265 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2266 if(SWIG_IsOK(status))
2268 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2272 if(e->getNumberOfCompo()==nbCompExpected)
2275 return e->getConstPointer();
2279 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2280 throw INTERP_KERNEL::Exception(oss.str().c_str());
2287 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2288 throw INTERP_KERNEL::Exception(oss.str().c_str());
2291 { nbTuples=0; return 0; }
2294 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2298 * if value int -> cpp val sw=1
2299 * if value double -> cpp val sw=1
2300 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2301 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2302 * if value list[int,double] -> cpp std::vector<double> sw=4
2303 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2305 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2306 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2308 ParaMEDMEM::DataArrayDouble *d=0;
2309 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2311 if(PyFloat_Check(value))
2313 val=PyFloat_AS_DOUBLE(value);
2318 if(PyInt_Check(value))
2320 val=(double)PyInt_AS_LONG(value);
2325 if(PyTuple_Check(value))
2327 int size=PyTuple_Size(value);
2329 for(int i=0;i<size;i++)
2331 PyObject *o=PyTuple_GetItem(value,i);
2332 if(PyFloat_Check(o))
2333 f[i]=PyFloat_AS_DOUBLE(o);
2334 else if(PyInt_Check(o))
2335 f[i]=(double)PyInt_AS_LONG(o);
2338 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2339 throw INTERP_KERNEL::Exception(oss.str().c_str());
2346 if(PyList_Check(value))
2348 int size=PyList_Size(value);
2350 for(int i=0;i<size;i++)
2352 PyObject *o=PyList_GetItem(value,i);
2353 if(PyFloat_Check(o))
2354 f[i]=PyFloat_AS_DOUBLE(o);
2355 else if(PyInt_Check(o))
2356 f[i]=(double)PyInt_AS_LONG(o);
2359 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2360 throw INTERP_KERNEL::Exception(oss.str().c_str());
2368 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2369 if(SWIG_IsOK(status))
2371 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2375 if(d->getNumberOfComponents()==1)
2377 nbTuples=d->getNumberOfTuples();
2378 return d->getConstPointer();
2382 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2383 throw INTERP_KERNEL::Exception(oss.str().c_str());
2390 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2391 throw INTERP_KERNEL::Exception(oss.str().c_str());
2394 { nbTuples=0; return 0; }
2397 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2398 if(SWIG_IsOK(status))
2400 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2404 nbTuples=e->getNumberOfCompo();
2405 return e->getConstPointer();
2411 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2412 throw INTERP_KERNEL::Exception(oss.str().c_str());
2415 { nbTuples=0; return 0; }
2418 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2422 * if python int -> cpp int sw=1
2423 * if python list[int] -> cpp vector<int> sw=2
2424 * if python tuple[int] -> cpp vector<int> sw=2
2425 * if python DataArrayInt -> cpp DataArrayInt sw=3
2426 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2428 * switch between (int,vector<int>,DataArrayInt)
2430 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2433 if(PyInt_Check(value))
2435 iTyypp=(int)PyInt_AS_LONG(value);
2439 if(PyTuple_Check(value))
2441 int size=PyTuple_Size(value);
2442 stdvecTyypp.resize(size);
2443 for(int i=0;i<size;i++)
2445 PyObject *o=PyTuple_GetItem(value,i);
2447 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2450 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2451 throw INTERP_KERNEL::Exception(oss.str().c_str());
2455 return &stdvecTyypp[0];
2457 if(PyList_Check(value))
2459 int size=PyList_Size(value);
2460 stdvecTyypp.resize(size);
2461 for(int i=0;i<size;i++)
2463 PyObject *o=PyList_GetItem(value,i);
2465 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2468 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2469 throw INTERP_KERNEL::Exception(oss.str().c_str());
2473 return &stdvecTyypp[0];
2476 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2477 if(SWIG_IsOK(status))
2479 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2482 sw=3; sz=daIntTyypp->getNbOfElems();
2483 return daIntTyypp->begin();
2491 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2492 if(SWIG_IsOK(status))
2494 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2495 sw=4; sz=daIntTuple->getNumberOfCompo();
2496 return daIntTuple->getConstPointer();
2498 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2501 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2504 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2505 if(!SWIG_IsOK(status))
2507 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2508 if(!SWIG_IsOK(status))
2510 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2511 if(!SWIG_IsOK(status))
2513 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2514 if(!SWIG_IsOK(status))
2516 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2517 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2518 throw INTERP_KERNEL::Exception(oss.str().c_str());
2523 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);