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>
72 #if NPY_API_VERSION <= 0x00000006
73 # define MED_NUMPY_OWNDATA NPY_OWNDATA
75 # define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
78 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
79 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
80 // if no more alive the "standart" DataArray deallocator is called.
81 void numarrdeal(void *pt, void *wron)
83 void **wronc=(void **)wron;
84 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
85 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
89 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
90 objC->flags|=MED_NUMPY_OWNDATA;
91 Py_XDECREF(weakRefOnOwner);
96 typedef void (*MyDeallocator)(void *,void *);
97 MyDeallocator deall=(MyDeallocator)wronc[1];
99 Py_XDECREF(weakRefOnOwner);
104 template<class MCData>
105 struct PyCallBackDataArraySt {
110 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
111 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
115 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
117 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
119 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
120 return (PyObject *)self;
123 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
125 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
126 return (PyObject *)self;
129 static void callbackmcdataarray_dealloc(PyObject *self)
131 Py_TYPE(self)->tp_free(self);
134 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
135 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
136 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
140 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
147 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
148 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
149 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
153 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
161 PyTypeObject PyCallBackDataArrayInt_RefType = {
162 PyVarObject_HEAD_INIT(&PyType_Type, 0)
163 "callbackmcdataarrayint",
164 sizeof(PyCallBackDataArrayInt),
166 callbackmcdataarray_dealloc, /*tp_dealloc*/
173 0, /*tp_as_sequence*/
176 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
181 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
185 0, /*tp_richcompare*/
186 0, /*tp_weaklistoffset*/
197 callbackmcdataarray___init__, /*tp_init*/
198 PyType_GenericAlloc, /*tp_alloc*/
199 callbackmcdataarrayint___new__, /*tp_new*/
200 PyObject_GC_Del, /*tp_free*/
203 PyTypeObject PyCallBackDataArrayDouble_RefType = {
204 PyVarObject_HEAD_INIT(&PyType_Type, 0)
205 "callbackmcdataarraydouble",
206 sizeof(PyCallBackDataArrayDouble),
208 callbackmcdataarray_dealloc, /*tp_dealloc*/
215 0, /*tp_as_sequence*/
218 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
223 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
227 0, /*tp_richcompare*/
228 0, /*tp_weaklistoffset*/
239 callbackmcdataarray___init__, /*tp_init*/
240 PyType_GenericAlloc, /*tp_alloc*/
241 callbackmcdataarraydouble___new__, /*tp_new*/
242 PyObject_GC_Del, /*tp_free*/
245 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
246 // in input when an another DataArray is already client of this.
247 template<class MCData>
248 void numarrdeal2(void *pt, void *obj)
250 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
251 void **obj1=(void **)obj;
252 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
253 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
255 Py_XDECREF(weakRefOnOwner);
260 template<class MCData, class T>
261 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
263 int ndim=PyArray_NDIM(elt0);
264 if(ndim!=1 && ndim!=2)
265 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
266 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
268 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
269 throw INTERP_KERNEL::Exception(oss.str().c_str());
271 npy_intp sz0=PyArray_DIM(elt0,0);
272 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
274 int itemSize=PyArray_ITEMSIZE(elt0);
275 if(itemSize!=sizeof(T))
277 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
278 throw INTERP_KERNEL::Exception(oss.str().c_str());
280 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
281 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
283 if(itemSize!=PyArray_STRIDE(elt0,1))
284 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 !");
285 const char *data=PyArray_BYTES(elt0);
286 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
287 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
289 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
290 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & MED_NUMPY_OWNDATA)?elt0C:NULL;
291 int mask=MED_NUMPY_OWNDATA; mask=~mask;
293 PyObject *deepestObj=elt0;
294 PyObject *base=elt0C->base;
295 if(base) deepestObj=base;
296 bool isSpetialCase(false);
299 if(PyArray_Check(base))
301 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
302 eltOwning=(PyArray_FLAGS(baseC) & MED_NUMPY_OWNDATA)?baseC:eltOwning;
305 if(base) deepestObj=base;
314 {// 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.
315 std::size_t nbOfElems(sz0*sz1);
316 T *dataCpy=(T*)malloc(sizeof(T)*nbOfElems);
317 std::copy(reinterpret_cast<const T*>(data),reinterpret_cast<const T*>(data)+nbOfElems,dataCpy);
318 ret->useArray(dataCpy,true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
321 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
324 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
326 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
327 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
328 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
329 mma.setParameterForDeallocator(objs);
330 mma.setSpecificDeallocator(numarrdeal2<MCData>);
331 //"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 !");
335 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
336 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
337 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(ParaMEDMEM::MemArray<T>::CDeallocator);
338 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
339 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
340 mma.setParameterForDeallocator(objs);
341 mma.setSpecificDeallocator(numarrdeal);
344 else if(PyArray_ISBEHAVED_RO(elt0))
345 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
350 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
353 PyErr_SetString(PyExc_ValueError,
354 "Cannot set the NumPy array 'base' "
355 "dependency to NULL after initialization");
359 * Allow the base to be set only once. Once the object which
360 * owns the data is set, it doesn't make sense to change it.
362 if (PyArray_BASE(arr) != NULL) {
364 PyErr_SetString(PyExc_ValueError,
365 "Cannot set the NumPy array 'base' "
366 "dependency more than once");
371 * Don't allow infinite chains of views, always set the base
372 * to the first owner of the data.
373 * That is, either the first object which isn't an array,
374 * or the first object which owns its own data.
377 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
378 PyArrayObject *obj_arr = (PyArrayObject *)obj;
382 /* If this array owns its own data, stop collapsing */
383 if (PyArray_CHKFLAGS(obj_arr, MED_NUMPY_OWNDATA )) {
387 tmp = PyArray_BASE(obj_arr);
388 /* If there's no base, stop collapsing */
392 /* Stop the collapse new base when the would not be of the same
393 * type (i.e. different subclass).
395 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
405 /* Disallow circular references */
406 if ((PyObject *)arr == obj) {
408 PyErr_SetString(PyExc_ValueError,
409 "Cannot create a circular NumPy array 'base' dependency");
418 template<class MCData, class T>
419 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
421 if(!self->isAllocated())
423 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
424 throw INTERP_KERNEL::Exception(oss.str().c_str());
426 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
429 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
430 throw INTERP_KERNEL::Exception(oss.str().c_str());
432 int nbDims=nbComp==1?1:2;
434 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
435 const T *bg=self->getConstPointer();
436 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
437 if(mem.isDeallocatorCalled())
439 if(mem.getDeallocator()!=numarrdeal)
440 {// case for the first call of toNumPyArray
441 PyObject *ref(PyWeakref_NewRef(ret,NULL));
442 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
443 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
444 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
445 mem.setParameterForDeallocator(objs);
446 mem.setSpecificDeallocator(numarrdeal);
450 {// case for the second and other call of toNumPyArray
451 void **objs=(void **)mem.getParameterForDeallocator();
452 PyObject *weakRefOnOwner=(PyObject *)objs[0];
453 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
455 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
457 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
460 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
461 Py_XDECREF(weakRefOnOwner);
462 PyObject *ref=PyWeakref_NewRef(ret,NULL);
470 template<class MCData, class T>
471 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
473 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
476 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
477 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
479 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
481 int nbRows((int)m.size());
482 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
483 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
484 indPtr->alloc(nbRows+1,1);
485 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
487 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
489 sz2+=(int)(*it0).size();
492 indices->alloc(sz2,1); data->alloc(sz2,1);
493 int *indices_ptr(indices->getPointer());
494 double *data_ptr(data->getPointer());
495 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
496 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
498 *indices_ptr=(*it1).first;
499 *data_ptr=(*it1).second;
501 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
503 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
504 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
505 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
506 PyObject *tmp1(PyString_FromString("shape"));
507 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
508 PyObject* pdict=PyDict_New();
509 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
510 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
512 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
513 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
515 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
516 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
517 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
523 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
531 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
532 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
533 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
534 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
536 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
540 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
548 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
549 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
550 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
551 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
552 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
553 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
554 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
555 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
557 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
561 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
563 PyObject *ret=PyList_New(size);
564 for(int i=0;i<size;i++)
565 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
569 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
572 PyObject *ret=PyList_New(size);
573 for(int i=0;i<size;i++)
574 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
578 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
581 PyObject *ret=PyList_New(size);
582 std::set<int>::const_iterator it=v.begin();
583 for(int i=0;i<size;i++,it++)
584 PyList_SetItem(ret,i,PyInt_FromLong(*it));
588 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
590 PyObject *ret=PyList_New(nbOfTuples);
591 for(int i=0;i<nbOfTuples;i++)
593 PyObject *t=PyTuple_New(nbOfComp);
594 for(int j=0;j<nbOfComp;j++)
595 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
596 PyList_SetItem(ret,i,t);
601 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
603 if(PyList_Check(pyLi))
605 *size=PyList_Size(pyLi);
606 int *tmp=new int[*size];
607 for(int i=0;i<*size;i++)
609 PyObject *o=PyList_GetItem(pyLi,i);
612 int val=(int)PyInt_AS_LONG(o);
618 throw INTERP_KERNEL::Exception("list must contain integers only");
623 else if(PyTuple_Check(pyLi))
625 *size=PyTuple_Size(pyLi);
626 int *tmp=new int[*size];
627 for(int i=0;i<*size;i++)
629 PyObject *o=PyTuple_GetItem(pyLi,i);
632 int val=(int)PyInt_AS_LONG(o);
638 throw INTERP_KERNEL::Exception("tuple must contain integers only");
645 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
649 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
651 PyObject *ret=PyList_New(arr.size());
652 for(std::size_t i=0;i<arr.size();i++)
654 PyObject *t=PyTuple_New(2);
655 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
656 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
657 PyList_SetItem(ret,i,t);
662 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
664 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
665 if(PyList_Check(pyLi))
667 int size=PyList_Size(pyLi);
669 for(int i=0;i<size;i++)
671 PyObject *o=PyList_GetItem(pyLi,i);
674 int sz2=PyTuple_Size(o);
676 throw INTERP_KERNEL::Exception(msg);
677 PyObject *o_0=PyTuple_GetItem(o,0);
678 if(!PyInt_Check(o_0))
679 throw INTERP_KERNEL::Exception(msg);
680 PyObject *o_1=PyTuple_GetItem(o,1);
681 if(!PyInt_Check(o_1))
682 throw INTERP_KERNEL::Exception(msg);
683 arr[i].first=(int)PyInt_AS_LONG(o_0);
684 arr[i].second=(int)PyInt_AS_LONG(o_1);
687 throw INTERP_KERNEL::Exception(msg);
690 else if(PyTuple_Check(pyLi))
692 int size=PyTuple_Size(pyLi);
694 for(int i=0;i<size;i++)
696 PyObject *o=PyTuple_GetItem(pyLi,i);
699 int sz2=PyTuple_Size(o);
701 throw INTERP_KERNEL::Exception(msg);
702 PyObject *o_0=PyTuple_GetItem(o,0);
703 if(!PyInt_Check(o_0))
704 throw INTERP_KERNEL::Exception(msg);
705 PyObject *o_1=PyTuple_GetItem(o,1);
706 if(!PyInt_Check(o_1))
707 throw INTERP_KERNEL::Exception(msg);
708 arr[i].first=(int)PyInt_AS_LONG(o_0);
709 arr[i].second=(int)PyInt_AS_LONG(o_1);
712 throw INTERP_KERNEL::Exception(msg);
716 throw INTERP_KERNEL::Exception(msg);
719 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
721 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
722 if(PyList_Check(pyLi))
724 int size=PyList_Size(pyLi);
726 for(int i=0;i<size;i++)
728 PyObject *o=PyList_GetItem(pyLi,i);
731 int sz2=PyTuple_Size(o);
733 throw INTERP_KERNEL::Exception(msg);
734 PyObject *o_0=PyTuple_GetItem(o,0);
735 if(!PyString_Check(o_0))
736 throw INTERP_KERNEL::Exception(msg);
737 PyObject *o_1=PyTuple_GetItem(o,1);
738 if(!PyInt_Check(o_1))
739 throw INTERP_KERNEL::Exception(msg);
740 arr[i].first=PyString_AsString(o_0);
741 arr[i].second=(int)PyInt_AS_LONG(o_1);
744 throw INTERP_KERNEL::Exception(msg);
747 else if(PyTuple_Check(pyLi))
749 int size=PyTuple_Size(pyLi);
751 for(int i=0;i<size;i++)
753 PyObject *o=PyTuple_GetItem(pyLi,i);
756 int sz2=PyTuple_Size(o);
758 throw INTERP_KERNEL::Exception(msg);
759 PyObject *o_0=PyTuple_GetItem(o,0);
760 if(!PyString_Check(o_0))
761 throw INTERP_KERNEL::Exception(msg);
762 PyObject *o_1=PyTuple_GetItem(o,1);
763 if(!PyInt_Check(o_1))
764 throw INTERP_KERNEL::Exception(msg);
765 arr[i].first=PyString_AsString(o_0);
766 arr[i].second=(int)PyInt_AS_LONG(o_1);
769 throw INTERP_KERNEL::Exception(msg);
773 throw INTERP_KERNEL::Exception(msg);
776 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
778 if(PyList_Check(pyLi))
780 int size=PyList_Size(pyLi);
782 for(int i=0;i<size;i++)
784 PyObject *o=PyList_GetItem(pyLi,i);
787 int val=(int)PyInt_AS_LONG(o);
791 throw INTERP_KERNEL::Exception("list must contain integers only");
794 else if(PyTuple_Check(pyLi))
796 int size=PyTuple_Size(pyLi);
798 for(int i=0;i<size;i++)
800 PyObject *o=PyTuple_GetItem(pyLi,i);
803 int val=(int)PyInt_AS_LONG(o);
807 throw INTERP_KERNEL::Exception("tuple must contain integers only");
812 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
816 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
819 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
821 if(PyList_Check(pyLi))
823 int size=PyList_Size(pyLi);
824 for(int i=0;i<size;i++)
826 PyObject *o=PyList_GetItem(pyLi,i);
829 int val=(int)PyInt_AS_LONG(o);
834 std::vector<int> arr2;
835 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
836 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
838 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
839 throw INTERP_KERNEL::Exception(oss.str().c_str());
841 arr.insert(arr.end(),arr2.begin(),arr2.end());
845 else if(PyTuple_Check(pyLi))
847 int size=PyTuple_Size(pyLi);
848 for(int i=0;i<size;i++)
850 PyObject *o=PyTuple_GetItem(pyLi,i);
853 int val=(int)PyInt_AS_LONG(o);
858 std::vector<int> arr2;
859 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
860 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
862 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
863 throw INTERP_KERNEL::Exception(oss.str().c_str());
865 arr.insert(arr.end(),arr2.begin(),arr2.end());
870 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
873 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
877 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
878 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
880 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
881 oss << " whereas nb of components expected is " << nbOfComp << " !";
882 throw INTERP_KERNEL::Exception(oss.str().c_str());
889 if((nbOfTuples!=size1 || nbOfComp!=size2))
891 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
893 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
894 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
895 throw INTERP_KERNEL::Exception(oss.str().c_str());
901 if(nbOfTuples==size1)
905 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
906 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
907 throw INTERP_KERNEL::Exception(oss.str().c_str());
913 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
915 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
916 if(PyInt_Check(pyLi))
918 long val=PyInt_AS_LONG(pyLi);
923 throw INTERP_KERNEL::Exception(MSG);
926 else if(PyList_Check(pyLi))
928 int size=PyList_Size(pyLi);
930 for(int i=0;i<size;i++)
932 PyObject *o=PyList_GetItem(pyLi,i);
934 fillArrayWithPyListInt3(o,tmp1,ret);
942 throw INTERP_KERNEL::Exception(MSG);
945 else if(PyTuple_Check(pyLi))
947 int size=PyTuple_Size(pyLi);
949 for(int i=0;i<size;i++)
951 PyObject *o=PyTuple_GetItem(pyLi,i);
953 fillArrayWithPyListInt3(o,tmp1,ret);
961 throw INTERP_KERNEL::Exception(MSG);
965 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
968 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
970 std::vector<int> ret;
971 int size1=-1,size2=-1;
972 if(PyList_Check(pyLi))
974 size1=PyList_Size(pyLi);
975 for(int i=0;i<size1;i++)
977 PyObject *o=PyList_GetItem(pyLi,i);
978 fillArrayWithPyListInt3(o,size2,ret);
983 else if(PyTuple_Check(pyLi))
985 size1=PyTuple_Size(pyLi);
986 for(int i=0;i<size1;i++)
988 PyObject *o=PyTuple_GetItem(pyLi,i);
989 fillArrayWithPyListInt3(o,size2,ret);
995 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
997 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1001 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
1003 if(PyList_Check(pyLi))
1005 Py_ssize_t sz=PyList_Size(pyLi);
1007 for(int i=0;i<sz;i++)
1009 PyObject *o=PyList_GetItem(pyLi,i);
1010 if(PyString_Check(o))
1011 vec[i]=PyString_AsString(o);
1017 else if(PyTuple_Check(pyLi))
1019 Py_ssize_t sz=PyTuple_Size(pyLi);
1021 for(int i=0;i<sz;i++)
1023 PyObject *o=PyTuple_GetItem(pyLi,i);
1024 if(PyString_Check(o))
1025 vec[i]=PyString_AsString(o);
1034 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
1036 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1037 if(PyList_Check(pyLi))
1039 Py_ssize_t sz=PyList_Size(pyLi);
1041 for(int i=0;i<sz;i++)
1043 PyObject *o=PyList_GetItem(pyLi,i);
1044 if(!fillStringVector(o,arr[i]))
1045 throw INTERP_KERNEL::Exception(msg);
1048 else if(PyTuple_Check(pyLi))
1050 Py_ssize_t sz=PyTuple_Size(pyLi);
1052 for(int i=0;i<sz;i++)
1054 PyObject *o=PyTuple_GetItem(pyLi,i);
1055 if(!fillStringVector(o,arr[i]))
1056 throw INTERP_KERNEL::Exception(msg);
1060 throw INTERP_KERNEL::Exception(msg);
1063 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
1065 if(PyList_Check(pyLi))
1067 Py_ssize_t sz=PyList_Size(pyLi);
1069 for(int i=0;i<sz;i++)
1071 PyObject *o=PyList_GetItem(pyLi,i);
1073 vec[i]=PyInt_AS_LONG(o);
1079 else if(PyTuple_Check(pyLi))
1081 Py_ssize_t sz=PyTuple_Size(pyLi);
1083 for(int i=0;i<sz;i++)
1085 PyObject *o=PyTuple_GetItem(pyLi,i);
1087 vec[i]=PyInt_AS_LONG(o);
1097 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
1099 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1100 if(PyList_Check(pyLi))
1102 Py_ssize_t sz=PyList_Size(pyLi);
1104 for(int i=0;i<sz;i++)
1106 PyObject *o=PyList_GetItem(pyLi,i);
1107 if(!fillIntVector(o,arr[i]))
1108 throw INTERP_KERNEL::Exception(msg);
1111 else if(PyTuple_Check(pyLi))
1113 Py_ssize_t sz=PyTuple_Size(pyLi);
1115 for(int i=0;i<sz;i++)
1117 PyObject *o=PyTuple_GetItem(pyLi,i);
1118 if(!fillIntVector(o,arr[i]))
1119 throw INTERP_KERNEL::Exception(msg);
1123 throw INTERP_KERNEL::Exception(msg);
1126 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1128 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1129 if(PyList_Check(pyLi))
1131 Py_ssize_t sz=PyList_Size(pyLi);
1133 for(int i=0;i<sz;i++)
1135 PyObject *o=PyList_GetItem(pyLi,i);
1136 if(PyTuple_Check(o))
1138 int sz2=PyTuple_Size(o);
1140 throw INTERP_KERNEL::Exception(msg);
1141 std::pair<std::string, std::vector<std::string> > item;
1142 PyObject *o_0=PyTuple_GetItem(o,0);
1143 if(!PyString_Check(o_0))
1144 throw INTERP_KERNEL::Exception(msg);
1145 item.first=PyString_AsString(o_0);
1146 PyObject *o_1=PyTuple_GetItem(o,1);
1147 if(!fillStringVector(o_1,item.second))
1148 throw INTERP_KERNEL::Exception(msg);
1152 throw INTERP_KERNEL::Exception(msg);
1155 else if(PyTuple_Check(pyLi))
1157 Py_ssize_t sz=PyTuple_Size(pyLi);
1159 for(int i=0;i<sz;i++)
1161 PyObject *o=PyTuple_GetItem(pyLi,i);
1162 if(PyTuple_Check(o))
1164 int sz2=PyTuple_Size(o);
1166 throw INTERP_KERNEL::Exception(msg);
1167 std::pair<std::string, std::vector<std::string> > item;
1168 PyObject *o_0=PyTuple_GetItem(o,0);
1169 if(!PyString_Check(o_0))
1170 throw INTERP_KERNEL::Exception(msg);
1171 item.first=PyString_AsString(o_0);
1172 PyObject *o_1=PyTuple_GetItem(o,1);
1173 if(!fillStringVector(o_1,item.second))
1174 throw INTERP_KERNEL::Exception(msg);
1178 throw INTERP_KERNEL::Exception(msg);
1182 throw INTERP_KERNEL::Exception(msg);
1185 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1187 PyObject *ret=PyList_New(size);
1188 for(int i=0;i<size;i++)
1189 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1193 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1196 PyObject *ret=PyList_New(size);
1197 for(int i=0;i<size;i++)
1198 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1202 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1204 PyObject *ret=PyList_New(nbOfTuples);
1205 for(int i=0;i<nbOfTuples;i++)
1207 PyObject *t=PyTuple_New(nbOfComp);
1208 for(int j=0;j<nbOfComp;j++)
1209 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1210 PyList_SetItem(ret,i,t);
1215 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1217 PyObject *ret=PyList_New(nbOfTuples);
1218 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1219 for(int i=0;i<nbOfTuples;i++)
1221 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1222 PyList_SetItem(ret,i,PyString_FromString(tmp));
1227 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1229 if(PyList_Check(pyLi))
1231 *size=PyList_Size(pyLi);
1232 double *tmp=(double *)malloc((*size)*sizeof(double));
1233 for(int i=0;i<*size;i++)
1235 PyObject *o=PyList_GetItem(pyLi,i);
1236 if(PyFloat_Check(o))
1238 double val=PyFloat_AS_DOUBLE(o);
1241 else if(PyInt_Check(o))
1243 long val0=PyInt_AS_LONG(o);
1250 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1255 else if(PyTuple_Check(pyLi))
1257 *size=PyTuple_Size(pyLi);
1258 double *tmp=(double *)malloc((*size)*sizeof(double));
1259 for(int i=0;i<*size;i++)
1261 PyObject *o=PyTuple_GetItem(pyLi,i);
1262 if(PyFloat_Check(o))
1264 double val=PyFloat_AS_DOUBLE(o);
1267 else if(PyInt_Check(o))
1269 long val0=PyInt_AS_LONG(o);
1276 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1282 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1285 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1287 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1288 if(PyFloat_Check(pyLi))
1294 throw INTERP_KERNEL::Exception(MSG);
1295 double val=PyFloat_AS_DOUBLE(pyLi);
1298 else if(PyInt_Check(pyLi))
1300 long val0=PyInt_AS_LONG(pyLi);
1306 throw INTERP_KERNEL::Exception(MSG);
1309 else if(PyList_Check(pyLi))
1311 int size=PyList_Size(pyLi);
1313 for(int i=0;i<size;i++)
1315 PyObject *o=PyList_GetItem(pyLi,i);
1317 fillArrayWithPyListDbl3(o,tmp1,ret);
1325 throw INTERP_KERNEL::Exception(MSG);
1328 else if(PyTuple_Check(pyLi))
1330 int size=PyTuple_Size(pyLi);
1332 for(int i=0;i<size;i++)
1334 PyObject *o=PyTuple_GetItem(pyLi,i);
1336 fillArrayWithPyListDbl3(o,tmp1,ret);
1344 throw INTERP_KERNEL::Exception(MSG);
1348 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1351 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1353 std::vector<double> ret;
1354 int size1=-1,size2=-1;
1355 if(PyList_Check(pyLi))
1357 size1=PyList_Size(pyLi);
1358 for(int i=0;i<size1;i++)
1360 PyObject *o=PyList_GetItem(pyLi,i);
1361 fillArrayWithPyListDbl3(o,size2,ret);
1366 else if(PyTuple_Check(pyLi))
1368 size1=PyTuple_Size(pyLi);
1369 for(int i=0;i<size1;i++)
1371 PyObject *o=PyTuple_GetItem(pyLi,i);
1372 fillArrayWithPyListDbl3(o,size2,ret);
1378 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1380 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1384 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1386 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1389 if(PyList_Check(pyLi))
1391 int size=PyList_Size(pyLi);
1393 for(int i=0;i<size;i++)
1395 PyObject *obj=PyList_GetItem(pyLi,i);
1396 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1397 if(!SWIG_IsOK(status))
1399 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1400 throw INTERP_KERNEL::Exception(oss.str().c_str());
1402 T arg=reinterpret_cast< T >(argp);
1406 else if(PyTuple_Check(pyLi))
1408 int size=PyTuple_Size(pyLi);
1410 for(int i=0;i<size;i++)
1412 PyObject *obj=PyTuple_GetItem(pyLi,i);
1413 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1414 if(!SWIG_IsOK(status))
1416 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1417 throw INTERP_KERNEL::Exception(oss.str().c_str());
1419 T arg=reinterpret_cast< T >(argp);
1423 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1426 T arg=reinterpret_cast< T >(argp);
1430 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1434 * if python int -> cpp int sw=1
1435 * if python list[int] -> cpp vector<int> sw=2
1436 * if python tuple[int] -> cpp vector<int> sw=2
1437 * if python DataArrayInt -> cpp DataArrayInt sw=3
1438 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1440 * switch between (int,vector<int>,DataArrayInt)
1442 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1445 if(PyInt_Check(value))
1447 iTyypp=(int)PyInt_AS_LONG(value);
1451 if(PyTuple_Check(value))
1453 int size=PyTuple_Size(value);
1454 stdvecTyypp.resize(size);
1455 for(int i=0;i<size;i++)
1457 PyObject *o=PyTuple_GetItem(value,i);
1459 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1462 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1463 throw INTERP_KERNEL::Exception(oss.str().c_str());
1469 if(PyList_Check(value))
1471 int size=PyList_Size(value);
1472 stdvecTyypp.resize(size);
1473 for(int i=0;i<size;i++)
1475 PyObject *o=PyList_GetItem(value,i);
1477 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1480 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1481 throw INTERP_KERNEL::Exception(oss.str().c_str());
1488 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1489 if(SWIG_IsOK(status))
1491 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1495 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1496 if(SWIG_IsOK(status))
1498 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1502 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1506 * if python double -> cpp double sw=1
1507 * if python int -> cpp double sw=1
1508 * if python list[double] -> cpp vector<double> sw=2
1509 * if python list[int] -> cpp vector<double> sw=2
1510 * if python tuple[double] -> cpp vector<double> sw=2
1511 * if python tuple[int] -> cpp vector<double> sw=2
1512 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1514 * switch between (int,vector<int>,DataArrayInt)
1516 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1519 if(PyFloat_Check(value))
1521 iTyypp=PyFloat_AS_DOUBLE(value);
1525 if(PyInt_Check(value))
1527 iTyypp=(double)PyInt_AS_LONG(value);
1531 if(PyTuple_Check(value))
1533 int size=PyTuple_Size(value);
1534 stdvecTyypp.resize(size);
1535 for(int i=0;i<size;i++)
1537 PyObject *o=PyTuple_GetItem(value,i);
1538 if(PyFloat_Check(o))
1539 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1540 else if(PyInt_Check(o))
1541 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1544 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1545 throw INTERP_KERNEL::Exception(oss.str().c_str());
1551 if(PyList_Check(value))
1553 int size=PyList_Size(value);
1554 stdvecTyypp.resize(size);
1555 for(int i=0;i<size;i++)
1557 PyObject *o=PyList_GetItem(value,i);
1558 if(PyFloat_Check(o))
1559 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1560 else if(PyInt_Check(o))
1561 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1564 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1572 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1573 if(!SWIG_IsOK(status))
1574 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1575 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1580 * if python double -> cpp double sw=1
1581 * if python int -> cpp double sw=1
1582 * if python list[double] -> cpp vector<double> sw=2
1583 * if python list[int] -> cpp vector<double> sw=2
1584 * if python tuple[double] -> cpp vector<double> sw=2
1585 * if python tuple[int] -> cpp vector<double> sw=2
1586 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1588 * switch between (int,vector<int>,DataArrayInt)
1590 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1593 if(PyFloat_Check(value))
1595 iTyypp=PyFloat_AS_DOUBLE(value);
1599 if(PyInt_Check(value))
1601 iTyypp=(double)PyInt_AS_LONG(value);
1605 if(PyTuple_Check(value))
1607 int size=PyTuple_Size(value);
1608 stdvecTyypp.resize(size);
1609 for(int i=0;i<size;i++)
1611 PyObject *o=PyTuple_GetItem(value,i);
1612 if(PyFloat_Check(o))
1613 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1614 else if(PyInt_Check(o))
1615 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1618 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1619 throw INTERP_KERNEL::Exception(oss.str().c_str());
1625 if(PyList_Check(value))
1627 int size=PyList_Size(value);
1628 stdvecTyypp.resize(size);
1629 for(int i=0;i<size;i++)
1631 PyObject *o=PyList_GetItem(value,i);
1632 if(PyFloat_Check(o))
1633 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1634 else if(PyInt_Check(o))
1635 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1638 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1639 throw INTERP_KERNEL::Exception(oss.str().c_str());
1646 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1647 if(!SWIG_IsOK(status))
1648 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1649 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1654 * if python int -> cpp int sw=1
1655 * if python list[int] -> cpp vector<int> sw=2
1656 * if python tuple[int] -> cpp vector<int> sw=2
1657 * if python slicp -> cpp pair sw=3 (begin,end,step)
1658 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1660 * switch between (int,vector<int>,DataArrayInt)
1662 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)
1664 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1666 if(PyInt_Check(value))
1668 iTyypp=(int)PyInt_AS_LONG(value);
1672 if(PyTuple_Check(value))
1674 int size=PyTuple_Size(value);
1675 stdvecTyypp.resize(size);
1676 for(int i=0;i<size;i++)
1678 PyObject *o=PyTuple_GetItem(value,i);
1680 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1683 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1684 throw INTERP_KERNEL::Exception(oss.str().c_str());
1690 if(PyList_Check(value))
1692 int size=PyList_Size(value);
1693 stdvecTyypp.resize(size);
1694 for(int i=0;i<size;i++)
1696 PyObject *o=PyList_GetItem(value,i);
1698 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1701 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1702 throw INTERP_KERNEL::Exception(oss.str().c_str());
1708 if(PySlice_Check(value))
1710 Py_ssize_t strt=2,stp=2,step=2;
1711 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1712 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1715 p.second.second=step;
1720 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1721 if(SWIG_IsOK(status))
1723 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1726 std::ostringstream oss; oss << msg << " Instance in null !";
1727 throw INTERP_KERNEL::Exception(oss.str().c_str());
1732 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1733 if(SWIG_IsOK(status))
1735 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1738 std::ostringstream oss; oss << msg << " Instance in null !";
1739 throw INTERP_KERNEL::Exception(oss.str().c_str());
1741 stdvecTyypp.resize(tmp->getNumberOfCompo());
1742 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1746 throw INTERP_KERNEL::Exception(msg);
1750 * Idem than convertObjToPossibleCpp2
1752 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)
1754 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1757 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1762 * if python int -> cpp int sw=1
1763 * if python tuple[int] -> cpp vector<int> sw=2
1764 * if python list[int] -> cpp vector<int> sw=2
1765 * if python slice -> cpp pair sw=3
1766 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1768 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)
1771 if(PyInt_Check(value))
1773 iTyypp=(int)PyInt_AS_LONG(value);
1777 if(PyTuple_Check(value))
1779 int size=PyTuple_Size(value);
1780 stdvecTyypp.resize(size);
1781 for(int i=0;i<size;i++)
1783 PyObject *o=PyTuple_GetItem(value,i);
1785 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1788 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1789 throw INTERP_KERNEL::Exception(oss.str().c_str());
1795 if(PyList_Check(value))
1797 int size=PyList_Size(value);
1798 stdvecTyypp.resize(size);
1799 for(int i=0;i<size;i++)
1801 PyObject *o=PyList_GetItem(value,i);
1803 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1806 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1807 throw INTERP_KERNEL::Exception(oss.str().c_str());
1813 if(PySlice_Check(value))
1815 Py_ssize_t strt=2,stp=2,step=2;
1816 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1817 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1820 p.second.second=step;
1825 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1826 if(!SWIG_IsOK(status))
1827 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1828 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1833 * if python string with size one -> cpp char sw=1
1834 * if python string with size different from one -> cpp string sw=2
1835 * if python tuple[string] or list[string] -> vector<string> sw=3
1836 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1837 * switch between (int,string,vector<string>,DataArrayChar)
1839 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1841 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1843 if(PyString_Check(value))
1845 const char *pt=PyString_AsString(value);
1846 Py_ssize_t sz=PyString_Size(value);
1860 if(PyTuple_Check(value))
1862 int size=PyTuple_Size(value);
1863 vsType.resize(size);
1864 for(int i=0;i<size;i++)
1866 PyObject *o=PyTuple_GetItem(value,i);
1867 if(PyString_Check(o))
1868 vsType[i]=PyString_AsString(o);
1871 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1872 throw INTERP_KERNEL::Exception(oss.str().c_str());
1878 if(PyList_Check(value))
1880 int size=PyList_Size(value);
1881 vsType.resize(size);
1882 for(int i=0;i<size;i++)
1884 PyObject *o=PyList_GetItem(value,i);
1885 if(PyString_Check(o))
1886 vsType[i]=PyString_AsString(o);
1889 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1890 throw INTERP_KERNEL::Exception(oss.str().c_str());
1897 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1898 if(SWIG_IsOK(status))
1900 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1903 std::ostringstream oss; oss << msg << " Instance in null !";
1904 throw INTERP_KERNEL::Exception(oss.str().c_str());
1909 throw INTERP_KERNEL::Exception(msg);
1913 * if value int -> cpp it sw=1
1914 * if value list[int] -> vt sw=2
1915 * if value tuple[int] -> vt sw=2
1916 * if value slice -> pt sw=3
1917 * if value DataArrayInt -> dt sw=4
1918 * if value tuple [int,int] -> cpp it,ip sw=5
1919 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1920 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1921 * if value tuple [slice,int] -> cpp pt,ip sw=7
1922 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1923 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1924 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1925 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1926 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1927 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1928 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1929 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1930 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1931 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1932 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1933 * if value tuple [int,slice] -> cpp it,pc sw=13
1934 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1935 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1936 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1937 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1939 * switch between (int,vector<int>,DataArrayInt)
1941 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1942 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1943 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1945 if(!PyTuple_Check(value))
1947 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1952 int sz=PyTuple_Size(value);
1954 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1955 PyObject *ob0=PyTuple_GetItem(value,0);
1957 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1958 PyObject *ob1=PyTuple_GetItem(value,1);
1959 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1965 * if value int -> cpp val sw=1
1966 * if value double -> cpp val sw=1
1967 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1968 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1969 * if value list[int,double] -> cpp std::vector<double> sw=4
1970 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1972 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1975 if(PyFloat_Check(value))
1977 val=PyFloat_AS_DOUBLE(value);
1981 if(PyInt_Check(value))
1983 val=(double)PyInt_AS_LONG(value);
1987 if(PyTuple_Check(value))
1989 int size=PyTuple_Size(value);
1991 for(int i=0;i<size;i++)
1993 PyObject *o=PyTuple_GetItem(value,i);
1994 if(PyFloat_Check(o))
1995 f[i]=PyFloat_AS_DOUBLE(o);
1996 else if(PyInt_Check(o))
1997 f[i]=(double)PyInt_AS_LONG(o);
2000 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2001 throw INTERP_KERNEL::Exception(oss.str().c_str());
2007 if(PyList_Check(value))
2009 int size=PyList_Size(value);
2011 for(int i=0;i<size;i++)
2013 PyObject *o=PyList_GetItem(value,i);
2014 if(PyFloat_Check(o))
2015 f[i]=PyFloat_AS_DOUBLE(o);
2016 else if(PyInt_Check(o))
2017 f[i]=(double)PyInt_AS_LONG(o);
2020 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2021 throw INTERP_KERNEL::Exception(oss.str().c_str());
2028 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2029 if(SWIG_IsOK(status))
2031 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2035 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2036 if(SWIG_IsOK(status))
2038 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2042 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2046 * if value int -> cpp val sw=1
2047 * if value double -> cpp val sw=1
2048 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2049 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2050 * if value list[int,double] -> cpp std::vector<double> sw=4
2051 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2053 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2054 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
2057 if(PyFloat_Check(value))
2059 val=PyFloat_AS_DOUBLE(value);
2061 if(nbTuplesExpected*nbCompExpected!=1)
2063 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2064 throw INTERP_KERNEL::Exception(oss.str().c_str());
2068 if(PyInt_Check(value))
2070 val=(double)PyInt_AS_LONG(value);
2072 if(nbTuplesExpected*nbCompExpected!=1)
2074 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2075 throw INTERP_KERNEL::Exception(oss.str().c_str());
2079 if(PyTuple_Check(value) || PyList_Check(value))
2083 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2084 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2089 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2092 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2093 if(SWIG_IsOK(status))
2095 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2099 if(d->getNumberOfTuples()==nbTuplesExpected)
2101 if(d->getNumberOfComponents()==nbCompExpected)
2103 return d->getConstPointer();
2107 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2108 throw INTERP_KERNEL::Exception(oss.str().c_str());
2113 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2114 throw INTERP_KERNEL::Exception(oss.str().c_str());
2121 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2128 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2129 if(SWIG_IsOK(status))
2131 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2133 if(e->getNumberOfCompo()==nbCompExpected)
2135 if(nbTuplesExpected==1)
2136 return e->getConstPointer();
2139 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2140 throw INTERP_KERNEL::Exception(oss.str().c_str());
2145 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2146 throw INTERP_KERNEL::Exception(oss.str().c_str());
2149 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2153 * if value int -> cpp val sw=1
2154 * if value double -> cpp val sw=1
2155 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2156 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2157 * if value list[int,double] -> cpp std::vector<double> sw=4
2158 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2160 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2161 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2164 if(PyFloat_Check(value))
2166 val=PyFloat_AS_DOUBLE(value);
2168 if(nbCompExpected!=1)
2170 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2171 throw INTERP_KERNEL::Exception(oss.str().c_str());
2176 if(PyInt_Check(value))
2178 val=(double)PyInt_AS_LONG(value);
2180 if(nbCompExpected!=1)
2182 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2183 throw INTERP_KERNEL::Exception(oss.str().c_str());
2188 if(PyTuple_Check(value))
2190 int size=PyTuple_Size(value);
2192 for(int i=0;i<size;i++)
2194 PyObject *o=PyTuple_GetItem(value,i);
2195 if(PyFloat_Check(o))
2196 f[i]=PyFloat_AS_DOUBLE(o);
2197 else if(PyInt_Check(o))
2198 f[i]=(double)PyInt_AS_LONG(o);
2201 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2202 throw INTERP_KERNEL::Exception(oss.str().c_str());
2206 if(size%nbCompExpected!=0)
2208 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2209 throw INTERP_KERNEL::Exception(oss.str().c_str());
2211 nbTuples=size/nbCompExpected;
2214 if(PyList_Check(value))
2216 int size=PyList_Size(value);
2218 for(int i=0;i<size;i++)
2220 PyObject *o=PyList_GetItem(value,i);
2221 if(PyFloat_Check(o))
2222 f[i]=PyFloat_AS_DOUBLE(o);
2223 else if(PyInt_Check(o))
2224 f[i]=(double)PyInt_AS_LONG(o);
2227 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2228 throw INTERP_KERNEL::Exception(oss.str().c_str());
2232 if(size%nbCompExpected!=0)
2234 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2235 throw INTERP_KERNEL::Exception(oss.str().c_str());
2237 nbTuples=size/nbCompExpected;
2241 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2242 if(SWIG_IsOK(status))
2244 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2248 if(d->getNumberOfComponents()==nbCompExpected)
2250 nbTuples=d->getNumberOfTuples();
2251 return d->getConstPointer();
2255 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2256 throw INTERP_KERNEL::Exception(oss.str().c_str());
2263 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2264 throw INTERP_KERNEL::Exception(oss.str().c_str());
2267 { nbTuples=0; return 0; }
2270 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2271 if(SWIG_IsOK(status))
2273 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2277 if(e->getNumberOfCompo()==nbCompExpected)
2280 return e->getConstPointer();
2284 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2285 throw INTERP_KERNEL::Exception(oss.str().c_str());
2292 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2293 throw INTERP_KERNEL::Exception(oss.str().c_str());
2296 { nbTuples=0; return 0; }
2299 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2303 * if value int -> cpp val sw=1
2304 * if value double -> cpp val sw=1
2305 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2306 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2307 * if value list[int,double] -> cpp std::vector<double> sw=4
2308 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2310 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2311 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2313 ParaMEDMEM::DataArrayDouble *d=0;
2314 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2316 if(PyFloat_Check(value))
2318 val=PyFloat_AS_DOUBLE(value);
2323 if(PyInt_Check(value))
2325 val=(double)PyInt_AS_LONG(value);
2330 if(PyTuple_Check(value))
2332 int size=PyTuple_Size(value);
2334 for(int i=0;i<size;i++)
2336 PyObject *o=PyTuple_GetItem(value,i);
2337 if(PyFloat_Check(o))
2338 f[i]=PyFloat_AS_DOUBLE(o);
2339 else if(PyInt_Check(o))
2340 f[i]=(double)PyInt_AS_LONG(o);
2343 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2344 throw INTERP_KERNEL::Exception(oss.str().c_str());
2351 if(PyList_Check(value))
2353 int size=PyList_Size(value);
2355 for(int i=0;i<size;i++)
2357 PyObject *o=PyList_GetItem(value,i);
2358 if(PyFloat_Check(o))
2359 f[i]=PyFloat_AS_DOUBLE(o);
2360 else if(PyInt_Check(o))
2361 f[i]=(double)PyInt_AS_LONG(o);
2364 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2365 throw INTERP_KERNEL::Exception(oss.str().c_str());
2373 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2374 if(SWIG_IsOK(status))
2376 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2380 if(d->getNumberOfComponents()==1)
2382 nbTuples=d->getNumberOfTuples();
2383 return d->getConstPointer();
2387 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2388 throw INTERP_KERNEL::Exception(oss.str().c_str());
2395 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2396 throw INTERP_KERNEL::Exception(oss.str().c_str());
2399 { nbTuples=0; return 0; }
2402 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2403 if(SWIG_IsOK(status))
2405 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2409 nbTuples=e->getNumberOfCompo();
2410 return e->getConstPointer();
2416 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2417 throw INTERP_KERNEL::Exception(oss.str().c_str());
2420 { nbTuples=0; return 0; }
2423 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2427 * if python int -> cpp int sw=1
2428 * if python list[int] -> cpp vector<int> sw=2
2429 * if python tuple[int] -> cpp vector<int> sw=2
2430 * if python DataArrayInt -> cpp DataArrayInt sw=3
2431 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2433 * switch between (int,vector<int>,DataArrayInt)
2435 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2438 if(PyInt_Check(value))
2440 iTyypp=(int)PyInt_AS_LONG(value);
2444 if(PyTuple_Check(value))
2446 int size=PyTuple_Size(value);
2447 stdvecTyypp.resize(size);
2448 for(int i=0;i<size;i++)
2450 PyObject *o=PyTuple_GetItem(value,i);
2452 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2455 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2456 throw INTERP_KERNEL::Exception(oss.str().c_str());
2460 return &stdvecTyypp[0];
2462 if(PyList_Check(value))
2464 int size=PyList_Size(value);
2465 stdvecTyypp.resize(size);
2466 for(int i=0;i<size;i++)
2468 PyObject *o=PyList_GetItem(value,i);
2470 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2473 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2474 throw INTERP_KERNEL::Exception(oss.str().c_str());
2478 return &stdvecTyypp[0];
2481 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2482 if(SWIG_IsOK(status))
2484 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2487 sw=3; sz=daIntTyypp->getNbOfElems();
2488 return daIntTyypp->begin();
2496 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2497 if(SWIG_IsOK(status))
2499 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2500 sw=4; sz=daIntTuple->getNumberOfCompo();
2501 return daIntTuple->getConstPointer();
2503 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2506 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2509 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2510 if(!SWIG_IsOK(status))
2512 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2513 if(!SWIG_IsOK(status))
2515 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2516 if(!SWIG_IsOK(status))
2518 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2519 if(!SWIG_IsOK(status))
2521 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2522 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2523 throw INTERP_KERNEL::Exception(oss.str().c_str());
2528 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);