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 void convertPyToVectorPairStringVecString(PyObject *pyLi, std::vector< std::pair<std::string, std::vector<std::string> > >& arr) throw(INTERP_KERNEL::Exception)
1048 const char msg[]="convertPyToVectorPairStringVecString : expecting list of tuples containing each exactly 2 items : one string and one vector of string !";
1049 if(PyList_Check(pyLi))
1051 Py_ssize_t sz=PyList_Size(pyLi);
1053 for(int i=0;i<sz;i++)
1055 PyObject *o=PyList_GetItem(pyLi,i);
1056 if(PyTuple_Check(o))
1058 int sz2=PyTuple_Size(o);
1060 throw INTERP_KERNEL::Exception(msg);
1061 std::pair<std::string, std::vector<std::string> > item;
1062 PyObject *o_0=PyTuple_GetItem(o,0);
1063 if(!PyString_Check(o_0))
1064 throw INTERP_KERNEL::Exception(msg);
1065 item.first=PyString_AsString(o_0);
1066 PyObject *o_1=PyTuple_GetItem(o,1);
1067 if(!fillStringVector(o_1,item.second))
1068 throw INTERP_KERNEL::Exception(msg);
1072 throw INTERP_KERNEL::Exception(msg);
1075 else if(PyTuple_Check(pyLi))
1077 Py_ssize_t sz=PyTuple_Size(pyLi);
1079 for(int i=0;i<sz;i++)
1081 PyObject *o=PyTuple_GetItem(pyLi,i);
1082 if(PyTuple_Check(o))
1084 int sz2=PyTuple_Size(o);
1086 throw INTERP_KERNEL::Exception(msg);
1087 std::pair<std::string, std::vector<std::string> > item;
1088 PyObject *o_0=PyTuple_GetItem(o,0);
1089 if(!PyString_Check(o_0))
1090 throw INTERP_KERNEL::Exception(msg);
1091 item.first=PyString_AsString(o_0);
1092 PyObject *o_1=PyTuple_GetItem(o,1);
1093 if(!fillStringVector(o_1,item.second))
1094 throw INTERP_KERNEL::Exception(msg);
1098 throw INTERP_KERNEL::Exception(msg);
1102 throw INTERP_KERNEL::Exception(msg);
1105 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
1107 PyObject *ret=PyList_New(size);
1108 for(int i=0;i<size;i++)
1109 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
1113 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
1116 PyObject *ret=PyList_New(size);
1117 for(int i=0;i<size;i++)
1118 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
1122 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1124 PyObject *ret=PyList_New(nbOfTuples);
1125 for(int i=0;i<nbOfTuples;i++)
1127 PyObject *t=PyTuple_New(nbOfComp);
1128 for(int j=0;j<nbOfComp;j++)
1129 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
1130 PyList_SetItem(ret,i,t);
1135 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
1137 PyObject *ret=PyList_New(nbOfTuples);
1138 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
1139 for(int i=0;i<nbOfTuples;i++)
1141 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
1142 PyList_SetItem(ret,i,PyString_FromString(tmp));
1147 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1149 if(PyList_Check(pyLi))
1151 *size=PyList_Size(pyLi);
1152 double *tmp=(double *)malloc((*size)*sizeof(double));
1153 for(int i=0;i<*size;i++)
1155 PyObject *o=PyList_GetItem(pyLi,i);
1156 if(PyFloat_Check(o))
1158 double val=PyFloat_AS_DOUBLE(o);
1161 else if(PyInt_Check(o))
1163 long val0=PyInt_AS_LONG(o);
1170 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1175 else if(PyTuple_Check(pyLi))
1177 *size=PyTuple_Size(pyLi);
1178 double *tmp=(double *)malloc((*size)*sizeof(double));
1179 for(int i=0;i<*size;i++)
1181 PyObject *o=PyTuple_GetItem(pyLi,i);
1182 if(PyFloat_Check(o))
1184 double val=PyFloat_AS_DOUBLE(o);
1187 else if(PyInt_Check(o))
1189 long val0=PyInt_AS_LONG(o);
1196 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1202 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1205 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1207 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1208 if(PyFloat_Check(pyLi))
1214 throw INTERP_KERNEL::Exception(MSG);
1215 double val=PyFloat_AS_DOUBLE(pyLi);
1218 else if(PyInt_Check(pyLi))
1220 long val0=PyInt_AS_LONG(pyLi);
1226 throw INTERP_KERNEL::Exception(MSG);
1229 else if(PyList_Check(pyLi))
1231 int size=PyList_Size(pyLi);
1233 for(int i=0;i<size;i++)
1235 PyObject *o=PyList_GetItem(pyLi,i);
1237 fillArrayWithPyListDbl3(o,tmp1,ret);
1245 throw INTERP_KERNEL::Exception(MSG);
1248 else if(PyTuple_Check(pyLi))
1250 int size=PyTuple_Size(pyLi);
1252 for(int i=0;i<size;i++)
1254 PyObject *o=PyTuple_GetItem(pyLi,i);
1256 fillArrayWithPyListDbl3(o,tmp1,ret);
1264 throw INTERP_KERNEL::Exception(MSG);
1268 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1271 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1273 std::vector<double> ret;
1274 int size1=-1,size2=-1;
1275 if(PyList_Check(pyLi))
1277 size1=PyList_Size(pyLi);
1278 for(int i=0;i<size1;i++)
1280 PyObject *o=PyList_GetItem(pyLi,i);
1281 fillArrayWithPyListDbl3(o,size2,ret);
1286 else if(PyTuple_Check(pyLi))
1288 size1=PyTuple_Size(pyLi);
1289 for(int i=0;i<size1;i++)
1291 PyObject *o=PyTuple_GetItem(pyLi,i);
1292 fillArrayWithPyListDbl3(o,size2,ret);
1298 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1300 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1304 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1306 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1309 if(PyList_Check(pyLi))
1311 int size=PyList_Size(pyLi);
1313 for(int i=0;i<size;i++)
1315 PyObject *obj=PyList_GetItem(pyLi,i);
1316 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1317 if(!SWIG_IsOK(status))
1319 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1320 throw INTERP_KERNEL::Exception(oss.str().c_str());
1322 T arg=reinterpret_cast< T >(argp);
1326 else if(PyTuple_Check(pyLi))
1328 int size=PyTuple_Size(pyLi);
1330 for(int i=0;i<size;i++)
1332 PyObject *obj=PyTuple_GetItem(pyLi,i);
1333 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1334 if(!SWIG_IsOK(status))
1336 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1337 throw INTERP_KERNEL::Exception(oss.str().c_str());
1339 T arg=reinterpret_cast< T >(argp);
1343 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1346 T arg=reinterpret_cast< T >(argp);
1350 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1354 * if python int -> cpp int sw=1
1355 * if python list[int] -> cpp vector<int> sw=2
1356 * if python tuple[int] -> cpp vector<int> sw=2
1357 * if python DataArrayInt -> cpp DataArrayInt sw=3
1358 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1360 * switch between (int,vector<int>,DataArrayInt)
1362 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1365 if(PyInt_Check(value))
1367 iTyypp=(int)PyInt_AS_LONG(value);
1371 if(PyTuple_Check(value))
1373 int size=PyTuple_Size(value);
1374 stdvecTyypp.resize(size);
1375 for(int i=0;i<size;i++)
1377 PyObject *o=PyTuple_GetItem(value,i);
1379 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1382 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1383 throw INTERP_KERNEL::Exception(oss.str().c_str());
1389 if(PyList_Check(value))
1391 int size=PyList_Size(value);
1392 stdvecTyypp.resize(size);
1393 for(int i=0;i<size;i++)
1395 PyObject *o=PyList_GetItem(value,i);
1397 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1400 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1401 throw INTERP_KERNEL::Exception(oss.str().c_str());
1408 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1409 if(SWIG_IsOK(status))
1411 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1415 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1416 if(SWIG_IsOK(status))
1418 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1422 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1426 * if python double -> cpp double sw=1
1427 * if python int -> cpp double sw=1
1428 * if python list[double] -> cpp vector<double> sw=2
1429 * if python list[int] -> cpp vector<double> sw=2
1430 * if python tuple[double] -> cpp vector<double> sw=2
1431 * if python tuple[int] -> cpp vector<double> sw=2
1432 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1434 * switch between (int,vector<int>,DataArrayInt)
1436 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1439 if(PyFloat_Check(value))
1441 iTyypp=PyFloat_AS_DOUBLE(value);
1445 if(PyInt_Check(value))
1447 iTyypp=(double)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);
1458 if(PyFloat_Check(o))
1459 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1460 else if(PyInt_Check(o))
1461 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1464 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1465 throw INTERP_KERNEL::Exception(oss.str().c_str());
1471 if(PyList_Check(value))
1473 int size=PyList_Size(value);
1474 stdvecTyypp.resize(size);
1475 for(int i=0;i<size;i++)
1477 PyObject *o=PyList_GetItem(value,i);
1478 if(PyFloat_Check(o))
1479 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1480 else if(PyInt_Check(o))
1481 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1484 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1485 throw INTERP_KERNEL::Exception(oss.str().c_str());
1492 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1493 if(!SWIG_IsOK(status))
1494 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1495 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1500 * if python double -> cpp double sw=1
1501 * if python int -> cpp double sw=1
1502 * if python list[double] -> cpp vector<double> sw=2
1503 * if python list[int] -> cpp vector<double> sw=2
1504 * if python tuple[double] -> cpp vector<double> sw=2
1505 * if python tuple[int] -> cpp vector<double> sw=2
1506 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1508 * switch between (int,vector<int>,DataArrayInt)
1510 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1513 if(PyFloat_Check(value))
1515 iTyypp=PyFloat_AS_DOUBLE(value);
1519 if(PyInt_Check(value))
1521 iTyypp=(double)PyInt_AS_LONG(value);
1525 if(PyTuple_Check(value))
1527 int size=PyTuple_Size(value);
1528 stdvecTyypp.resize(size);
1529 for(int i=0;i<size;i++)
1531 PyObject *o=PyTuple_GetItem(value,i);
1532 if(PyFloat_Check(o))
1533 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1534 else if(PyInt_Check(o))
1535 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1538 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1539 throw INTERP_KERNEL::Exception(oss.str().c_str());
1545 if(PyList_Check(value))
1547 int size=PyList_Size(value);
1548 stdvecTyypp.resize(size);
1549 for(int i=0;i<size;i++)
1551 PyObject *o=PyList_GetItem(value,i);
1552 if(PyFloat_Check(o))
1553 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1554 else if(PyInt_Check(o))
1555 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1558 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1559 throw INTERP_KERNEL::Exception(oss.str().c_str());
1566 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1567 if(!SWIG_IsOK(status))
1568 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1569 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1574 * if python int -> cpp int sw=1
1575 * if python list[int] -> cpp vector<int> sw=2
1576 * if python tuple[int] -> cpp vector<int> sw=2
1577 * if python slicp -> cpp pair sw=3 (begin,end,step)
1578 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1580 * switch between (int,vector<int>,DataArrayInt)
1582 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)
1584 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1586 if(PyInt_Check(value))
1588 iTyypp=(int)PyInt_AS_LONG(value);
1592 if(PyTuple_Check(value))
1594 int size=PyTuple_Size(value);
1595 stdvecTyypp.resize(size);
1596 for(int i=0;i<size;i++)
1598 PyObject *o=PyTuple_GetItem(value,i);
1600 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1603 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1604 throw INTERP_KERNEL::Exception(oss.str().c_str());
1610 if(PyList_Check(value))
1612 int size=PyList_Size(value);
1613 stdvecTyypp.resize(size);
1614 for(int i=0;i<size;i++)
1616 PyObject *o=PyList_GetItem(value,i);
1618 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1621 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1622 throw INTERP_KERNEL::Exception(oss.str().c_str());
1628 if(PySlice_Check(value))
1630 Py_ssize_t strt=2,stp=2,step=2;
1631 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1632 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1635 p.second.second=step;
1640 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1641 if(SWIG_IsOK(status))
1643 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1646 std::ostringstream oss; oss << msg << " Instance in null !";
1647 throw INTERP_KERNEL::Exception(oss.str().c_str());
1652 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1653 if(SWIG_IsOK(status))
1655 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1658 std::ostringstream oss; oss << msg << " Instance in null !";
1659 throw INTERP_KERNEL::Exception(oss.str().c_str());
1661 stdvecTyypp.resize(tmp->getNumberOfCompo());
1662 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1666 throw INTERP_KERNEL::Exception(msg);
1670 * Idem than convertObjToPossibleCpp2
1672 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)
1674 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1677 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1682 * if python int -> cpp int sw=1
1683 * if python tuple[int] -> cpp vector<int> sw=2
1684 * if python list[int] -> cpp vector<int> sw=2
1685 * if python slice -> cpp pair sw=3
1686 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1688 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)
1691 if(PyInt_Check(value))
1693 iTyypp=(int)PyInt_AS_LONG(value);
1697 if(PyTuple_Check(value))
1699 int size=PyTuple_Size(value);
1700 stdvecTyypp.resize(size);
1701 for(int i=0;i<size;i++)
1703 PyObject *o=PyTuple_GetItem(value,i);
1705 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1708 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1709 throw INTERP_KERNEL::Exception(oss.str().c_str());
1715 if(PyList_Check(value))
1717 int size=PyList_Size(value);
1718 stdvecTyypp.resize(size);
1719 for(int i=0;i<size;i++)
1721 PyObject *o=PyList_GetItem(value,i);
1723 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1726 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1727 throw INTERP_KERNEL::Exception(oss.str().c_str());
1733 if(PySlice_Check(value))
1735 Py_ssize_t strt=2,stp=2,step=2;
1736 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1737 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1740 p.second.second=step;
1745 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1746 if(!SWIG_IsOK(status))
1747 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1748 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1753 * if python string with size one -> cpp char sw=1
1754 * if python string with size different from one -> cpp string sw=2
1755 * if python tuple[string] or list[string] -> vector<string> sw=3
1756 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1757 * switch between (int,string,vector<string>,DataArrayChar)
1759 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1761 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1763 if(PyString_Check(value))
1765 const char *pt=PyString_AsString(value);
1766 Py_ssize_t sz=PyString_Size(value);
1780 if(PyTuple_Check(value))
1782 int size=PyTuple_Size(value);
1783 vsType.resize(size);
1784 for(int i=0;i<size;i++)
1786 PyObject *o=PyTuple_GetItem(value,i);
1787 if(PyString_Check(o))
1788 vsType[i]=PyString_AsString(o);
1791 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1792 throw INTERP_KERNEL::Exception(oss.str().c_str());
1798 if(PyList_Check(value))
1800 int size=PyList_Size(value);
1801 vsType.resize(size);
1802 for(int i=0;i<size;i++)
1804 PyObject *o=PyList_GetItem(value,i);
1805 if(PyString_Check(o))
1806 vsType[i]=PyString_AsString(o);
1809 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1810 throw INTERP_KERNEL::Exception(oss.str().c_str());
1817 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1818 if(SWIG_IsOK(status))
1820 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1823 std::ostringstream oss; oss << msg << " Instance in null !";
1824 throw INTERP_KERNEL::Exception(oss.str().c_str());
1829 throw INTERP_KERNEL::Exception(msg);
1833 * if value int -> cpp it sw=1
1834 * if value list[int] -> vt sw=2
1835 * if value tuple[int] -> vt sw=2
1836 * if value slice -> pt sw=3
1837 * if value DataArrayInt -> dt sw=4
1838 * if value tuple [int,int] -> cpp it,ip sw=5
1839 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1840 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1841 * if value tuple [slice,int] -> cpp pt,ip sw=7
1842 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1843 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1844 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1845 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1846 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1847 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1848 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1849 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1850 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1851 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1852 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1853 * if value tuple [int,slice] -> cpp it,pc sw=13
1854 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1855 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1856 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1857 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1859 * switch between (int,vector<int>,DataArrayInt)
1861 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1862 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1863 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1865 if(!PyTuple_Check(value))
1867 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1872 int sz=PyTuple_Size(value);
1874 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1875 PyObject *ob0=PyTuple_GetItem(value,0);
1877 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1878 PyObject *ob1=PyTuple_GetItem(value,1);
1879 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1885 * if value int -> cpp val sw=1
1886 * if value double -> cpp val sw=1
1887 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1888 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1889 * if value list[int,double] -> cpp std::vector<double> sw=4
1890 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1892 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1895 if(PyFloat_Check(value))
1897 val=PyFloat_AS_DOUBLE(value);
1901 if(PyInt_Check(value))
1903 val=(double)PyInt_AS_LONG(value);
1907 if(PyTuple_Check(value))
1909 int size=PyTuple_Size(value);
1911 for(int i=0;i<size;i++)
1913 PyObject *o=PyTuple_GetItem(value,i);
1914 if(PyFloat_Check(o))
1915 f[i]=PyFloat_AS_DOUBLE(o);
1916 else if(PyInt_Check(o))
1917 f[i]=(double)PyInt_AS_LONG(o);
1920 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1921 throw INTERP_KERNEL::Exception(oss.str().c_str());
1927 if(PyList_Check(value))
1929 int size=PyList_Size(value);
1931 for(int i=0;i<size;i++)
1933 PyObject *o=PyList_GetItem(value,i);
1934 if(PyFloat_Check(o))
1935 f[i]=PyFloat_AS_DOUBLE(o);
1936 else if(PyInt_Check(o))
1937 f[i]=(double)PyInt_AS_LONG(o);
1940 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1941 throw INTERP_KERNEL::Exception(oss.str().c_str());
1948 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1949 if(SWIG_IsOK(status))
1951 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1955 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1956 if(SWIG_IsOK(status))
1958 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1962 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1966 * if value int -> cpp val sw=1
1967 * if value double -> cpp val sw=1
1968 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1969 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1970 * if value list[int,double] -> cpp std::vector<double> sw=4
1971 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1973 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1974 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1977 if(PyFloat_Check(value))
1979 val=PyFloat_AS_DOUBLE(value);
1981 if(nbTuplesExpected*nbCompExpected!=1)
1983 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1984 throw INTERP_KERNEL::Exception(oss.str().c_str());
1988 if(PyInt_Check(value))
1990 val=(double)PyInt_AS_LONG(value);
1992 if(nbTuplesExpected*nbCompExpected!=1)
1994 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1995 throw INTERP_KERNEL::Exception(oss.str().c_str());
1999 if(PyTuple_Check(value) || PyList_Check(value))
2003 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
2004 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
2009 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
2012 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2013 if(SWIG_IsOK(status))
2015 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2019 if(d->getNumberOfTuples()==nbTuplesExpected)
2021 if(d->getNumberOfComponents()==nbCompExpected)
2023 return d->getConstPointer();
2027 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2028 throw INTERP_KERNEL::Exception(oss.str().c_str());
2033 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
2034 throw INTERP_KERNEL::Exception(oss.str().c_str());
2041 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2042 throw INTERP_KERNEL::Exception(oss.str().c_str());
2048 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2049 if(SWIG_IsOK(status))
2051 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2053 if(e->getNumberOfCompo()==nbCompExpected)
2055 if(nbTuplesExpected==1)
2056 return e->getConstPointer();
2059 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
2060 throw INTERP_KERNEL::Exception(oss.str().c_str());
2065 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2066 throw INTERP_KERNEL::Exception(oss.str().c_str());
2069 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2073 * if value int -> cpp val sw=1
2074 * if value double -> cpp val sw=1
2075 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2076 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2077 * if value list[int,double] -> cpp std::vector<double> sw=4
2078 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2080 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
2081 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2084 if(PyFloat_Check(value))
2086 val=PyFloat_AS_DOUBLE(value);
2088 if(nbCompExpected!=1)
2090 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
2091 throw INTERP_KERNEL::Exception(oss.str().c_str());
2096 if(PyInt_Check(value))
2098 val=(double)PyInt_AS_LONG(value);
2100 if(nbCompExpected!=1)
2102 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
2103 throw INTERP_KERNEL::Exception(oss.str().c_str());
2108 if(PyTuple_Check(value))
2110 int size=PyTuple_Size(value);
2112 for(int i=0;i<size;i++)
2114 PyObject *o=PyTuple_GetItem(value,i);
2115 if(PyFloat_Check(o))
2116 f[i]=PyFloat_AS_DOUBLE(o);
2117 else if(PyInt_Check(o))
2118 f[i]=(double)PyInt_AS_LONG(o);
2121 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2126 if(size%nbCompExpected!=0)
2128 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2129 throw INTERP_KERNEL::Exception(oss.str().c_str());
2131 nbTuples=size/nbCompExpected;
2134 if(PyList_Check(value))
2136 int size=PyList_Size(value);
2138 for(int i=0;i<size;i++)
2140 PyObject *o=PyList_GetItem(value,i);
2141 if(PyFloat_Check(o))
2142 f[i]=PyFloat_AS_DOUBLE(o);
2143 else if(PyInt_Check(o))
2144 f[i]=(double)PyInt_AS_LONG(o);
2147 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2148 throw INTERP_KERNEL::Exception(oss.str().c_str());
2152 if(size%nbCompExpected!=0)
2154 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2155 throw INTERP_KERNEL::Exception(oss.str().c_str());
2157 nbTuples=size/nbCompExpected;
2161 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2162 if(SWIG_IsOK(status))
2164 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2168 if(d->getNumberOfComponents()==nbCompExpected)
2170 nbTuples=d->getNumberOfTuples();
2171 return d->getConstPointer();
2175 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2176 throw INTERP_KERNEL::Exception(oss.str().c_str());
2183 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2184 throw INTERP_KERNEL::Exception(oss.str().c_str());
2187 { nbTuples=0; return 0; }
2190 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2191 if(SWIG_IsOK(status))
2193 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2197 if(e->getNumberOfCompo()==nbCompExpected)
2200 return e->getConstPointer();
2204 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2205 throw INTERP_KERNEL::Exception(oss.str().c_str());
2212 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2213 throw INTERP_KERNEL::Exception(oss.str().c_str());
2216 { nbTuples=0; return 0; }
2219 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2223 * if value int -> cpp val sw=1
2224 * if value double -> cpp val sw=1
2225 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2226 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2227 * if value list[int,double] -> cpp std::vector<double> sw=4
2228 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2230 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2231 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2233 ParaMEDMEM::DataArrayDouble *d=0;
2234 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2236 if(PyFloat_Check(value))
2238 val=PyFloat_AS_DOUBLE(value);
2243 if(PyInt_Check(value))
2245 val=(double)PyInt_AS_LONG(value);
2250 if(PyTuple_Check(value))
2252 int size=PyTuple_Size(value);
2254 for(int i=0;i<size;i++)
2256 PyObject *o=PyTuple_GetItem(value,i);
2257 if(PyFloat_Check(o))
2258 f[i]=PyFloat_AS_DOUBLE(o);
2259 else if(PyInt_Check(o))
2260 f[i]=(double)PyInt_AS_LONG(o);
2263 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2264 throw INTERP_KERNEL::Exception(oss.str().c_str());
2271 if(PyList_Check(value))
2273 int size=PyList_Size(value);
2275 for(int i=0;i<size;i++)
2277 PyObject *o=PyList_GetItem(value,i);
2278 if(PyFloat_Check(o))
2279 f[i]=PyFloat_AS_DOUBLE(o);
2280 else if(PyInt_Check(o))
2281 f[i]=(double)PyInt_AS_LONG(o);
2284 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2285 throw INTERP_KERNEL::Exception(oss.str().c_str());
2293 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2294 if(SWIG_IsOK(status))
2296 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2300 if(d->getNumberOfComponents()==1)
2302 nbTuples=d->getNumberOfTuples();
2303 return d->getConstPointer();
2307 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2308 throw INTERP_KERNEL::Exception(oss.str().c_str());
2315 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2316 throw INTERP_KERNEL::Exception(oss.str().c_str());
2319 { nbTuples=0; return 0; }
2322 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2323 if(SWIG_IsOK(status))
2325 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2329 nbTuples=e->getNumberOfCompo();
2330 return e->getConstPointer();
2336 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2337 throw INTERP_KERNEL::Exception(oss.str().c_str());
2340 { nbTuples=0; return 0; }
2343 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2347 * if python int -> cpp int sw=1
2348 * if python list[int] -> cpp vector<int> sw=2
2349 * if python tuple[int] -> cpp vector<int> sw=2
2350 * if python DataArrayInt -> cpp DataArrayInt sw=3
2351 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2353 * switch between (int,vector<int>,DataArrayInt)
2355 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2358 if(PyInt_Check(value))
2360 iTyypp=(int)PyInt_AS_LONG(value);
2364 if(PyTuple_Check(value))
2366 int size=PyTuple_Size(value);
2367 stdvecTyypp.resize(size);
2368 for(int i=0;i<size;i++)
2370 PyObject *o=PyTuple_GetItem(value,i);
2372 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2375 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2376 throw INTERP_KERNEL::Exception(oss.str().c_str());
2380 return &stdvecTyypp[0];
2382 if(PyList_Check(value))
2384 int size=PyList_Size(value);
2385 stdvecTyypp.resize(size);
2386 for(int i=0;i<size;i++)
2388 PyObject *o=PyList_GetItem(value,i);
2390 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2393 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2394 throw INTERP_KERNEL::Exception(oss.str().c_str());
2398 return &stdvecTyypp[0];
2401 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2402 if(SWIG_IsOK(status))
2404 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2407 sw=3; sz=daIntTyypp->getNbOfElems();
2408 return daIntTyypp->begin();
2416 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2417 if(SWIG_IsOK(status))
2419 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2420 sw=4; sz=daIntTuple->getNumberOfCompo();
2421 return daIntTuple->getConstPointer();
2423 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2426 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2429 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2430 if(!SWIG_IsOK(status))
2432 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2433 if(!SWIG_IsOK(status))
2435 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2436 if(!SWIG_IsOK(status))
2438 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2439 if(!SWIG_IsOK(status))
2441 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2442 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2443 throw INTERP_KERNEL::Exception(oss.str().c_str());
2448 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);