1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelAutoPtr.hxx"
24 #include <numpy/arrayobject.h>
26 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
27 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
28 // if no more alive the "standart" DataArray deallocator is called.
29 void numarrdeal(void *pt, void *wron)
31 void **wronc=(void **)wron;
32 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
33 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
37 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
38 objC->flags|=NPY_OWNDATA;
39 Py_XDECREF(weakRefOnOwner);
44 typedef void (*MyDeallocator)(void *,void *);
45 MyDeallocator deall=(MyDeallocator)wronc[1];
47 Py_XDECREF(weakRefOnOwner);
52 template<class MCData>
53 struct PyCallBackDataArraySt {
58 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
59 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
63 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
65 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
67 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
68 return (PyObject *)self;
71 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
73 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
74 return (PyObject *)self;
77 static void callbackmcdataarray_dealloc(PyObject *self)
79 Py_TYPE(self)->tp_free(self);
82 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
83 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
84 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
88 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
95 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
96 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
97 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
101 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
109 PyTypeObject PyCallBackDataArrayInt_RefType = {
110 PyVarObject_HEAD_INIT(&PyType_Type, 0)
111 "callbackmcdataarrayint",
112 sizeof(PyCallBackDataArrayInt),
114 callbackmcdataarray_dealloc, /*tp_dealloc*/
121 0, /*tp_as_sequence*/
124 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
129 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
133 0, /*tp_richcompare*/
134 0, /*tp_weaklistoffset*/
145 callbackmcdataarray___init__, /*tp_init*/
146 PyType_GenericAlloc, /*tp_alloc*/
147 callbackmcdataarrayint___new__, /*tp_new*/
148 PyObject_GC_Del, /*tp_free*/
151 PyTypeObject PyCallBackDataArrayDouble_RefType = {
152 PyVarObject_HEAD_INIT(&PyType_Type, 0)
153 "callbackmcdataarraydouble",
154 sizeof(PyCallBackDataArrayDouble),
156 callbackmcdataarray_dealloc, /*tp_dealloc*/
163 0, /*tp_as_sequence*/
166 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
171 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
175 0, /*tp_richcompare*/
176 0, /*tp_weaklistoffset*/
187 callbackmcdataarray___init__, /*tp_init*/
188 PyType_GenericAlloc, /*tp_alloc*/
189 callbackmcdataarraydouble___new__, /*tp_new*/
190 PyObject_GC_Del, /*tp_free*/
193 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
194 // in input when an another DataArray is already client of this.
195 template<class MCData>
196 void numarrdeal2(void *pt, void *obj)
198 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
199 void **obj1=(void **)obj;
200 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
201 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
203 Py_XDECREF(weakRefOnOwner);
208 template<class MCData, class T>
209 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
211 int ndim=PyArray_NDIM(elt0);
212 if(ndim!=1 && ndim!=2)
213 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
214 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
216 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
217 throw INTERP_KERNEL::Exception(oss.str().c_str());
219 npy_intp sz0=PyArray_DIM(elt0,0);
220 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
222 int itemSize=PyArray_ITEMSIZE(elt0);
223 if(itemSize!=sizeof(T))
225 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
226 throw INTERP_KERNEL::Exception(oss.str().c_str());
228 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
229 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
231 if(itemSize!=PyArray_STRIDE(elt0,1))
232 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 !");
233 const char *data=PyArray_BYTES(elt0);
234 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
235 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
237 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
238 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
239 int mask=NPY_OWNDATA; mask=~mask;
241 PyObject *deepestObj=elt0;
242 PyObject *base=elt0C->base;
243 if(base) deepestObj=base;
246 if(PyArray_Check(base))
248 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
249 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
252 if(base) deepestObj=base;
257 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
260 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
262 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
263 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
264 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
265 mma.setParameterForDeallocator(objs);
266 mma.setSpecificDeallocator(numarrdeal2<MCData>);
267 //"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 !");
271 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
272 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
273 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) ParaMEDMEM::MemArray<T>::CDeallocator;
274 mma.setParameterForDeallocator(objs);
275 mma.setSpecificDeallocator(numarrdeal);
278 else if(PyArray_ISBEHAVED_RO(elt0))
279 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
284 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
287 PyErr_SetString(PyExc_ValueError,
288 "Cannot set the NumPy array 'base' "
289 "dependency to NULL after initialization");
293 * Allow the base to be set only once. Once the object which
294 * owns the data is set, it doesn't make sense to change it.
296 if (PyArray_BASE(arr) != NULL) {
298 PyErr_SetString(PyExc_ValueError,
299 "Cannot set the NumPy array 'base' "
300 "dependency more than once");
305 * Don't allow infinite chains of views, always set the base
306 * to the first owner of the data.
307 * That is, either the first object which isn't an array,
308 * or the first object which owns its own data.
311 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
312 PyArrayObject *obj_arr = (PyArrayObject *)obj;
316 /* If this array owns its own data, stop collapsing */
317 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
321 tmp = PyArray_BASE(obj_arr);
322 /* If there's no base, stop collapsing */
326 /* Stop the collapse new base when the would not be of the same
327 * type (i.e. different subclass).
329 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
339 /* Disallow circular references */
340 if ((PyObject *)arr == obj) {
342 PyErr_SetString(PyExc_ValueError,
343 "Cannot create a circular NumPy array 'base' dependency");
352 template<class MCData, class T>
353 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
355 if(!self->isAllocated())
357 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
358 throw INTERP_KERNEL::Exception(oss.str().c_str());
360 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
361 int nbComp=self->getNumberOfComponents();
364 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
365 throw INTERP_KERNEL::Exception(oss.str().c_str());
367 int nbDims=nbComp==1?1:2;
369 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
370 const T *bg=self->getConstPointer();
371 PyObject *ret=PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg));
372 if(mem.isDeallocatorCalled())
374 if(mem.getDeallocator()!=numarrdeal)
375 {// case for the first call of toNumPyArray
376 PyObject *ref=PyWeakref_NewRef(ret,NULL);
377 void **objs=new void *[2]; objs[0]=ref; objs[1]=(void*) mem.getDeallocator();
378 mem.setParameterForDeallocator(objs);
379 mem.setSpecificDeallocator(numarrdeal);
383 {// case for the second and other call of toNumPyArray
384 void **objs=(void **)mem.getParameterForDeallocator();
385 PyObject *weakRefOnOwner=(PyObject *)objs[0];
386 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
388 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
390 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
393 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
394 Py_XDECREF(weakRefOnOwner);
395 PyObject *ref=PyWeakref_NewRef(ret,NULL);
403 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
404 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
406 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
408 int nbRows((int)m.size());
409 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
410 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
411 indPtr->alloc(nbRows+1,1);
412 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
414 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
416 sz2+=(int)(*it0).size();
419 indices->alloc(sz2,1); data->alloc(sz2,1);
420 int *indices_ptr(indices->getPointer());
421 double *data_ptr(data->getPointer());
422 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
423 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
425 *indices_ptr=(*it1).first;
426 *data_ptr=(*it1).second;
428 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
430 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
431 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
432 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
433 PyObject *tmp1(PyString_FromString("shape"));
434 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
435 PyObject* pdict=PyDict_New();
436 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
437 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
439 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
440 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
442 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
443 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
444 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
450 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
458 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
459 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
460 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
461 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
463 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
467 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
475 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
476 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
477 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
478 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
479 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
480 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
481 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
482 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
484 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
488 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
490 PyObject *ret=PyList_New(size);
491 for(int i=0;i<size;i++)
492 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
496 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
499 PyObject *ret=PyList_New(size);
500 for(int i=0;i<size;i++)
501 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
505 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
508 PyObject *ret=PyList_New(size);
509 std::set<int>::const_iterator it=v.begin();
510 for(int i=0;i<size;i++,it++)
511 PyList_SetItem(ret,i,PyInt_FromLong(*it));
515 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
517 PyObject *ret=PyList_New(nbOfTuples);
518 for(int i=0;i<nbOfTuples;i++)
520 PyObject *t=PyTuple_New(nbOfComp);
521 for(int j=0;j<nbOfComp;j++)
522 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
523 PyList_SetItem(ret,i,t);
528 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
530 if(PyList_Check(pyLi))
532 *size=PyList_Size(pyLi);
533 int *tmp=new int[*size];
534 for(int i=0;i<*size;i++)
536 PyObject *o=PyList_GetItem(pyLi,i);
539 int val=(int)PyInt_AS_LONG(o);
545 throw INTERP_KERNEL::Exception("list must contain integers only");
550 else if(PyTuple_Check(pyLi))
552 *size=PyTuple_Size(pyLi);
553 int *tmp=new int[*size];
554 for(int i=0;i<*size;i++)
556 PyObject *o=PyTuple_GetItem(pyLi,i);
559 int val=(int)PyInt_AS_LONG(o);
565 throw INTERP_KERNEL::Exception("tuple must contain integers only");
572 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
576 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
578 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
579 if(PyList_Check(pyLi))
581 int size=PyList_Size(pyLi);
583 for(int i=0;i<size;i++)
585 PyObject *o=PyList_GetItem(pyLi,i);
588 int sz2=PyTuple_Size(o);
590 throw INTERP_KERNEL::Exception(msg);
591 PyObject *o_0=PyTuple_GetItem(o,0);
592 if(!PyInt_Check(o_0))
593 throw INTERP_KERNEL::Exception(msg);
594 PyObject *o_1=PyTuple_GetItem(o,1);
595 if(!PyInt_Check(o_1))
596 throw INTERP_KERNEL::Exception(msg);
597 arr[i].first=(int)PyInt_AS_LONG(o_0);
598 arr[i].second=(int)PyInt_AS_LONG(o_1);
601 throw INTERP_KERNEL::Exception(msg);
604 else if(PyTuple_Check(pyLi))
606 int size=PyTuple_Size(pyLi);
608 for(int i=0;i<size;i++)
610 PyObject *o=PyTuple_GetItem(pyLi,i);
613 int sz2=PyTuple_Size(o);
615 throw INTERP_KERNEL::Exception(msg);
616 PyObject *o_0=PyTuple_GetItem(o,0);
617 if(!PyInt_Check(o_0))
618 throw INTERP_KERNEL::Exception(msg);
619 PyObject *o_1=PyTuple_GetItem(o,1);
620 if(!PyInt_Check(o_1))
621 throw INTERP_KERNEL::Exception(msg);
622 arr[i].first=(int)PyInt_AS_LONG(o_0);
623 arr[i].second=(int)PyInt_AS_LONG(o_1);
626 throw INTERP_KERNEL::Exception(msg);
630 throw INTERP_KERNEL::Exception(msg);
633 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
635 if(PyList_Check(pyLi))
637 int size=PyList_Size(pyLi);
639 for(int i=0;i<size;i++)
641 PyObject *o=PyList_GetItem(pyLi,i);
644 int val=(int)PyInt_AS_LONG(o);
648 throw INTERP_KERNEL::Exception("list must contain integers only");
651 else if(PyTuple_Check(pyLi))
653 int size=PyTuple_Size(pyLi);
655 for(int i=0;i<size;i++)
657 PyObject *o=PyTuple_GetItem(pyLi,i);
660 int val=(int)PyInt_AS_LONG(o);
664 throw INTERP_KERNEL::Exception("tuple must contain integers only");
669 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
673 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
676 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
678 if(PyList_Check(pyLi))
680 int size=PyList_Size(pyLi);
681 for(int i=0;i<size;i++)
683 PyObject *o=PyList_GetItem(pyLi,i);
686 int val=(int)PyInt_AS_LONG(o);
691 std::vector<int> arr2;
692 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
693 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
695 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
696 throw INTERP_KERNEL::Exception(oss.str().c_str());
698 arr.insert(arr.end(),arr2.begin(),arr2.end());
702 else if(PyTuple_Check(pyLi))
704 int size=PyTuple_Size(pyLi);
705 for(int i=0;i<size;i++)
707 PyObject *o=PyTuple_GetItem(pyLi,i);
710 int val=(int)PyInt_AS_LONG(o);
715 std::vector<int> arr2;
716 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
717 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
719 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
720 throw INTERP_KERNEL::Exception(oss.str().c_str());
722 arr.insert(arr.end(),arr2.begin(),arr2.end());
727 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
730 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
734 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
735 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
737 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
738 oss << " whereas nb of components expected is " << nbOfComp << " !";
739 throw INTERP_KERNEL::Exception(oss.str().c_str());
746 if((nbOfTuples!=size1 || nbOfComp!=size2))
748 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
750 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
751 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
752 throw INTERP_KERNEL::Exception(oss.str().c_str());
758 if(nbOfTuples==size1)
762 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
763 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
764 throw INTERP_KERNEL::Exception(oss.str().c_str());
770 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
772 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
773 if(PyInt_Check(pyLi))
775 long val=PyInt_AS_LONG(pyLi);
780 throw INTERP_KERNEL::Exception(MSG);
783 else if(PyList_Check(pyLi))
785 int size=PyList_Size(pyLi);
787 for(int i=0;i<size;i++)
789 PyObject *o=PyList_GetItem(pyLi,i);
791 fillArrayWithPyListInt3(o,tmp1,ret);
799 throw INTERP_KERNEL::Exception(MSG);
802 else if(PyTuple_Check(pyLi))
804 int size=PyTuple_Size(pyLi);
806 for(int i=0;i<size;i++)
808 PyObject *o=PyTuple_GetItem(pyLi,i);
810 fillArrayWithPyListInt3(o,tmp1,ret);
818 throw INTERP_KERNEL::Exception(MSG);
822 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
825 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
827 std::vector<int> ret;
828 int size1=-1,size2=-1;
829 if(PyList_Check(pyLi))
831 size1=PyList_Size(pyLi);
832 for(int i=0;i<size1;i++)
834 PyObject *o=PyList_GetItem(pyLi,i);
835 fillArrayWithPyListInt3(o,size2,ret);
840 else if(PyTuple_Check(pyLi))
842 size1=PyTuple_Size(pyLi);
843 for(int i=0;i<size1;i++)
845 PyObject *o=PyTuple_GetItem(pyLi,i);
846 fillArrayWithPyListInt3(o,size2,ret);
852 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
854 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
858 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
860 if(PyList_Check(pyLi))
862 Py_ssize_t sz=PyList_Size(pyLi);
864 for(int i=0;i<sz;i++)
866 PyObject *o=PyList_GetItem(pyLi,i);
867 if(PyString_Check(o))
868 vec[i]=PyString_AsString(o);
874 else if(PyTuple_Check(pyLi))
876 Py_ssize_t sz=PyTuple_Size(pyLi);
878 for(int i=0;i<sz;i++)
880 PyObject *o=PyTuple_GetItem(pyLi,i);
881 if(PyString_Check(o))
882 vec[i]=PyString_AsString(o);
892 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
894 PyObject *ret=PyList_New(size);
895 for(int i=0;i<size;i++)
896 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
900 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
903 PyObject *ret=PyList_New(size);
904 for(int i=0;i<size;i++)
905 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
909 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
911 PyObject *ret=PyList_New(nbOfTuples);
912 for(int i=0;i<nbOfTuples;i++)
914 PyObject *t=PyTuple_New(nbOfComp);
915 for(int j=0;j<nbOfComp;j++)
916 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
917 PyList_SetItem(ret,i,t);
922 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
924 PyObject *ret=PyList_New(nbOfTuples);
925 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
926 for(int i=0;i<nbOfTuples;i++)
928 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
929 PyList_SetItem(ret,i,PyString_FromString(tmp));
934 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
936 if(PyList_Check(pyLi))
938 *size=PyList_Size(pyLi);
939 double *tmp=(double *)malloc((*size)*sizeof(double));
940 for(int i=0;i<*size;i++)
942 PyObject *o=PyList_GetItem(pyLi,i);
945 double val=PyFloat_AS_DOUBLE(o);
948 else if(PyInt_Check(o))
950 long val0=PyInt_AS_LONG(o);
957 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
962 else if(PyTuple_Check(pyLi))
964 *size=PyTuple_Size(pyLi);
965 double *tmp=(double *)malloc((*size)*sizeof(double));
966 for(int i=0;i<*size;i++)
968 PyObject *o=PyTuple_GetItem(pyLi,i);
971 double val=PyFloat_AS_DOUBLE(o);
974 else if(PyInt_Check(o))
976 long val0=PyInt_AS_LONG(o);
983 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
989 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
992 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
994 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
995 if(PyFloat_Check(pyLi))
1001 throw INTERP_KERNEL::Exception(MSG);
1002 double val=PyFloat_AS_DOUBLE(pyLi);
1005 else if(PyInt_Check(pyLi))
1007 long val0=PyInt_AS_LONG(pyLi);
1013 throw INTERP_KERNEL::Exception(MSG);
1016 else if(PyList_Check(pyLi))
1018 int size=PyList_Size(pyLi);
1020 for(int i=0;i<size;i++)
1022 PyObject *o=PyList_GetItem(pyLi,i);
1024 fillArrayWithPyListDbl3(o,tmp1,ret);
1032 throw INTERP_KERNEL::Exception(MSG);
1035 else if(PyTuple_Check(pyLi))
1037 int size=PyTuple_Size(pyLi);
1039 for(int i=0;i<size;i++)
1041 PyObject *o=PyTuple_GetItem(pyLi,i);
1043 fillArrayWithPyListDbl3(o,tmp1,ret);
1051 throw INTERP_KERNEL::Exception(MSG);
1055 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1058 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1060 std::vector<double> ret;
1061 int size1=-1,size2=-1;
1062 if(PyList_Check(pyLi))
1064 size1=PyList_Size(pyLi);
1065 for(int i=0;i<size1;i++)
1067 PyObject *o=PyList_GetItem(pyLi,i);
1068 fillArrayWithPyListDbl3(o,size2,ret);
1073 else if(PyTuple_Check(pyLi))
1075 size1=PyTuple_Size(pyLi);
1076 for(int i=0;i<size1;i++)
1078 PyObject *o=PyTuple_GetItem(pyLi,i);
1079 fillArrayWithPyListDbl3(o,size2,ret);
1085 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1087 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1091 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1093 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1096 if(PyList_Check(pyLi))
1098 int size=PyList_Size(pyLi);
1100 for(int i=0;i<size;i++)
1102 PyObject *obj=PyList_GetItem(pyLi,i);
1103 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1104 if(!SWIG_IsOK(status))
1106 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1107 throw INTERP_KERNEL::Exception(oss.str().c_str());
1109 T arg=reinterpret_cast< T >(argp);
1113 else if(PyTuple_Check(pyLi))
1115 int size=PyTuple_Size(pyLi);
1117 for(int i=0;i<size;i++)
1119 PyObject *obj=PyTuple_GetItem(pyLi,i);
1120 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1121 if(!SWIG_IsOK(status))
1123 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1124 throw INTERP_KERNEL::Exception(oss.str().c_str());
1126 T arg=reinterpret_cast< T >(argp);
1130 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1133 T arg=reinterpret_cast< T >(argp);
1137 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1141 * if python int -> cpp int sw=1
1142 * if python list[int] -> cpp vector<int> sw=2
1143 * if python tuple[int] -> cpp vector<int> sw=2
1144 * if python DataArrayInt -> cpp DataArrayInt sw=3
1145 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1147 * switch between (int,vector<int>,DataArrayInt)
1149 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1152 if(PyInt_Check(value))
1154 iTyypp=(int)PyInt_AS_LONG(value);
1158 if(PyTuple_Check(value))
1160 int size=PyTuple_Size(value);
1161 stdvecTyypp.resize(size);
1162 for(int i=0;i<size;i++)
1164 PyObject *o=PyTuple_GetItem(value,i);
1166 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1169 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1170 throw INTERP_KERNEL::Exception(oss.str().c_str());
1176 if(PyList_Check(value))
1178 int size=PyList_Size(value);
1179 stdvecTyypp.resize(size);
1180 for(int i=0;i<size;i++)
1182 PyObject *o=PyList_GetItem(value,i);
1184 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1187 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1188 throw INTERP_KERNEL::Exception(oss.str().c_str());
1195 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1196 if(SWIG_IsOK(status))
1198 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1202 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1203 if(SWIG_IsOK(status))
1205 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1209 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1213 * if python double -> cpp double sw=1
1214 * if python int -> cpp double sw=1
1215 * if python list[double] -> cpp vector<double> sw=2
1216 * if python list[int] -> cpp vector<double> sw=2
1217 * if python tuple[double] -> cpp vector<double> sw=2
1218 * if python tuple[int] -> cpp vector<double> sw=2
1219 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1221 * switch between (int,vector<int>,DataArrayInt)
1223 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1226 if(PyFloat_Check(value))
1228 iTyypp=PyFloat_AS_DOUBLE(value);
1232 if(PyInt_Check(value))
1234 iTyypp=(double)PyInt_AS_LONG(value);
1238 if(PyTuple_Check(value))
1240 int size=PyTuple_Size(value);
1241 stdvecTyypp.resize(size);
1242 for(int i=0;i<size;i++)
1244 PyObject *o=PyTuple_GetItem(value,i);
1245 if(PyFloat_Check(o))
1246 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1247 else if(PyInt_Check(o))
1248 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1251 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1252 throw INTERP_KERNEL::Exception(oss.str().c_str());
1258 if(PyList_Check(value))
1260 int size=PyList_Size(value);
1261 stdvecTyypp.resize(size);
1262 for(int i=0;i<size;i++)
1264 PyObject *o=PyList_GetItem(value,i);
1265 if(PyFloat_Check(o))
1266 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1267 else if(PyInt_Check(o))
1268 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1271 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1272 throw INTERP_KERNEL::Exception(oss.str().c_str());
1279 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1280 if(!SWIG_IsOK(status))
1281 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1282 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1287 * if python double -> cpp double sw=1
1288 * if python int -> cpp double sw=1
1289 * if python list[double] -> cpp vector<double> sw=2
1290 * if python list[int] -> cpp vector<double> sw=2
1291 * if python tuple[double] -> cpp vector<double> sw=2
1292 * if python tuple[int] -> cpp vector<double> sw=2
1293 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1295 * switch between (int,vector<int>,DataArrayInt)
1297 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1300 if(PyFloat_Check(value))
1302 iTyypp=PyFloat_AS_DOUBLE(value);
1306 if(PyInt_Check(value))
1308 iTyypp=(double)PyInt_AS_LONG(value);
1312 if(PyTuple_Check(value))
1314 int size=PyTuple_Size(value);
1315 stdvecTyypp.resize(size);
1316 for(int i=0;i<size;i++)
1318 PyObject *o=PyTuple_GetItem(value,i);
1319 if(PyFloat_Check(o))
1320 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1321 else if(PyInt_Check(o))
1322 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1325 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1326 throw INTERP_KERNEL::Exception(oss.str().c_str());
1332 if(PyList_Check(value))
1334 int size=PyList_Size(value);
1335 stdvecTyypp.resize(size);
1336 for(int i=0;i<size;i++)
1338 PyObject *o=PyList_GetItem(value,i);
1339 if(PyFloat_Check(o))
1340 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1341 else if(PyInt_Check(o))
1342 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1345 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1346 throw INTERP_KERNEL::Exception(oss.str().c_str());
1353 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1354 if(!SWIG_IsOK(status))
1355 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1356 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1361 * if python int -> cpp int sw=1
1362 * if python list[int] -> cpp vector<int> sw=2
1363 * if python tuple[int] -> cpp vector<int> sw=2
1364 * if python slicp -> cpp pair sw=3 (begin,end,step)
1365 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1367 * switch between (int,vector<int>,DataArrayInt)
1369 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)
1371 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1373 if(PyInt_Check(value))
1375 iTyypp=(int)PyInt_AS_LONG(value);
1379 if(PyTuple_Check(value))
1381 int size=PyTuple_Size(value);
1382 stdvecTyypp.resize(size);
1383 for(int i=0;i<size;i++)
1385 PyObject *o=PyTuple_GetItem(value,i);
1387 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1390 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1391 throw INTERP_KERNEL::Exception(oss.str().c_str());
1397 if(PyList_Check(value))
1399 int size=PyList_Size(value);
1400 stdvecTyypp.resize(size);
1401 for(int i=0;i<size;i++)
1403 PyObject *o=PyList_GetItem(value,i);
1405 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1408 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1409 throw INTERP_KERNEL::Exception(oss.str().c_str());
1415 if(PySlice_Check(value))
1417 Py_ssize_t strt=2,stp=2,step=2;
1418 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1419 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1420 if(nbelem!=0 || strt!=0 || stp!=0)
1422 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1423 throw INTERP_KERNEL::Exception(oss.str().c_str());
1427 p.second.second=step;
1432 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1433 if(SWIG_IsOK(status))
1435 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1438 std::ostringstream oss; oss << msg << " Instance in null !";
1439 throw INTERP_KERNEL::Exception(oss.str().c_str());
1444 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1445 if(SWIG_IsOK(status))
1447 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1450 std::ostringstream oss; oss << msg << " Instance in null !";
1451 throw INTERP_KERNEL::Exception(oss.str().c_str());
1453 stdvecTyypp.resize(tmp->getNumberOfCompo());
1454 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1458 throw INTERP_KERNEL::Exception(msg);
1462 * if python int -> cpp int sw=1
1463 * if python tuple[int] -> cpp vector<int> sw=2
1464 * if python list[int] -> cpp vector<int> sw=2
1465 * if python slice -> cpp pair sw=3
1466 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1468 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)
1471 if(PyInt_Check(value))
1473 iTyypp=(int)PyInt_AS_LONG(value);
1477 if(PyTuple_Check(value))
1479 int size=PyTuple_Size(value);
1480 stdvecTyypp.resize(size);
1481 for(int i=0;i<size;i++)
1483 PyObject *o=PyTuple_GetItem(value,i);
1485 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1488 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1489 throw INTERP_KERNEL::Exception(oss.str().c_str());
1495 if(PyList_Check(value))
1497 int size=PyList_Size(value);
1498 stdvecTyypp.resize(size);
1499 for(int i=0;i<size;i++)
1501 PyObject *o=PyList_GetItem(value,i);
1503 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1506 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1507 throw INTERP_KERNEL::Exception(oss.str().c_str());
1513 if(PySlice_Check(value))
1515 Py_ssize_t strt=2,stp=2,step=2;
1516 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1517 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1518 if(nbelem!=0 || strt!=0 || stp!=0)
1520 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1521 throw INTERP_KERNEL::Exception(oss.str().c_str());
1525 p.second.second=step;
1530 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1531 if(!SWIG_IsOK(status))
1532 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1533 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1538 * if python string with size one -> cpp char sw=1
1539 * if python string with size different from one -> cpp string sw=2
1540 * if python tuple[string] or list[string] -> vector<string> sw=3
1541 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1542 * switch between (int,string,vector<string>,DataArrayChar)
1544 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1546 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1548 if(PyString_Check(value))
1550 const char *pt=PyString_AsString(value);
1551 Py_ssize_t sz=PyString_Size(value);
1565 if(PyTuple_Check(value))
1567 int size=PyTuple_Size(value);
1568 vsType.resize(size);
1569 for(int i=0;i<size;i++)
1571 PyObject *o=PyTuple_GetItem(value,i);
1572 if(PyString_Check(o))
1573 vsType[i]=PyString_AsString(o);
1576 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1577 throw INTERP_KERNEL::Exception(oss.str().c_str());
1583 if(PyList_Check(value))
1585 int size=PyList_Size(value);
1586 vsType.resize(size);
1587 for(int i=0;i<size;i++)
1589 PyObject *o=PyList_GetItem(value,i);
1590 if(PyString_Check(o))
1591 vsType[i]=PyString_AsString(o);
1594 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1595 throw INTERP_KERNEL::Exception(oss.str().c_str());
1602 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1603 if(SWIG_IsOK(status))
1605 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1608 std::ostringstream oss; oss << msg << " Instance in null !";
1609 throw INTERP_KERNEL::Exception(oss.str().c_str());
1614 throw INTERP_KERNEL::Exception(msg);
1618 * if value int -> cpp it sw=1
1619 * if value list[int] -> vt sw=2
1620 * if value tuple[int] -> vt sw=2
1621 * if value slice -> pt sw=3
1622 * if value DataArrayInt -> dt sw=4
1623 * if value tuple [int,int] -> cpp it,ip sw=5
1624 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1625 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1626 * if value tuple [slice,int] -> cpp pt,ip sw=7
1627 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1628 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1629 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1630 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1631 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1632 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1633 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1634 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1635 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1636 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1637 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1638 * if value tuple [int,slice] -> cpp it,pc sw=13
1639 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1640 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1641 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1642 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1644 * switch between (int,vector<int>,DataArrayInt)
1646 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1647 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1648 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1650 if(!PyTuple_Check(value))
1652 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1657 int sz=PyTuple_Size(value);
1659 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1660 PyObject *ob0=PyTuple_GetItem(value,0);
1662 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1663 PyObject *ob1=PyTuple_GetItem(value,1);
1664 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1670 * if value int -> cpp val sw=1
1671 * if value double -> cpp val sw=1
1672 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1673 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1674 * if value list[int,double] -> cpp std::vector<double> sw=4
1675 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1677 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1680 if(PyFloat_Check(value))
1682 val=PyFloat_AS_DOUBLE(value);
1686 if(PyInt_Check(value))
1688 val=(double)PyInt_AS_LONG(value);
1692 if(PyTuple_Check(value))
1694 int size=PyTuple_Size(value);
1696 for(int i=0;i<size;i++)
1698 PyObject *o=PyTuple_GetItem(value,i);
1699 if(PyFloat_Check(o))
1700 f[i]=PyFloat_AS_DOUBLE(o);
1701 else if(PyInt_Check(o))
1702 f[i]=(double)PyInt_AS_LONG(o);
1705 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1706 throw INTERP_KERNEL::Exception(oss.str().c_str());
1712 if(PyList_Check(value))
1714 int size=PyList_Size(value);
1716 for(int i=0;i<size;i++)
1718 PyObject *o=PyList_GetItem(value,i);
1719 if(PyFloat_Check(o))
1720 f[i]=PyFloat_AS_DOUBLE(o);
1721 else if(PyInt_Check(o))
1722 f[i]=(double)PyInt_AS_LONG(o);
1725 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1726 throw INTERP_KERNEL::Exception(oss.str().c_str());
1733 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1734 if(SWIG_IsOK(status))
1736 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1740 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1741 if(SWIG_IsOK(status))
1743 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1747 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1751 * if value int -> cpp val sw=1
1752 * if value double -> cpp val sw=1
1753 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1754 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1755 * if value list[int,double] -> cpp std::vector<double> sw=4
1756 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1758 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1759 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1762 if(PyFloat_Check(value))
1764 val=PyFloat_AS_DOUBLE(value);
1766 if(nbTuplesExpected*nbCompExpected!=1)
1768 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1769 throw INTERP_KERNEL::Exception(oss.str().c_str());
1773 if(PyInt_Check(value))
1775 val=(double)PyInt_AS_LONG(value);
1777 if(nbTuplesExpected*nbCompExpected!=1)
1779 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1780 throw INTERP_KERNEL::Exception(oss.str().c_str());
1784 if(PyTuple_Check(value) || PyList_Check(value))
1788 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1789 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1794 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1797 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1798 if(SWIG_IsOK(status))
1800 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1804 if(d->getNumberOfTuples()==nbTuplesExpected)
1806 if(d->getNumberOfComponents()==nbCompExpected)
1808 return d->getConstPointer();
1812 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1813 throw INTERP_KERNEL::Exception(oss.str().c_str());
1818 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1819 throw INTERP_KERNEL::Exception(oss.str().c_str());
1826 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1827 throw INTERP_KERNEL::Exception(oss.str().c_str());
1833 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1834 if(SWIG_IsOK(status))
1836 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1838 if(e->getNumberOfCompo()==nbCompExpected)
1840 if(nbTuplesExpected==1)
1841 return e->getConstPointer();
1844 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1845 throw INTERP_KERNEL::Exception(oss.str().c_str());
1850 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1851 throw INTERP_KERNEL::Exception(oss.str().c_str());
1854 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1858 * if value int -> cpp val sw=1
1859 * if value double -> cpp val sw=1
1860 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1861 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1862 * if value list[int,double] -> cpp std::vector<double> sw=4
1863 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1865 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1866 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1869 if(PyFloat_Check(value))
1871 val=PyFloat_AS_DOUBLE(value);
1873 if(nbCompExpected!=1)
1875 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1876 throw INTERP_KERNEL::Exception(oss.str().c_str());
1881 if(PyInt_Check(value))
1883 val=(double)PyInt_AS_LONG(value);
1885 if(nbCompExpected!=1)
1887 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1888 throw INTERP_KERNEL::Exception(oss.str().c_str());
1893 if(PyTuple_Check(value))
1895 int size=PyTuple_Size(value);
1897 for(int i=0;i<size;i++)
1899 PyObject *o=PyTuple_GetItem(value,i);
1900 if(PyFloat_Check(o))
1901 f[i]=PyFloat_AS_DOUBLE(o);
1902 else if(PyInt_Check(o))
1903 f[i]=(double)PyInt_AS_LONG(o);
1906 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1907 throw INTERP_KERNEL::Exception(oss.str().c_str());
1911 if(size%nbCompExpected!=0)
1913 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1914 throw INTERP_KERNEL::Exception(oss.str().c_str());
1916 nbTuples=size/nbCompExpected;
1919 if(PyList_Check(value))
1921 int size=PyList_Size(value);
1923 for(int i=0;i<size;i++)
1925 PyObject *o=PyList_GetItem(value,i);
1926 if(PyFloat_Check(o))
1927 f[i]=PyFloat_AS_DOUBLE(o);
1928 else if(PyInt_Check(o))
1929 f[i]=(double)PyInt_AS_LONG(o);
1932 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1933 throw INTERP_KERNEL::Exception(oss.str().c_str());
1937 if(size%nbCompExpected!=0)
1939 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1940 throw INTERP_KERNEL::Exception(oss.str().c_str());
1942 nbTuples=size/nbCompExpected;
1946 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1947 if(SWIG_IsOK(status))
1949 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1953 if(d->getNumberOfComponents()==nbCompExpected)
1955 nbTuples=d->getNumberOfTuples();
1956 return d->getConstPointer();
1960 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1961 throw INTERP_KERNEL::Exception(oss.str().c_str());
1968 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1969 throw INTERP_KERNEL::Exception(oss.str().c_str());
1972 { nbTuples=0; return 0; }
1975 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1976 if(SWIG_IsOK(status))
1978 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1982 if(e->getNumberOfCompo()==nbCompExpected)
1985 return e->getConstPointer();
1989 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1990 throw INTERP_KERNEL::Exception(oss.str().c_str());
1997 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1998 throw INTERP_KERNEL::Exception(oss.str().c_str());
2001 { nbTuples=0; return 0; }
2004 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2008 * if value int -> cpp val sw=1
2009 * if value double -> cpp val sw=1
2010 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2011 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2012 * if value list[int,double] -> cpp std::vector<double> sw=4
2013 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2015 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2016 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2018 ParaMEDMEM::DataArrayDouble *d=0;
2019 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2021 if(PyFloat_Check(value))
2023 val=PyFloat_AS_DOUBLE(value);
2028 if(PyInt_Check(value))
2030 val=(double)PyInt_AS_LONG(value);
2035 if(PyTuple_Check(value))
2037 int size=PyTuple_Size(value);
2039 for(int i=0;i<size;i++)
2041 PyObject *o=PyTuple_GetItem(value,i);
2042 if(PyFloat_Check(o))
2043 f[i]=PyFloat_AS_DOUBLE(o);
2044 else if(PyInt_Check(o))
2045 f[i]=(double)PyInt_AS_LONG(o);
2048 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2049 throw INTERP_KERNEL::Exception(oss.str().c_str());
2056 if(PyList_Check(value))
2058 int size=PyList_Size(value);
2060 for(int i=0;i<size;i++)
2062 PyObject *o=PyList_GetItem(value,i);
2063 if(PyFloat_Check(o))
2064 f[i]=PyFloat_AS_DOUBLE(o);
2065 else if(PyInt_Check(o))
2066 f[i]=(double)PyInt_AS_LONG(o);
2069 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2070 throw INTERP_KERNEL::Exception(oss.str().c_str());
2078 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2079 if(SWIG_IsOK(status))
2081 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2085 if(d->getNumberOfComponents()==1)
2087 nbTuples=d->getNumberOfTuples();
2088 return d->getConstPointer();
2092 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2093 throw INTERP_KERNEL::Exception(oss.str().c_str());
2100 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2101 throw INTERP_KERNEL::Exception(oss.str().c_str());
2104 { nbTuples=0; return 0; }
2107 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2108 if(SWIG_IsOK(status))
2110 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2114 nbTuples=e->getNumberOfCompo();
2115 return e->getConstPointer();
2121 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2122 throw INTERP_KERNEL::Exception(oss.str().c_str());
2125 { nbTuples=0; return 0; }
2128 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2132 * if python int -> cpp int sw=1
2133 * if python list[int] -> cpp vector<int> sw=2
2134 * if python tuple[int] -> cpp vector<int> sw=2
2135 * if python DataArrayInt -> cpp DataArrayInt sw=3
2136 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2138 * switch between (int,vector<int>,DataArrayInt)
2140 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2143 if(PyInt_Check(value))
2145 iTyypp=(int)PyInt_AS_LONG(value);
2149 if(PyTuple_Check(value))
2151 int size=PyTuple_Size(value);
2152 stdvecTyypp.resize(size);
2153 for(int i=0;i<size;i++)
2155 PyObject *o=PyTuple_GetItem(value,i);
2157 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2160 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2161 throw INTERP_KERNEL::Exception(oss.str().c_str());
2165 return &stdvecTyypp[0];
2167 if(PyList_Check(value))
2169 int size=PyList_Size(value);
2170 stdvecTyypp.resize(size);
2171 for(int i=0;i<size;i++)
2173 PyObject *o=PyList_GetItem(value,i);
2175 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2178 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2179 throw INTERP_KERNEL::Exception(oss.str().c_str());
2183 return &stdvecTyypp[0];
2186 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2187 if(SWIG_IsOK(status))
2189 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2192 sw=3; sz=daIntTyypp->getNbOfElems();
2193 return daIntTyypp->begin();
2201 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2202 if(SWIG_IsOK(status))
2204 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2205 sw=4; sz=daIntTuple->getNumberOfCompo();
2206 return daIntTuple->getConstPointer();
2208 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2211 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2214 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2215 if(!SWIG_IsOK(status))
2217 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2218 if(!SWIG_IsOK(status))
2220 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2221 if(!SWIG_IsOK(status))
2223 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2224 if(!SWIG_IsOK(status))
2226 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2227 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2228 throw INTERP_KERNEL::Exception(oss.str().c_str());
2233 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);