1 // Copyright (C) 2007-2014 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_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_OWNDATA)?elt0C:NULL;
286 int mask=NPY_OWNDATA; mask=~mask;
288 PyObject *deepestObj=elt0;
289 PyObject *base=elt0C->base;
290 if(base) deepestObj=base;
293 if(PyArray_Check(base))
295 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
296 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
299 if(base) deepestObj=base;
304 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
307 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
309 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
310 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
311 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
312 mma.setParameterForDeallocator(objs);
313 mma.setSpecificDeallocator(numarrdeal2<MCData>);
314 //"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 !");
318 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
319 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
320 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(ParaMEDMEM::MemArray<T>::CDeallocator);
321 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
322 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
323 mma.setParameterForDeallocator(objs);
324 mma.setSpecificDeallocator(numarrdeal);
327 else if(PyArray_ISBEHAVED_RO(elt0))
328 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
333 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
336 PyErr_SetString(PyExc_ValueError,
337 "Cannot set the NumPy array 'base' "
338 "dependency to NULL after initialization");
342 * Allow the base to be set only once. Once the object which
343 * owns the data is set, it doesn't make sense to change it.
345 if (PyArray_BASE(arr) != NULL) {
347 PyErr_SetString(PyExc_ValueError,
348 "Cannot set the NumPy array 'base' "
349 "dependency more than once");
354 * Don't allow infinite chains of views, always set the base
355 * to the first owner of the data.
356 * That is, either the first object which isn't an array,
357 * or the first object which owns its own data.
360 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
361 PyArrayObject *obj_arr = (PyArrayObject *)obj;
365 /* If this array owns its own data, stop collapsing */
366 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
370 tmp = PyArray_BASE(obj_arr);
371 /* If there's no base, stop collapsing */
375 /* Stop the collapse new base when the would not be of the same
376 * type (i.e. different subclass).
378 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
388 /* Disallow circular references */
389 if ((PyObject *)arr == obj) {
391 PyErr_SetString(PyExc_ValueError,
392 "Cannot create a circular NumPy array 'base' dependency");
401 template<class MCData, class T>
402 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
404 if(!self->isAllocated())
406 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
407 throw INTERP_KERNEL::Exception(oss.str().c_str());
409 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
412 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
413 throw INTERP_KERNEL::Exception(oss.str().c_str());
415 int nbDims=nbComp==1?1:2;
417 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
418 const T *bg=self->getConstPointer();
419 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
420 if(mem.isDeallocatorCalled())
422 if(mem.getDeallocator()!=numarrdeal)
423 {// case for the first call of toNumPyArray
424 PyObject *ref(PyWeakref_NewRef(ret,NULL));
425 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
426 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
427 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
428 mem.setParameterForDeallocator(objs);
429 mem.setSpecificDeallocator(numarrdeal);
433 {// case for the second and other call of toNumPyArray
434 void **objs=(void **)mem.getParameterForDeallocator();
435 PyObject *weakRefOnOwner=(PyObject *)objs[0];
436 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
438 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
440 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
443 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
444 Py_XDECREF(weakRefOnOwner);
445 PyObject *ref=PyWeakref_NewRef(ret,NULL);
453 template<class MCData, class T>
454 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
456 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
459 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
460 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
462 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
464 int nbRows((int)m.size());
465 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
466 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
467 indPtr->alloc(nbRows+1,1);
468 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
470 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
472 sz2+=(int)(*it0).size();
475 indices->alloc(sz2,1); data->alloc(sz2,1);
476 int *indices_ptr(indices->getPointer());
477 double *data_ptr(data->getPointer());
478 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
479 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
481 *indices_ptr=(*it1).first;
482 *data_ptr=(*it1).second;
484 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
486 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
487 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
488 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
489 PyObject *tmp1(PyString_FromString("shape"));
490 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
491 PyObject* pdict=PyDict_New();
492 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
493 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
495 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
496 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
498 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
499 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
500 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
506 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
514 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
515 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
516 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
517 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
519 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
523 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
531 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
532 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
533 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
534 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
535 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
536 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
537 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
538 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
540 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
544 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
546 PyObject *ret=PyList_New(size);
547 for(int i=0;i<size;i++)
548 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
552 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
555 PyObject *ret=PyList_New(size);
556 for(int i=0;i<size;i++)
557 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
561 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
564 PyObject *ret=PyList_New(size);
565 std::set<int>::const_iterator it=v.begin();
566 for(int i=0;i<size;i++,it++)
567 PyList_SetItem(ret,i,PyInt_FromLong(*it));
571 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
573 PyObject *ret=PyList_New(nbOfTuples);
574 for(int i=0;i<nbOfTuples;i++)
576 PyObject *t=PyTuple_New(nbOfComp);
577 for(int j=0;j<nbOfComp;j++)
578 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
579 PyList_SetItem(ret,i,t);
584 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
586 if(PyList_Check(pyLi))
588 *size=PyList_Size(pyLi);
589 int *tmp=new int[*size];
590 for(int i=0;i<*size;i++)
592 PyObject *o=PyList_GetItem(pyLi,i);
595 int val=(int)PyInt_AS_LONG(o);
601 throw INTERP_KERNEL::Exception("list must contain integers only");
606 else if(PyTuple_Check(pyLi))
608 *size=PyTuple_Size(pyLi);
609 int *tmp=new int[*size];
610 for(int i=0;i<*size;i++)
612 PyObject *o=PyTuple_GetItem(pyLi,i);
615 int val=(int)PyInt_AS_LONG(o);
621 throw INTERP_KERNEL::Exception("tuple must contain integers only");
628 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
632 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
634 PyObject *ret=PyList_New(arr.size());
635 for(std::size_t i=0;i<arr.size();i++)
637 PyObject *t=PyTuple_New(2);
638 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
639 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
640 PyList_SetItem(ret,i,t);
645 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
647 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
648 if(PyList_Check(pyLi))
650 int size=PyList_Size(pyLi);
652 for(int i=0;i<size;i++)
654 PyObject *o=PyList_GetItem(pyLi,i);
657 int sz2=PyTuple_Size(o);
659 throw INTERP_KERNEL::Exception(msg);
660 PyObject *o_0=PyTuple_GetItem(o,0);
661 if(!PyInt_Check(o_0))
662 throw INTERP_KERNEL::Exception(msg);
663 PyObject *o_1=PyTuple_GetItem(o,1);
664 if(!PyInt_Check(o_1))
665 throw INTERP_KERNEL::Exception(msg);
666 arr[i].first=(int)PyInt_AS_LONG(o_0);
667 arr[i].second=(int)PyInt_AS_LONG(o_1);
670 throw INTERP_KERNEL::Exception(msg);
673 else if(PyTuple_Check(pyLi))
675 int size=PyTuple_Size(pyLi);
677 for(int i=0;i<size;i++)
679 PyObject *o=PyTuple_GetItem(pyLi,i);
682 int sz2=PyTuple_Size(o);
684 throw INTERP_KERNEL::Exception(msg);
685 PyObject *o_0=PyTuple_GetItem(o,0);
686 if(!PyInt_Check(o_0))
687 throw INTERP_KERNEL::Exception(msg);
688 PyObject *o_1=PyTuple_GetItem(o,1);
689 if(!PyInt_Check(o_1))
690 throw INTERP_KERNEL::Exception(msg);
691 arr[i].first=(int)PyInt_AS_LONG(o_0);
692 arr[i].second=(int)PyInt_AS_LONG(o_1);
695 throw INTERP_KERNEL::Exception(msg);
699 throw INTERP_KERNEL::Exception(msg);
702 static void convertPyToVectorPairStringInt(PyObject *pyLi, std::vector< std::pair<std::string,int> >& arr) throw(INTERP_KERNEL::Exception)
704 const char msg[]="convertPyToVectorPairStringInt : list must contain tuples of 2 integers only or tuple must contain tuples of 1 string and 1 integer only !";
705 if(PyList_Check(pyLi))
707 int size=PyList_Size(pyLi);
709 for(int i=0;i<size;i++)
711 PyObject *o=PyList_GetItem(pyLi,i);
714 int sz2=PyTuple_Size(o);
716 throw INTERP_KERNEL::Exception(msg);
717 PyObject *o_0=PyTuple_GetItem(o,0);
718 if(!PyString_Check(o_0))
719 throw INTERP_KERNEL::Exception(msg);
720 PyObject *o_1=PyTuple_GetItem(o,1);
721 if(!PyInt_Check(o_1))
722 throw INTERP_KERNEL::Exception(msg);
723 arr[i].first=PyString_AsString(o_0);
724 arr[i].second=(int)PyInt_AS_LONG(o_1);
727 throw INTERP_KERNEL::Exception(msg);
730 else if(PyTuple_Check(pyLi))
732 int size=PyTuple_Size(pyLi);
734 for(int i=0;i<size;i++)
736 PyObject *o=PyTuple_GetItem(pyLi,i);
739 int sz2=PyTuple_Size(o);
741 throw INTERP_KERNEL::Exception(msg);
742 PyObject *o_0=PyTuple_GetItem(o,0);
743 if(!PyString_Check(o_0))
744 throw INTERP_KERNEL::Exception(msg);
745 PyObject *o_1=PyTuple_GetItem(o,1);
746 if(!PyInt_Check(o_1))
747 throw INTERP_KERNEL::Exception(msg);
748 arr[i].first=PyString_AsString(o_0);
749 arr[i].second=(int)PyInt_AS_LONG(o_1);
752 throw INTERP_KERNEL::Exception(msg);
756 throw INTERP_KERNEL::Exception(msg);
759 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
761 if(PyList_Check(pyLi))
763 int size=PyList_Size(pyLi);
765 for(int i=0;i<size;i++)
767 PyObject *o=PyList_GetItem(pyLi,i);
770 int val=(int)PyInt_AS_LONG(o);
774 throw INTERP_KERNEL::Exception("list must contain integers only");
777 else if(PyTuple_Check(pyLi))
779 int size=PyTuple_Size(pyLi);
781 for(int i=0;i<size;i++)
783 PyObject *o=PyTuple_GetItem(pyLi,i);
786 int val=(int)PyInt_AS_LONG(o);
790 throw INTERP_KERNEL::Exception("tuple must contain integers only");
795 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
799 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
802 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
804 if(PyList_Check(pyLi))
806 int size=PyList_Size(pyLi);
807 for(int i=0;i<size;i++)
809 PyObject *o=PyList_GetItem(pyLi,i);
812 int val=(int)PyInt_AS_LONG(o);
817 std::vector<int> arr2;
818 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
819 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
821 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
822 throw INTERP_KERNEL::Exception(oss.str().c_str());
824 arr.insert(arr.end(),arr2.begin(),arr2.end());
828 else if(PyTuple_Check(pyLi))
830 int size=PyTuple_Size(pyLi);
831 for(int i=0;i<size;i++)
833 PyObject *o=PyTuple_GetItem(pyLi,i);
836 int val=(int)PyInt_AS_LONG(o);
841 std::vector<int> arr2;
842 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
843 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
845 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
846 throw INTERP_KERNEL::Exception(oss.str().c_str());
848 arr.insert(arr.end(),arr2.begin(),arr2.end());
853 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
856 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
860 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
861 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
863 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
864 oss << " whereas nb of components expected is " << nbOfComp << " !";
865 throw INTERP_KERNEL::Exception(oss.str().c_str());
872 if((nbOfTuples!=size1 || nbOfComp!=size2))
874 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
876 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
877 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
878 throw INTERP_KERNEL::Exception(oss.str().c_str());
884 if(nbOfTuples==size1)
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 << " !";
890 throw INTERP_KERNEL::Exception(oss.str().c_str());
896 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
898 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
899 if(PyInt_Check(pyLi))
901 long val=PyInt_AS_LONG(pyLi);
906 throw INTERP_KERNEL::Exception(MSG);
909 else if(PyList_Check(pyLi))
911 int size=PyList_Size(pyLi);
913 for(int i=0;i<size;i++)
915 PyObject *o=PyList_GetItem(pyLi,i);
917 fillArrayWithPyListInt3(o,tmp1,ret);
925 throw INTERP_KERNEL::Exception(MSG);
928 else if(PyTuple_Check(pyLi))
930 int size=PyTuple_Size(pyLi);
932 for(int i=0;i<size;i++)
934 PyObject *o=PyTuple_GetItem(pyLi,i);
936 fillArrayWithPyListInt3(o,tmp1,ret);
944 throw INTERP_KERNEL::Exception(MSG);
948 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
951 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
953 std::vector<int> ret;
954 int size1=-1,size2=-1;
955 if(PyList_Check(pyLi))
957 size1=PyList_Size(pyLi);
958 for(int i=0;i<size1;i++)
960 PyObject *o=PyList_GetItem(pyLi,i);
961 fillArrayWithPyListInt3(o,size2,ret);
966 else if(PyTuple_Check(pyLi))
968 size1=PyTuple_Size(pyLi);
969 for(int i=0;i<size1;i++)
971 PyObject *o=PyTuple_GetItem(pyLi,i);
972 fillArrayWithPyListInt3(o,size2,ret);
978 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
980 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
984 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
986 if(PyList_Check(pyLi))
988 Py_ssize_t sz=PyList_Size(pyLi);
990 for(int i=0;i<sz;i++)
992 PyObject *o=PyList_GetItem(pyLi,i);
993 if(PyString_Check(o))
994 vec[i]=PyString_AsString(o);
1000 else if(PyTuple_Check(pyLi))
1002 Py_ssize_t sz=PyTuple_Size(pyLi);
1004 for(int i=0;i<sz;i++)
1006 PyObject *o=PyTuple_GetItem(pyLi,i);
1007 if(PyString_Check(o))
1008 vec[i]=PyString_AsString(o);
1017 static void convertPyToVectorOfVectorOfString(PyObject *pyLi, std::vector< std::vector<std::string> >& arr) throw(INTERP_KERNEL::Exception)
1019 const char msg[]="convertPyToVectorOfVectorOfString : expecting list of list of strings !";
1020 if(PyList_Check(pyLi))
1022 Py_ssize_t sz=PyList_Size(pyLi);
1024 for(int i=0;i<sz;i++)
1026 PyObject *o=PyList_GetItem(pyLi,i);
1027 if(!fillStringVector(o,arr[i]))
1028 throw INTERP_KERNEL::Exception(msg);
1031 else if(PyTuple_Check(pyLi))
1033 Py_ssize_t sz=PyTuple_Size(pyLi);
1035 for(int i=0;i<sz;i++)
1037 PyObject *o=PyTuple_GetItem(pyLi,i);
1038 if(!fillStringVector(o,arr[i]))
1039 throw INTERP_KERNEL::Exception(msg);
1043 throw INTERP_KERNEL::Exception(msg);
1046 static bool fillIntVector(PyObject *pyLi, std::vector<int>& vec) throw(INTERP_KERNEL::Exception)
1048 if(PyList_Check(pyLi))
1050 Py_ssize_t sz=PyList_Size(pyLi);
1052 for(int i=0;i<sz;i++)
1054 PyObject *o=PyList_GetItem(pyLi,i);
1056 vec[i]=PyInt_AS_LONG(o);
1062 else if(PyTuple_Check(pyLi))
1064 Py_ssize_t sz=PyTuple_Size(pyLi);
1066 for(int i=0;i<sz;i++)
1068 PyObject *o=PyTuple_GetItem(pyLi,i);
1070 vec[i]=PyInt_AS_LONG(o);
1080 static void convertPyToVectorOfVectorOfInt(PyObject *pyLi, std::vector< std::vector<int> >& arr) throw(INTERP_KERNEL::Exception)
1082 const char msg[]="convertPyToVectorOfVectorOfInt : expecting list of list of strings !";
1083 if(PyList_Check(pyLi))
1085 Py_ssize_t sz=PyList_Size(pyLi);
1087 for(int i=0;i<sz;i++)
1089 PyObject *o=PyList_GetItem(pyLi,i);
1090 if(!fillIntVector(o,arr[i]))
1091 throw INTERP_KERNEL::Exception(msg);
1094 else if(PyTuple_Check(pyLi))
1096 Py_ssize_t sz=PyTuple_Size(pyLi);
1098 for(int i=0;i<sz;i++)
1100 PyObject *o=PyTuple_GetItem(pyLi,i);
1101 if(!fillIntVector(o,arr[i]))
1102 throw INTERP_KERNEL::Exception(msg);
1106 throw INTERP_KERNEL::Exception(msg);
1109 static void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1111 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1112 if(PyList_Check(pyLi))
1114 Py_ssize_t sz=PyList_Size(pyLi);
1116 for(int i=0;i<sz;i++)
1118 PyObject *o=PyList_GetItem(pyLi,i);
1119 if(PyTuple_Check(o))
1121 int sz2=PyTuple_Size(o);
1123 throw INTERP_KERNEL::Exception(msg);
1124 std::pair<std::string, std::vector<std::string> > item;
1125 PyObject *o_0=PyTuple_GetItem(o,0);
1126 if(!PyString_Check(o_0))
1127 throw INTERP_KERNEL::Exception(msg);
1128 item.first=PyString_AsString(o_0);
1129 PyObject *o_1=PyTuple_GetItem(o,1);
1130 if(!fillStringVector(o_1,item.second))
1131 throw INTERP_KERNEL::Exception(msg);
1135 throw INTERP_KERNEL::Exception(msg);
1138 else if(PyTuple_Check(pyLi))
1140 Py_ssize_t sz=PyTuple_Size(pyLi);
1142 for(int i=0;i<sz;i++)
1144 PyObject *o=PyTuple_GetItem(pyLi,i);
1145 if(PyTuple_Check(o))
1147 int sz2=PyTuple_Size(o);
1149 throw INTERP_KERNEL::Exception(msg);
1150 std::pair<std::string, std::vector<std::string> > item;
1151 PyObject *o_0=PyTuple_GetItem(o,0);
1152 if(!PyString_Check(o_0))
1153 throw INTERP_KERNEL::Exception(msg);
1154 item.first=PyString_AsString(o_0);
1155 PyObject *o_1=PyTuple_GetItem(o,1);
1156 if(!fillStringVector(o_1,item.second))
1157 throw INTERP_KERNEL::Exception(msg);
1161 throw INTERP_KERNEL::Exception(msg);
1165 throw INTERP_KERNEL::Exception(msg);
1168 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1170 PyObject *ret=PyList_New(size);
1171 for(int i=0;i<size;i++)
1172 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1176 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1179 PyObject *ret=PyList_New(size);
1180 for(int i=0;i<size;i++)
1181 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1185 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1187 PyObject *ret=PyList_New(nbOfTuples);
1188 for(int i=0;i<nbOfTuples;i++)
1190 PyObject *t=PyTuple_New(nbOfComp);
1191 for(int j=0;j<nbOfComp;j++)
1192 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1193 PyList_SetItem(ret,i,t);
1198 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1200 PyObject *ret=PyList_New(nbOfTuples);
1201 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1202 for(int i=0;i<nbOfTuples;i++)
1204 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1205 PyList_SetItem(ret,i,PyString_FromString(tmp));
1210 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1212 if(PyList_Check(pyLi))
1214 *size=PyList_Size(pyLi);
1215 double *tmp=(double *)malloc((*size)*sizeof(double));
1216 for(int i=0;i<*size;i++)
1218 PyObject *o=PyList_GetItem(pyLi,i);
1219 if(PyFloat_Check(o))
1221 double val=PyFloat_AS_DOUBLE(o);
1224 else if(PyInt_Check(o))
1226 long val0=PyInt_AS_LONG(o);
1233 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1238 else if(PyTuple_Check(pyLi))
1240 *size=PyTuple_Size(pyLi);
1241 double *tmp=(double *)malloc((*size)*sizeof(double));
1242 for(int i=0;i<*size;i++)
1244 PyObject *o=PyTuple_GetItem(pyLi,i);
1245 if(PyFloat_Check(o))
1247 double val=PyFloat_AS_DOUBLE(o);
1250 else if(PyInt_Check(o))
1252 long val0=PyInt_AS_LONG(o);
1259 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1265 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1268 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1270 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1271 if(PyFloat_Check(pyLi))
1277 throw INTERP_KERNEL::Exception(MSG);
1278 double val=PyFloat_AS_DOUBLE(pyLi);
1281 else if(PyInt_Check(pyLi))
1283 long val0=PyInt_AS_LONG(pyLi);
1289 throw INTERP_KERNEL::Exception(MSG);
1292 else if(PyList_Check(pyLi))
1294 int size=PyList_Size(pyLi);
1296 for(int i=0;i<size;i++)
1298 PyObject *o=PyList_GetItem(pyLi,i);
1300 fillArrayWithPyListDbl3(o,tmp1,ret);
1308 throw INTERP_KERNEL::Exception(MSG);
1311 else if(PyTuple_Check(pyLi))
1313 int size=PyTuple_Size(pyLi);
1315 for(int i=0;i<size;i++)
1317 PyObject *o=PyTuple_GetItem(pyLi,i);
1319 fillArrayWithPyListDbl3(o,tmp1,ret);
1327 throw INTERP_KERNEL::Exception(MSG);
1331 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1334 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1336 std::vector<double> ret;
1337 int size1=-1,size2=-1;
1338 if(PyList_Check(pyLi))
1340 size1=PyList_Size(pyLi);
1341 for(int i=0;i<size1;i++)
1343 PyObject *o=PyList_GetItem(pyLi,i);
1344 fillArrayWithPyListDbl3(o,size2,ret);
1349 else if(PyTuple_Check(pyLi))
1351 size1=PyTuple_Size(pyLi);
1352 for(int i=0;i<size1;i++)
1354 PyObject *o=PyTuple_GetItem(pyLi,i);
1355 fillArrayWithPyListDbl3(o,size2,ret);
1361 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1363 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1367 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1369 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1372 if(PyList_Check(pyLi))
1374 int size=PyList_Size(pyLi);
1376 for(int i=0;i<size;i++)
1378 PyObject *obj=PyList_GetItem(pyLi,i);
1379 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1380 if(!SWIG_IsOK(status))
1382 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1383 throw INTERP_KERNEL::Exception(oss.str().c_str());
1385 T arg=reinterpret_cast< T >(argp);
1389 else if(PyTuple_Check(pyLi))
1391 int size=PyTuple_Size(pyLi);
1393 for(int i=0;i<size;i++)
1395 PyObject *obj=PyTuple_GetItem(pyLi,i);
1396 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1397 if(!SWIG_IsOK(status))
1399 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple 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(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1409 T arg=reinterpret_cast< T >(argp);
1413 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1417 * if python int -> cpp int sw=1
1418 * if python list[int] -> cpp vector<int> sw=2
1419 * if python tuple[int] -> cpp vector<int> sw=2
1420 * if python DataArrayInt -> cpp DataArrayInt sw=3
1421 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1423 * switch between (int,vector<int>,DataArrayInt)
1425 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1428 if(PyInt_Check(value))
1430 iTyypp=(int)PyInt_AS_LONG(value);
1434 if(PyTuple_Check(value))
1436 int size=PyTuple_Size(value);
1437 stdvecTyypp.resize(size);
1438 for(int i=0;i<size;i++)
1440 PyObject *o=PyTuple_GetItem(value,i);
1442 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1445 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1446 throw INTERP_KERNEL::Exception(oss.str().c_str());
1452 if(PyList_Check(value))
1454 int size=PyList_Size(value);
1455 stdvecTyypp.resize(size);
1456 for(int i=0;i<size;i++)
1458 PyObject *o=PyList_GetItem(value,i);
1460 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1463 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1464 throw INTERP_KERNEL::Exception(oss.str().c_str());
1471 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1472 if(SWIG_IsOK(status))
1474 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1478 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1479 if(SWIG_IsOK(status))
1481 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1485 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1489 * if python double -> cpp double sw=1
1490 * if python int -> cpp double sw=1
1491 * if python list[double] -> cpp vector<double> sw=2
1492 * if python list[int] -> cpp vector<double> sw=2
1493 * if python tuple[double] -> cpp vector<double> sw=2
1494 * if python tuple[int] -> cpp vector<double> sw=2
1495 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1497 * switch between (int,vector<int>,DataArrayInt)
1499 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1502 if(PyFloat_Check(value))
1504 iTyypp=PyFloat_AS_DOUBLE(value);
1508 if(PyInt_Check(value))
1510 iTyypp=(double)PyInt_AS_LONG(value);
1514 if(PyTuple_Check(value))
1516 int size=PyTuple_Size(value);
1517 stdvecTyypp.resize(size);
1518 for(int i=0;i<size;i++)
1520 PyObject *o=PyTuple_GetItem(value,i);
1521 if(PyFloat_Check(o))
1522 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1523 else if(PyInt_Check(o))
1524 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1527 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1528 throw INTERP_KERNEL::Exception(oss.str().c_str());
1534 if(PyList_Check(value))
1536 int size=PyList_Size(value);
1537 stdvecTyypp.resize(size);
1538 for(int i=0;i<size;i++)
1540 PyObject *o=PyList_GetItem(value,i);
1541 if(PyFloat_Check(o))
1542 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1543 else if(PyInt_Check(o))
1544 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1547 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1548 throw INTERP_KERNEL::Exception(oss.str().c_str());
1555 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1556 if(!SWIG_IsOK(status))
1557 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1558 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1563 * if python double -> cpp double sw=1
1564 * if python int -> cpp double sw=1
1565 * if python list[double] -> cpp vector<double> sw=2
1566 * if python list[int] -> cpp vector<double> sw=2
1567 * if python tuple[double] -> cpp vector<double> sw=2
1568 * if python tuple[int] -> cpp vector<double> sw=2
1569 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1571 * switch between (int,vector<int>,DataArrayInt)
1573 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1576 if(PyFloat_Check(value))
1578 iTyypp=PyFloat_AS_DOUBLE(value);
1582 if(PyInt_Check(value))
1584 iTyypp=(double)PyInt_AS_LONG(value);
1588 if(PyTuple_Check(value))
1590 int size=PyTuple_Size(value);
1591 stdvecTyypp.resize(size);
1592 for(int i=0;i<size;i++)
1594 PyObject *o=PyTuple_GetItem(value,i);
1595 if(PyFloat_Check(o))
1596 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1597 else if(PyInt_Check(o))
1598 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1601 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1602 throw INTERP_KERNEL::Exception(oss.str().c_str());
1608 if(PyList_Check(value))
1610 int size=PyList_Size(value);
1611 stdvecTyypp.resize(size);
1612 for(int i=0;i<size;i++)
1614 PyObject *o=PyList_GetItem(value,i);
1615 if(PyFloat_Check(o))
1616 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1617 else if(PyInt_Check(o))
1618 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1621 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1622 throw INTERP_KERNEL::Exception(oss.str().c_str());
1629 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1630 if(!SWIG_IsOK(status))
1631 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1632 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1637 * if python int -> cpp int sw=1
1638 * if python list[int] -> cpp vector<int> sw=2
1639 * if python tuple[int] -> cpp vector<int> sw=2
1640 * if python slicp -> cpp pair sw=3 (begin,end,step)
1641 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1643 * switch between (int,vector<int>,DataArrayInt)
1645 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)
1647 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1649 if(PyInt_Check(value))
1651 iTyypp=(int)PyInt_AS_LONG(value);
1655 if(PyTuple_Check(value))
1657 int size=PyTuple_Size(value);
1658 stdvecTyypp.resize(size);
1659 for(int i=0;i<size;i++)
1661 PyObject *o=PyTuple_GetItem(value,i);
1663 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1666 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1667 throw INTERP_KERNEL::Exception(oss.str().c_str());
1673 if(PyList_Check(value))
1675 int size=PyList_Size(value);
1676 stdvecTyypp.resize(size);
1677 for(int i=0;i<size;i++)
1679 PyObject *o=PyList_GetItem(value,i);
1681 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1684 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1685 throw INTERP_KERNEL::Exception(oss.str().c_str());
1691 if(PySlice_Check(value))
1693 Py_ssize_t strt=2,stp=2,step=2;
1694 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1695 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1698 p.second.second=step;
1703 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1704 if(SWIG_IsOK(status))
1706 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1709 std::ostringstream oss; oss << msg << " Instance in null !";
1710 throw INTERP_KERNEL::Exception(oss.str().c_str());
1715 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1716 if(SWIG_IsOK(status))
1718 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1721 std::ostringstream oss; oss << msg << " Instance in null !";
1722 throw INTERP_KERNEL::Exception(oss.str().c_str());
1724 stdvecTyypp.resize(tmp->getNumberOfCompo());
1725 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1729 throw INTERP_KERNEL::Exception(msg);
1733 * Idem than convertObjToPossibleCpp2
1735 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)
1737 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1740 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1745 * if python int -> cpp int sw=1
1746 * if python tuple[int] -> cpp vector<int> sw=2
1747 * if python list[int] -> cpp vector<int> sw=2
1748 * if python slice -> cpp pair sw=3
1749 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1751 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)
1754 if(PyInt_Check(value))
1756 iTyypp=(int)PyInt_AS_LONG(value);
1760 if(PyTuple_Check(value))
1762 int size=PyTuple_Size(value);
1763 stdvecTyypp.resize(size);
1764 for(int i=0;i<size;i++)
1766 PyObject *o=PyTuple_GetItem(value,i);
1768 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1771 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1772 throw INTERP_KERNEL::Exception(oss.str().c_str());
1778 if(PyList_Check(value))
1780 int size=PyList_Size(value);
1781 stdvecTyypp.resize(size);
1782 for(int i=0;i<size;i++)
1784 PyObject *o=PyList_GetItem(value,i);
1786 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1789 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1790 throw INTERP_KERNEL::Exception(oss.str().c_str());
1796 if(PySlice_Check(value))
1798 Py_ssize_t strt=2,stp=2,step=2;
1799 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1800 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1803 p.second.second=step;
1808 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1809 if(!SWIG_IsOK(status))
1810 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1811 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1816 * if python string with size one -> cpp char sw=1
1817 * if python string with size different from one -> cpp string sw=2
1818 * if python tuple[string] or list[string] -> vector<string> sw=3
1819 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1820 * switch between (int,string,vector<string>,DataArrayChar)
1822 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1824 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1826 if(PyString_Check(value))
1828 const char *pt=PyString_AsString(value);
1829 Py_ssize_t sz=PyString_Size(value);
1843 if(PyTuple_Check(value))
1845 int size=PyTuple_Size(value);
1846 vsType.resize(size);
1847 for(int i=0;i<size;i++)
1849 PyObject *o=PyTuple_GetItem(value,i);
1850 if(PyString_Check(o))
1851 vsType[i]=PyString_AsString(o);
1854 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1855 throw INTERP_KERNEL::Exception(oss.str().c_str());
1861 if(PyList_Check(value))
1863 int size=PyList_Size(value);
1864 vsType.resize(size);
1865 for(int i=0;i<size;i++)
1867 PyObject *o=PyList_GetItem(value,i);
1868 if(PyString_Check(o))
1869 vsType[i]=PyString_AsString(o);
1872 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1873 throw INTERP_KERNEL::Exception(oss.str().c_str());
1880 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1881 if(SWIG_IsOK(status))
1883 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1886 std::ostringstream oss; oss << msg << " Instance in null !";
1887 throw INTERP_KERNEL::Exception(oss.str().c_str());
1892 throw INTERP_KERNEL::Exception(msg);
1896 * if value int -> cpp it sw=1
1897 * if value list[int] -> vt sw=2
1898 * if value tuple[int] -> vt sw=2
1899 * if value slice -> pt sw=3
1900 * if value DataArrayInt -> dt sw=4
1901 * if value tuple [int,int] -> cpp it,ip sw=5
1902 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1903 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1904 * if value tuple [slice,int] -> cpp pt,ip sw=7
1905 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1906 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1907 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1908 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1909 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1910 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1911 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1912 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1913 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1914 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1915 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1916 * if value tuple [int,slice] -> cpp it,pc sw=13
1917 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1918 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1919 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1920 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1922 * switch between (int,vector<int>,DataArrayInt)
1924 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1925 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1926 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1928 if(!PyTuple_Check(value))
1930 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1935 int sz=PyTuple_Size(value);
1937 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1938 PyObject *ob0=PyTuple_GetItem(value,0);
1940 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1941 PyObject *ob1=PyTuple_GetItem(value,1);
1942 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1948 * if value int -> cpp val sw=1
1949 * if value double -> cpp val sw=1
1950 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1951 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1952 * if value list[int,double] -> cpp std::vector<double> sw=4
1953 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1955 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1958 if(PyFloat_Check(value))
1960 val=PyFloat_AS_DOUBLE(value);
1964 if(PyInt_Check(value))
1966 val=(double)PyInt_AS_LONG(value);
1970 if(PyTuple_Check(value))
1972 int size=PyTuple_Size(value);
1974 for(int i=0;i<size;i++)
1976 PyObject *o=PyTuple_GetItem(value,i);
1977 if(PyFloat_Check(o))
1978 f[i]=PyFloat_AS_DOUBLE(o);
1979 else if(PyInt_Check(o))
1980 f[i]=(double)PyInt_AS_LONG(o);
1983 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1984 throw INTERP_KERNEL::Exception(oss.str().c_str());
1990 if(PyList_Check(value))
1992 int size=PyList_Size(value);
1994 for(int i=0;i<size;i++)
1996 PyObject *o=PyList_GetItem(value,i);
1997 if(PyFloat_Check(o))
1998 f[i]=PyFloat_AS_DOUBLE(o);
1999 else if(PyInt_Check(o))
2000 f[i]=(double)PyInt_AS_LONG(o);
2003 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2004 throw INTERP_KERNEL::Exception(oss.str().c_str());
2011 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2012 if(SWIG_IsOK(status))
2014 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2018 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2019 if(SWIG_IsOK(status))
2021 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2025 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2029 * if value int -> cpp val sw=1
2030 * if value double -> cpp val sw=1
2031 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2032 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2033 * if value list[int,double] -> cpp std::vector<double> sw=4
2034 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2036 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2037 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
2040 if(PyFloat_Check(value))
2042 val=PyFloat_AS_DOUBLE(value);
2044 if(nbTuplesExpected*nbCompExpected!=1)
2046 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2047 throw INTERP_KERNEL::Exception(oss.str().c_str());
2051 if(PyInt_Check(value))
2053 val=(double)PyInt_AS_LONG(value);
2055 if(nbTuplesExpected*nbCompExpected!=1)
2057 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2058 throw INTERP_KERNEL::Exception(oss.str().c_str());
2062 if(PyTuple_Check(value) || PyList_Check(value))
2066 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2067 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2072 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2075 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2076 if(SWIG_IsOK(status))
2078 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2082 if(d->getNumberOfTuples()==nbTuplesExpected)
2084 if(d->getNumberOfComponents()==nbCompExpected)
2086 return d->getConstPointer();
2090 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2091 throw INTERP_KERNEL::Exception(oss.str().c_str());
2096 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2097 throw INTERP_KERNEL::Exception(oss.str().c_str());
2104 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2105 throw INTERP_KERNEL::Exception(oss.str().c_str());
2111 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2112 if(SWIG_IsOK(status))
2114 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2116 if(e->getNumberOfCompo()==nbCompExpected)
2118 if(nbTuplesExpected==1)
2119 return e->getConstPointer();
2122 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2123 throw INTERP_KERNEL::Exception(oss.str().c_str());
2128 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2129 throw INTERP_KERNEL::Exception(oss.str().c_str());
2132 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2136 * if value int -> cpp val sw=1
2137 * if value double -> cpp val sw=1
2138 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2139 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2140 * if value list[int,double] -> cpp std::vector<double> sw=4
2141 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2143 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2144 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2147 if(PyFloat_Check(value))
2149 val=PyFloat_AS_DOUBLE(value);
2151 if(nbCompExpected!=1)
2153 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2154 throw INTERP_KERNEL::Exception(oss.str().c_str());
2159 if(PyInt_Check(value))
2161 val=(double)PyInt_AS_LONG(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 PyInt) !";
2166 throw INTERP_KERNEL::Exception(oss.str().c_str());
2171 if(PyTuple_Check(value))
2173 int size=PyTuple_Size(value);
2175 for(int i=0;i<size;i++)
2177 PyObject *o=PyTuple_GetItem(value,i);
2178 if(PyFloat_Check(o))
2179 f[i]=PyFloat_AS_DOUBLE(o);
2180 else if(PyInt_Check(o))
2181 f[i]=(double)PyInt_AS_LONG(o);
2184 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2185 throw INTERP_KERNEL::Exception(oss.str().c_str());
2189 if(size%nbCompExpected!=0)
2191 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2192 throw INTERP_KERNEL::Exception(oss.str().c_str());
2194 nbTuples=size/nbCompExpected;
2197 if(PyList_Check(value))
2199 int size=PyList_Size(value);
2201 for(int i=0;i<size;i++)
2203 PyObject *o=PyList_GetItem(value,i);
2204 if(PyFloat_Check(o))
2205 f[i]=PyFloat_AS_DOUBLE(o);
2206 else if(PyInt_Check(o))
2207 f[i]=(double)PyInt_AS_LONG(o);
2210 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2211 throw INTERP_KERNEL::Exception(oss.str().c_str());
2215 if(size%nbCompExpected!=0)
2217 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2218 throw INTERP_KERNEL::Exception(oss.str().c_str());
2220 nbTuples=size/nbCompExpected;
2224 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2225 if(SWIG_IsOK(status))
2227 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2231 if(d->getNumberOfComponents()==nbCompExpected)
2233 nbTuples=d->getNumberOfTuples();
2234 return d->getConstPointer();
2238 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2239 throw INTERP_KERNEL::Exception(oss.str().c_str());
2246 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2247 throw INTERP_KERNEL::Exception(oss.str().c_str());
2250 { nbTuples=0; return 0; }
2253 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2254 if(SWIG_IsOK(status))
2256 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2260 if(e->getNumberOfCompo()==nbCompExpected)
2263 return e->getConstPointer();
2267 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2268 throw INTERP_KERNEL::Exception(oss.str().c_str());
2275 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2276 throw INTERP_KERNEL::Exception(oss.str().c_str());
2279 { nbTuples=0; return 0; }
2282 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2286 * if value int -> cpp val sw=1
2287 * if value double -> cpp val sw=1
2288 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2289 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2290 * if value list[int,double] -> cpp std::vector<double> sw=4
2291 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2293 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2294 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2296 ParaMEDMEM::DataArrayDouble *d=0;
2297 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2299 if(PyFloat_Check(value))
2301 val=PyFloat_AS_DOUBLE(value);
2306 if(PyInt_Check(value))
2308 val=(double)PyInt_AS_LONG(value);
2313 if(PyTuple_Check(value))
2315 int size=PyTuple_Size(value);
2317 for(int i=0;i<size;i++)
2319 PyObject *o=PyTuple_GetItem(value,i);
2320 if(PyFloat_Check(o))
2321 f[i]=PyFloat_AS_DOUBLE(o);
2322 else if(PyInt_Check(o))
2323 f[i]=(double)PyInt_AS_LONG(o);
2326 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2327 throw INTERP_KERNEL::Exception(oss.str().c_str());
2334 if(PyList_Check(value))
2336 int size=PyList_Size(value);
2338 for(int i=0;i<size;i++)
2340 PyObject *o=PyList_GetItem(value,i);
2341 if(PyFloat_Check(o))
2342 f[i]=PyFloat_AS_DOUBLE(o);
2343 else if(PyInt_Check(o))
2344 f[i]=(double)PyInt_AS_LONG(o);
2347 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2348 throw INTERP_KERNEL::Exception(oss.str().c_str());
2356 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2357 if(SWIG_IsOK(status))
2359 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2363 if(d->getNumberOfComponents()==1)
2365 nbTuples=d->getNumberOfTuples();
2366 return d->getConstPointer();
2370 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2371 throw INTERP_KERNEL::Exception(oss.str().c_str());
2378 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2379 throw INTERP_KERNEL::Exception(oss.str().c_str());
2382 { nbTuples=0; return 0; }
2385 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2386 if(SWIG_IsOK(status))
2388 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2392 nbTuples=e->getNumberOfCompo();
2393 return e->getConstPointer();
2399 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2400 throw INTERP_KERNEL::Exception(oss.str().c_str());
2403 { nbTuples=0; return 0; }
2406 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2410 * if python int -> cpp int sw=1
2411 * if python list[int] -> cpp vector<int> sw=2
2412 * if python tuple[int] -> cpp vector<int> sw=2
2413 * if python DataArrayInt -> cpp DataArrayInt sw=3
2414 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2416 * switch between (int,vector<int>,DataArrayInt)
2418 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2421 if(PyInt_Check(value))
2423 iTyypp=(int)PyInt_AS_LONG(value);
2427 if(PyTuple_Check(value))
2429 int size=PyTuple_Size(value);
2430 stdvecTyypp.resize(size);
2431 for(int i=0;i<size;i++)
2433 PyObject *o=PyTuple_GetItem(value,i);
2435 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2438 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2439 throw INTERP_KERNEL::Exception(oss.str().c_str());
2443 return &stdvecTyypp[0];
2445 if(PyList_Check(value))
2447 int size=PyList_Size(value);
2448 stdvecTyypp.resize(size);
2449 for(int i=0;i<size;i++)
2451 PyObject *o=PyList_GetItem(value,i);
2453 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2456 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2457 throw INTERP_KERNEL::Exception(oss.str().c_str());
2461 return &stdvecTyypp[0];
2464 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2465 if(SWIG_IsOK(status))
2467 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2470 sw=3; sz=daIntTyypp->getNbOfElems();
2471 return daIntTyypp->begin();
2479 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2480 if(SWIG_IsOK(status))
2482 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2483 sw=4; sz=daIntTuple->getNumberOfCompo();
2484 return daIntTuple->getConstPointer();
2486 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2489 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2492 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2493 if(!SWIG_IsOK(status))
2495 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2496 if(!SWIG_IsOK(status))
2498 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2499 if(!SWIG_IsOK(status))
2501 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2502 if(!SWIG_IsOK(status))
2504 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2505 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2506 throw INTERP_KERNEL::Exception(oss.str().c_str());
2511 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);