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 *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
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();
410 int nbComp=self->getNumberOfComponents();
413 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
414 throw INTERP_KERNEL::Exception(oss.str().c_str());
416 int nbDims=nbComp==1?1:2;
418 dim[0]=(npy_intp)self->getNumberOfTuples(); dim[1]=nbComp;
419 const T *bg=self->getConstPointer();
420 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
421 if(mem.isDeallocatorCalled())
423 if(mem.getDeallocator()!=numarrdeal)
424 {// case for the first call of toNumPyArray
425 PyObject *ref(PyWeakref_NewRef(ret,NULL));
426 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
427 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
428 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
429 mem.setParameterForDeallocator(objs);
430 mem.setSpecificDeallocator(numarrdeal);
434 {// case for the second and other call of toNumPyArray
435 void **objs=(void **)mem.getParameterForDeallocator();
436 PyObject *weakRefOnOwner=(PyObject *)objs[0];
437 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
439 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
441 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
444 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
445 Py_XDECREF(weakRefOnOwner);
446 PyObject *ref=PyWeakref_NewRef(ret,NULL);
454 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
455 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
457 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
459 int nbRows((int)m.size());
460 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
461 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
462 indPtr->alloc(nbRows+1,1);
463 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
465 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
467 sz2+=(int)(*it0).size();
470 indices->alloc(sz2,1); data->alloc(sz2,1);
471 int *indices_ptr(indices->getPointer());
472 double *data_ptr(data->getPointer());
473 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
474 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
476 *indices_ptr=(*it1).first;
477 *data_ptr=(*it1).second;
479 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
481 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
482 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
483 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
484 PyObject *tmp1(PyString_FromString("shape"));
485 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
486 PyObject* pdict=PyDict_New();
487 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
488 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
490 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
491 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
493 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
494 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
495 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
501 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
509 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
510 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
511 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
512 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
514 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
518 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
526 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
527 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
528 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
529 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
530 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
531 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
532 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
533 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
535 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
539 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
541 PyObject *ret=PyList_New(size);
542 for(int i=0;i<size;i++)
543 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
547 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
550 PyObject *ret=PyList_New(size);
551 for(int i=0;i<size;i++)
552 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
556 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
559 PyObject *ret=PyList_New(size);
560 std::set<int>::const_iterator it=v.begin();
561 for(int i=0;i<size;i++,it++)
562 PyList_SetItem(ret,i,PyInt_FromLong(*it));
566 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
568 PyObject *ret=PyList_New(nbOfTuples);
569 for(int i=0;i<nbOfTuples;i++)
571 PyObject *t=PyTuple_New(nbOfComp);
572 for(int j=0;j<nbOfComp;j++)
573 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
574 PyList_SetItem(ret,i,t);
579 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
581 if(PyList_Check(pyLi))
583 *size=PyList_Size(pyLi);
584 int *tmp=new int[*size];
585 for(int i=0;i<*size;i++)
587 PyObject *o=PyList_GetItem(pyLi,i);
590 int val=(int)PyInt_AS_LONG(o);
596 throw INTERP_KERNEL::Exception("list must contain integers only");
601 else if(PyTuple_Check(pyLi))
603 *size=PyTuple_Size(pyLi);
604 int *tmp=new int[*size];
605 for(int i=0;i<*size;i++)
607 PyObject *o=PyTuple_GetItem(pyLi,i);
610 int val=(int)PyInt_AS_LONG(o);
616 throw INTERP_KERNEL::Exception("tuple must contain integers only");
623 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
627 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
629 PyObject *ret=PyList_New(arr.size());
630 for(std::size_t i=0;i<arr.size();i++)
632 PyObject *t=PyTuple_New(2);
633 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
634 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
635 PyList_SetItem(ret,i,t);
640 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
642 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
643 if(PyList_Check(pyLi))
645 int size=PyList_Size(pyLi);
647 for(int i=0;i<size;i++)
649 PyObject *o=PyList_GetItem(pyLi,i);
652 int sz2=PyTuple_Size(o);
654 throw INTERP_KERNEL::Exception(msg);
655 PyObject *o_0=PyTuple_GetItem(o,0);
656 if(!PyInt_Check(o_0))
657 throw INTERP_KERNEL::Exception(msg);
658 PyObject *o_1=PyTuple_GetItem(o,1);
659 if(!PyInt_Check(o_1))
660 throw INTERP_KERNEL::Exception(msg);
661 arr[i].first=(int)PyInt_AS_LONG(o_0);
662 arr[i].second=(int)PyInt_AS_LONG(o_1);
665 throw INTERP_KERNEL::Exception(msg);
668 else if(PyTuple_Check(pyLi))
670 int size=PyTuple_Size(pyLi);
672 for(int i=0;i<size;i++)
674 PyObject *o=PyTuple_GetItem(pyLi,i);
677 int sz2=PyTuple_Size(o);
679 throw INTERP_KERNEL::Exception(msg);
680 PyObject *o_0=PyTuple_GetItem(o,0);
681 if(!PyInt_Check(o_0))
682 throw INTERP_KERNEL::Exception(msg);
683 PyObject *o_1=PyTuple_GetItem(o,1);
684 if(!PyInt_Check(o_1))
685 throw INTERP_KERNEL::Exception(msg);
686 arr[i].first=(int)PyInt_AS_LONG(o_0);
687 arr[i].second=(int)PyInt_AS_LONG(o_1);
690 throw INTERP_KERNEL::Exception(msg);
694 throw INTERP_KERNEL::Exception(msg);
697 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
699 if(PyList_Check(pyLi))
701 int size=PyList_Size(pyLi);
703 for(int i=0;i<size;i++)
705 PyObject *o=PyList_GetItem(pyLi,i);
708 int val=(int)PyInt_AS_LONG(o);
712 throw INTERP_KERNEL::Exception("list must contain integers only");
715 else if(PyTuple_Check(pyLi))
717 int size=PyTuple_Size(pyLi);
719 for(int i=0;i<size;i++)
721 PyObject *o=PyTuple_GetItem(pyLi,i);
724 int val=(int)PyInt_AS_LONG(o);
728 throw INTERP_KERNEL::Exception("tuple must contain integers only");
733 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
737 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
740 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
742 if(PyList_Check(pyLi))
744 int size=PyList_Size(pyLi);
745 for(int i=0;i<size;i++)
747 PyObject *o=PyList_GetItem(pyLi,i);
750 int val=(int)PyInt_AS_LONG(o);
755 std::vector<int> arr2;
756 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
757 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
759 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
760 throw INTERP_KERNEL::Exception(oss.str().c_str());
762 arr.insert(arr.end(),arr2.begin(),arr2.end());
766 else if(PyTuple_Check(pyLi))
768 int size=PyTuple_Size(pyLi);
769 for(int i=0;i<size;i++)
771 PyObject *o=PyTuple_GetItem(pyLi,i);
774 int val=(int)PyInt_AS_LONG(o);
779 std::vector<int> arr2;
780 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
781 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
783 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
784 throw INTERP_KERNEL::Exception(oss.str().c_str());
786 arr.insert(arr.end(),arr2.begin(),arr2.end());
791 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
794 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
798 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
799 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
801 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
802 oss << " whereas nb of components expected is " << nbOfComp << " !";
803 throw INTERP_KERNEL::Exception(oss.str().c_str());
810 if((nbOfTuples!=size1 || nbOfComp!=size2))
812 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
814 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
815 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
816 throw INTERP_KERNEL::Exception(oss.str().c_str());
822 if(nbOfTuples==size1)
826 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
827 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
828 throw INTERP_KERNEL::Exception(oss.str().c_str());
834 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
836 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
837 if(PyInt_Check(pyLi))
839 long val=PyInt_AS_LONG(pyLi);
844 throw INTERP_KERNEL::Exception(MSG);
847 else if(PyList_Check(pyLi))
849 int size=PyList_Size(pyLi);
851 for(int i=0;i<size;i++)
853 PyObject *o=PyList_GetItem(pyLi,i);
855 fillArrayWithPyListInt3(o,tmp1,ret);
863 throw INTERP_KERNEL::Exception(MSG);
866 else if(PyTuple_Check(pyLi))
868 int size=PyTuple_Size(pyLi);
870 for(int i=0;i<size;i++)
872 PyObject *o=PyTuple_GetItem(pyLi,i);
874 fillArrayWithPyListInt3(o,tmp1,ret);
882 throw INTERP_KERNEL::Exception(MSG);
886 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
889 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
891 std::vector<int> ret;
892 int size1=-1,size2=-1;
893 if(PyList_Check(pyLi))
895 size1=PyList_Size(pyLi);
896 for(int i=0;i<size1;i++)
898 PyObject *o=PyList_GetItem(pyLi,i);
899 fillArrayWithPyListInt3(o,size2,ret);
904 else if(PyTuple_Check(pyLi))
906 size1=PyTuple_Size(pyLi);
907 for(int i=0;i<size1;i++)
909 PyObject *o=PyTuple_GetItem(pyLi,i);
910 fillArrayWithPyListInt3(o,size2,ret);
916 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
918 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
922 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
924 if(PyList_Check(pyLi))
926 Py_ssize_t sz=PyList_Size(pyLi);
928 for(int i=0;i<sz;i++)
930 PyObject *o=PyList_GetItem(pyLi,i);
931 if(PyString_Check(o))
932 vec[i]=PyString_AsString(o);
938 else if(PyTuple_Check(pyLi))
940 Py_ssize_t sz=PyTuple_Size(pyLi);
942 for(int i=0;i<sz;i++)
944 PyObject *o=PyTuple_GetItem(pyLi,i);
945 if(PyString_Check(o))
946 vec[i]=PyString_AsString(o);
956 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
958 PyObject *ret=PyList_New(size);
959 for(int i=0;i<size;i++)
960 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
964 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
967 PyObject *ret=PyList_New(size);
968 for(int i=0;i<size;i++)
969 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
973 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
975 PyObject *ret=PyList_New(nbOfTuples);
976 for(int i=0;i<nbOfTuples;i++)
978 PyObject *t=PyTuple_New(nbOfComp);
979 for(int j=0;j<nbOfComp;j++)
980 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
981 PyList_SetItem(ret,i,t);
986 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
988 PyObject *ret=PyList_New(nbOfTuples);
989 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
990 for(int i=0;i<nbOfTuples;i++)
992 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
993 PyList_SetItem(ret,i,PyString_FromString(tmp));
998 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1000 if(PyList_Check(pyLi))
1002 *size=PyList_Size(pyLi);
1003 double *tmp=(double *)malloc((*size)*sizeof(double));
1004 for(int i=0;i<*size;i++)
1006 PyObject *o=PyList_GetItem(pyLi,i);
1007 if(PyFloat_Check(o))
1009 double val=PyFloat_AS_DOUBLE(o);
1012 else if(PyInt_Check(o))
1014 long val0=PyInt_AS_LONG(o);
1021 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1026 else if(PyTuple_Check(pyLi))
1028 *size=PyTuple_Size(pyLi);
1029 double *tmp=(double *)malloc((*size)*sizeof(double));
1030 for(int i=0;i<*size;i++)
1032 PyObject *o=PyTuple_GetItem(pyLi,i);
1033 if(PyFloat_Check(o))
1035 double val=PyFloat_AS_DOUBLE(o);
1038 else if(PyInt_Check(o))
1040 long val0=PyInt_AS_LONG(o);
1047 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1053 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1056 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1058 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1059 if(PyFloat_Check(pyLi))
1065 throw INTERP_KERNEL::Exception(MSG);
1066 double val=PyFloat_AS_DOUBLE(pyLi);
1069 else if(PyInt_Check(pyLi))
1071 long val0=PyInt_AS_LONG(pyLi);
1077 throw INTERP_KERNEL::Exception(MSG);
1080 else if(PyList_Check(pyLi))
1082 int size=PyList_Size(pyLi);
1084 for(int i=0;i<size;i++)
1086 PyObject *o=PyList_GetItem(pyLi,i);
1088 fillArrayWithPyListDbl3(o,tmp1,ret);
1096 throw INTERP_KERNEL::Exception(MSG);
1099 else if(PyTuple_Check(pyLi))
1101 int size=PyTuple_Size(pyLi);
1103 for(int i=0;i<size;i++)
1105 PyObject *o=PyTuple_GetItem(pyLi,i);
1107 fillArrayWithPyListDbl3(o,tmp1,ret);
1115 throw INTERP_KERNEL::Exception(MSG);
1119 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1122 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1124 std::vector<double> ret;
1125 int size1=-1,size2=-1;
1126 if(PyList_Check(pyLi))
1128 size1=PyList_Size(pyLi);
1129 for(int i=0;i<size1;i++)
1131 PyObject *o=PyList_GetItem(pyLi,i);
1132 fillArrayWithPyListDbl3(o,size2,ret);
1137 else if(PyTuple_Check(pyLi))
1139 size1=PyTuple_Size(pyLi);
1140 for(int i=0;i<size1;i++)
1142 PyObject *o=PyTuple_GetItem(pyLi,i);
1143 fillArrayWithPyListDbl3(o,size2,ret);
1149 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1151 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1155 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1157 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1160 if(PyList_Check(pyLi))
1162 int size=PyList_Size(pyLi);
1164 for(int i=0;i<size;i++)
1166 PyObject *obj=PyList_GetItem(pyLi,i);
1167 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1168 if(!SWIG_IsOK(status))
1170 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1171 throw INTERP_KERNEL::Exception(oss.str().c_str());
1173 T arg=reinterpret_cast< T >(argp);
1177 else if(PyTuple_Check(pyLi))
1179 int size=PyTuple_Size(pyLi);
1181 for(int i=0;i<size;i++)
1183 PyObject *obj=PyTuple_GetItem(pyLi,i);
1184 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1185 if(!SWIG_IsOK(status))
1187 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1188 throw INTERP_KERNEL::Exception(oss.str().c_str());
1190 T arg=reinterpret_cast< T >(argp);
1194 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1197 T arg=reinterpret_cast< T >(argp);
1201 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1205 * if python int -> cpp int sw=1
1206 * if python list[int] -> cpp vector<int> sw=2
1207 * if python tuple[int] -> cpp vector<int> sw=2
1208 * if python DataArrayInt -> cpp DataArrayInt sw=3
1209 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1211 * switch between (int,vector<int>,DataArrayInt)
1213 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1216 if(PyInt_Check(value))
1218 iTyypp=(int)PyInt_AS_LONG(value);
1222 if(PyTuple_Check(value))
1224 int size=PyTuple_Size(value);
1225 stdvecTyypp.resize(size);
1226 for(int i=0;i<size;i++)
1228 PyObject *o=PyTuple_GetItem(value,i);
1230 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1233 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1234 throw INTERP_KERNEL::Exception(oss.str().c_str());
1240 if(PyList_Check(value))
1242 int size=PyList_Size(value);
1243 stdvecTyypp.resize(size);
1244 for(int i=0;i<size;i++)
1246 PyObject *o=PyList_GetItem(value,i);
1248 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1251 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1252 throw INTERP_KERNEL::Exception(oss.str().c_str());
1259 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1260 if(SWIG_IsOK(status))
1262 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1266 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1267 if(SWIG_IsOK(status))
1269 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1273 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1277 * if python double -> cpp double sw=1
1278 * if python int -> cpp double sw=1
1279 * if python list[double] -> cpp vector<double> sw=2
1280 * if python list[int] -> cpp vector<double> sw=2
1281 * if python tuple[double] -> cpp vector<double> sw=2
1282 * if python tuple[int] -> cpp vector<double> sw=2
1283 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1285 * switch between (int,vector<int>,DataArrayInt)
1287 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1290 if(PyFloat_Check(value))
1292 iTyypp=PyFloat_AS_DOUBLE(value);
1296 if(PyInt_Check(value))
1298 iTyypp=(double)PyInt_AS_LONG(value);
1302 if(PyTuple_Check(value))
1304 int size=PyTuple_Size(value);
1305 stdvecTyypp.resize(size);
1306 for(int i=0;i<size;i++)
1308 PyObject *o=PyTuple_GetItem(value,i);
1309 if(PyFloat_Check(o))
1310 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1311 else if(PyInt_Check(o))
1312 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1315 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1316 throw INTERP_KERNEL::Exception(oss.str().c_str());
1322 if(PyList_Check(value))
1324 int size=PyList_Size(value);
1325 stdvecTyypp.resize(size);
1326 for(int i=0;i<size;i++)
1328 PyObject *o=PyList_GetItem(value,i);
1329 if(PyFloat_Check(o))
1330 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1331 else if(PyInt_Check(o))
1332 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1335 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1336 throw INTERP_KERNEL::Exception(oss.str().c_str());
1343 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1344 if(!SWIG_IsOK(status))
1345 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1346 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1351 * if python double -> cpp double sw=1
1352 * if python int -> cpp double sw=1
1353 * if python list[double] -> cpp vector<double> sw=2
1354 * if python list[int] -> cpp vector<double> sw=2
1355 * if python tuple[double] -> cpp vector<double> sw=2
1356 * if python tuple[int] -> cpp vector<double> sw=2
1357 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1359 * switch between (int,vector<int>,DataArrayInt)
1361 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1364 if(PyFloat_Check(value))
1366 iTyypp=PyFloat_AS_DOUBLE(value);
1370 if(PyInt_Check(value))
1372 iTyypp=(double)PyInt_AS_LONG(value);
1376 if(PyTuple_Check(value))
1378 int size=PyTuple_Size(value);
1379 stdvecTyypp.resize(size);
1380 for(int i=0;i<size;i++)
1382 PyObject *o=PyTuple_GetItem(value,i);
1383 if(PyFloat_Check(o))
1384 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1385 else if(PyInt_Check(o))
1386 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1389 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1390 throw INTERP_KERNEL::Exception(oss.str().c_str());
1396 if(PyList_Check(value))
1398 int size=PyList_Size(value);
1399 stdvecTyypp.resize(size);
1400 for(int i=0;i<size;i++)
1402 PyObject *o=PyList_GetItem(value,i);
1403 if(PyFloat_Check(o))
1404 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1405 else if(PyInt_Check(o))
1406 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1409 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1410 throw INTERP_KERNEL::Exception(oss.str().c_str());
1417 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1418 if(!SWIG_IsOK(status))
1419 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1420 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1425 * if python int -> cpp int sw=1
1426 * if python list[int] -> cpp vector<int> sw=2
1427 * if python tuple[int] -> cpp vector<int> sw=2
1428 * if python slicp -> cpp pair sw=3 (begin,end,step)
1429 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1431 * switch between (int,vector<int>,DataArrayInt)
1433 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)
1435 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1437 if(PyInt_Check(value))
1439 iTyypp=(int)PyInt_AS_LONG(value);
1443 if(PyTuple_Check(value))
1445 int size=PyTuple_Size(value);
1446 stdvecTyypp.resize(size);
1447 for(int i=0;i<size;i++)
1449 PyObject *o=PyTuple_GetItem(value,i);
1451 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1454 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1455 throw INTERP_KERNEL::Exception(oss.str().c_str());
1461 if(PyList_Check(value))
1463 int size=PyList_Size(value);
1464 stdvecTyypp.resize(size);
1465 for(int i=0;i<size;i++)
1467 PyObject *o=PyList_GetItem(value,i);
1469 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1472 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1473 throw INTERP_KERNEL::Exception(oss.str().c_str());
1479 if(PySlice_Check(value))
1481 Py_ssize_t strt=2,stp=2,step=2;
1482 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1483 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1486 p.second.second=step;
1491 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1492 if(SWIG_IsOK(status))
1494 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1497 std::ostringstream oss; oss << msg << " Instance in null !";
1498 throw INTERP_KERNEL::Exception(oss.str().c_str());
1503 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1504 if(SWIG_IsOK(status))
1506 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1509 std::ostringstream oss; oss << msg << " Instance in null !";
1510 throw INTERP_KERNEL::Exception(oss.str().c_str());
1512 stdvecTyypp.resize(tmp->getNumberOfCompo());
1513 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1517 throw INTERP_KERNEL::Exception(msg);
1521 * Idem than convertObjToPossibleCpp2
1523 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)
1525 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1528 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1533 * if python int -> cpp int sw=1
1534 * if python tuple[int] -> cpp vector<int> sw=2
1535 * if python list[int] -> cpp vector<int> sw=2
1536 * if python slice -> cpp pair sw=3
1537 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1539 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)
1542 if(PyInt_Check(value))
1544 iTyypp=(int)PyInt_AS_LONG(value);
1548 if(PyTuple_Check(value))
1550 int size=PyTuple_Size(value);
1551 stdvecTyypp.resize(size);
1552 for(int i=0;i<size;i++)
1554 PyObject *o=PyTuple_GetItem(value,i);
1556 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1559 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1560 throw INTERP_KERNEL::Exception(oss.str().c_str());
1566 if(PyList_Check(value))
1568 int size=PyList_Size(value);
1569 stdvecTyypp.resize(size);
1570 for(int i=0;i<size;i++)
1572 PyObject *o=PyList_GetItem(value,i);
1574 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1577 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1578 throw INTERP_KERNEL::Exception(oss.str().c_str());
1584 if(PySlice_Check(value))
1586 Py_ssize_t strt=2,stp=2,step=2;
1587 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1588 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1591 p.second.second=step;
1596 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1597 if(!SWIG_IsOK(status))
1598 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1599 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1604 * if python string with size one -> cpp char sw=1
1605 * if python string with size different from one -> cpp string sw=2
1606 * if python tuple[string] or list[string] -> vector<string> sw=3
1607 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1608 * switch between (int,string,vector<string>,DataArrayChar)
1610 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1612 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1614 if(PyString_Check(value))
1616 const char *pt=PyString_AsString(value);
1617 Py_ssize_t sz=PyString_Size(value);
1631 if(PyTuple_Check(value))
1633 int size=PyTuple_Size(value);
1634 vsType.resize(size);
1635 for(int i=0;i<size;i++)
1637 PyObject *o=PyTuple_GetItem(value,i);
1638 if(PyString_Check(o))
1639 vsType[i]=PyString_AsString(o);
1642 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1643 throw INTERP_KERNEL::Exception(oss.str().c_str());
1649 if(PyList_Check(value))
1651 int size=PyList_Size(value);
1652 vsType.resize(size);
1653 for(int i=0;i<size;i++)
1655 PyObject *o=PyList_GetItem(value,i);
1656 if(PyString_Check(o))
1657 vsType[i]=PyString_AsString(o);
1660 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1661 throw INTERP_KERNEL::Exception(oss.str().c_str());
1668 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1669 if(SWIG_IsOK(status))
1671 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1674 std::ostringstream oss; oss << msg << " Instance in null !";
1675 throw INTERP_KERNEL::Exception(oss.str().c_str());
1680 throw INTERP_KERNEL::Exception(msg);
1684 * if value int -> cpp it sw=1
1685 * if value list[int] -> vt sw=2
1686 * if value tuple[int] -> vt sw=2
1687 * if value slice -> pt sw=3
1688 * if value DataArrayInt -> dt sw=4
1689 * if value tuple [int,int] -> cpp it,ip sw=5
1690 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1691 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1692 * if value tuple [slice,int] -> cpp pt,ip sw=7
1693 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1694 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1695 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1696 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1697 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1698 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1699 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1700 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1701 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1702 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1703 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1704 * if value tuple [int,slice] -> cpp it,pc sw=13
1705 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1706 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1707 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1708 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1710 * switch between (int,vector<int>,DataArrayInt)
1712 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1713 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1714 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1716 if(!PyTuple_Check(value))
1718 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1723 int sz=PyTuple_Size(value);
1725 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1726 PyObject *ob0=PyTuple_GetItem(value,0);
1728 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1729 PyObject *ob1=PyTuple_GetItem(value,1);
1730 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1736 * if value int -> cpp val sw=1
1737 * if value double -> cpp val sw=1
1738 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1739 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1740 * if value list[int,double] -> cpp std::vector<double> sw=4
1741 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1743 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1746 if(PyFloat_Check(value))
1748 val=PyFloat_AS_DOUBLE(value);
1752 if(PyInt_Check(value))
1754 val=(double)PyInt_AS_LONG(value);
1758 if(PyTuple_Check(value))
1760 int size=PyTuple_Size(value);
1762 for(int i=0;i<size;i++)
1764 PyObject *o=PyTuple_GetItem(value,i);
1765 if(PyFloat_Check(o))
1766 f[i]=PyFloat_AS_DOUBLE(o);
1767 else if(PyInt_Check(o))
1768 f[i]=(double)PyInt_AS_LONG(o);
1771 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1772 throw INTERP_KERNEL::Exception(oss.str().c_str());
1778 if(PyList_Check(value))
1780 int size=PyList_Size(value);
1782 for(int i=0;i<size;i++)
1784 PyObject *o=PyList_GetItem(value,i);
1785 if(PyFloat_Check(o))
1786 f[i]=PyFloat_AS_DOUBLE(o);
1787 else if(PyInt_Check(o))
1788 f[i]=(double)PyInt_AS_LONG(o);
1791 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1792 throw INTERP_KERNEL::Exception(oss.str().c_str());
1799 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1800 if(SWIG_IsOK(status))
1802 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1806 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1807 if(SWIG_IsOK(status))
1809 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1813 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1817 * if value int -> cpp val sw=1
1818 * if value double -> cpp val sw=1
1819 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1820 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1821 * if value list[int,double] -> cpp std::vector<double> sw=4
1822 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1824 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1825 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1828 if(PyFloat_Check(value))
1830 val=PyFloat_AS_DOUBLE(value);
1832 if(nbTuplesExpected*nbCompExpected!=1)
1834 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1835 throw INTERP_KERNEL::Exception(oss.str().c_str());
1839 if(PyInt_Check(value))
1841 val=(double)PyInt_AS_LONG(value);
1843 if(nbTuplesExpected*nbCompExpected!=1)
1845 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1846 throw INTERP_KERNEL::Exception(oss.str().c_str());
1850 if(PyTuple_Check(value) || PyList_Check(value))
1854 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1855 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1860 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1863 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1864 if(SWIG_IsOK(status))
1866 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1870 if(d->getNumberOfTuples()==nbTuplesExpected)
1872 if(d->getNumberOfComponents()==nbCompExpected)
1874 return d->getConstPointer();
1878 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1879 throw INTERP_KERNEL::Exception(oss.str().c_str());
1884 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1885 throw INTERP_KERNEL::Exception(oss.str().c_str());
1892 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1893 throw INTERP_KERNEL::Exception(oss.str().c_str());
1899 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1900 if(SWIG_IsOK(status))
1902 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1904 if(e->getNumberOfCompo()==nbCompExpected)
1906 if(nbTuplesExpected==1)
1907 return e->getConstPointer();
1910 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1911 throw INTERP_KERNEL::Exception(oss.str().c_str());
1916 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1917 throw INTERP_KERNEL::Exception(oss.str().c_str());
1920 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1924 * if value int -> cpp val sw=1
1925 * if value double -> cpp val sw=1
1926 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1927 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1928 * if value list[int,double] -> cpp std::vector<double> sw=4
1929 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1931 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1932 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1935 if(PyFloat_Check(value))
1937 val=PyFloat_AS_DOUBLE(value);
1939 if(nbCompExpected!=1)
1941 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1942 throw INTERP_KERNEL::Exception(oss.str().c_str());
1947 if(PyInt_Check(value))
1949 val=(double)PyInt_AS_LONG(value);
1951 if(nbCompExpected!=1)
1953 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1954 throw INTERP_KERNEL::Exception(oss.str().c_str());
1959 if(PyTuple_Check(value))
1961 int size=PyTuple_Size(value);
1963 for(int i=0;i<size;i++)
1965 PyObject *o=PyTuple_GetItem(value,i);
1966 if(PyFloat_Check(o))
1967 f[i]=PyFloat_AS_DOUBLE(o);
1968 else if(PyInt_Check(o))
1969 f[i]=(double)PyInt_AS_LONG(o);
1972 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1973 throw INTERP_KERNEL::Exception(oss.str().c_str());
1977 if(size%nbCompExpected!=0)
1979 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1980 throw INTERP_KERNEL::Exception(oss.str().c_str());
1982 nbTuples=size/nbCompExpected;
1985 if(PyList_Check(value))
1987 int size=PyList_Size(value);
1989 for(int i=0;i<size;i++)
1991 PyObject *o=PyList_GetItem(value,i);
1992 if(PyFloat_Check(o))
1993 f[i]=PyFloat_AS_DOUBLE(o);
1994 else if(PyInt_Check(o))
1995 f[i]=(double)PyInt_AS_LONG(o);
1998 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1999 throw INTERP_KERNEL::Exception(oss.str().c_str());
2003 if(size%nbCompExpected!=0)
2005 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2006 throw INTERP_KERNEL::Exception(oss.str().c_str());
2008 nbTuples=size/nbCompExpected;
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->getNumberOfComponents()==nbCompExpected)
2021 nbTuples=d->getNumberOfTuples();
2022 return d->getConstPointer();
2026 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2027 throw INTERP_KERNEL::Exception(oss.str().c_str());
2034 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2035 throw INTERP_KERNEL::Exception(oss.str().c_str());
2038 { nbTuples=0; return 0; }
2041 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2042 if(SWIG_IsOK(status))
2044 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2048 if(e->getNumberOfCompo()==nbCompExpected)
2051 return e->getConstPointer();
2055 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2056 throw INTERP_KERNEL::Exception(oss.str().c_str());
2063 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2064 throw INTERP_KERNEL::Exception(oss.str().c_str());
2067 { nbTuples=0; return 0; }
2070 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2074 * if value int -> cpp val sw=1
2075 * if value double -> cpp val sw=1
2076 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2077 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2078 * if value list[int,double] -> cpp std::vector<double> sw=4
2079 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2081 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2082 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2084 ParaMEDMEM::DataArrayDouble *d=0;
2085 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2087 if(PyFloat_Check(value))
2089 val=PyFloat_AS_DOUBLE(value);
2094 if(PyInt_Check(value))
2096 val=(double)PyInt_AS_LONG(value);
2101 if(PyTuple_Check(value))
2103 int size=PyTuple_Size(value);
2105 for(int i=0;i<size;i++)
2107 PyObject *o=PyTuple_GetItem(value,i);
2108 if(PyFloat_Check(o))
2109 f[i]=PyFloat_AS_DOUBLE(o);
2110 else if(PyInt_Check(o))
2111 f[i]=(double)PyInt_AS_LONG(o);
2114 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2115 throw INTERP_KERNEL::Exception(oss.str().c_str());
2122 if(PyList_Check(value))
2124 int size=PyList_Size(value);
2126 for(int i=0;i<size;i++)
2128 PyObject *o=PyList_GetItem(value,i);
2129 if(PyFloat_Check(o))
2130 f[i]=PyFloat_AS_DOUBLE(o);
2131 else if(PyInt_Check(o))
2132 f[i]=(double)PyInt_AS_LONG(o);
2135 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2136 throw INTERP_KERNEL::Exception(oss.str().c_str());
2144 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2145 if(SWIG_IsOK(status))
2147 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2151 if(d->getNumberOfComponents()==1)
2153 nbTuples=d->getNumberOfTuples();
2154 return d->getConstPointer();
2158 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2159 throw INTERP_KERNEL::Exception(oss.str().c_str());
2166 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2167 throw INTERP_KERNEL::Exception(oss.str().c_str());
2170 { nbTuples=0; return 0; }
2173 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2174 if(SWIG_IsOK(status))
2176 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2180 nbTuples=e->getNumberOfCompo();
2181 return e->getConstPointer();
2187 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2188 throw INTERP_KERNEL::Exception(oss.str().c_str());
2191 { nbTuples=0; return 0; }
2194 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2198 * if python int -> cpp int sw=1
2199 * if python list[int] -> cpp vector<int> sw=2
2200 * if python tuple[int] -> cpp vector<int> sw=2
2201 * if python DataArrayInt -> cpp DataArrayInt sw=3
2202 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2204 * switch between (int,vector<int>,DataArrayInt)
2206 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2209 if(PyInt_Check(value))
2211 iTyypp=(int)PyInt_AS_LONG(value);
2215 if(PyTuple_Check(value))
2217 int size=PyTuple_Size(value);
2218 stdvecTyypp.resize(size);
2219 for(int i=0;i<size;i++)
2221 PyObject *o=PyTuple_GetItem(value,i);
2223 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2226 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2227 throw INTERP_KERNEL::Exception(oss.str().c_str());
2231 return &stdvecTyypp[0];
2233 if(PyList_Check(value))
2235 int size=PyList_Size(value);
2236 stdvecTyypp.resize(size);
2237 for(int i=0;i<size;i++)
2239 PyObject *o=PyList_GetItem(value,i);
2241 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2244 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2245 throw INTERP_KERNEL::Exception(oss.str().c_str());
2249 return &stdvecTyypp[0];
2252 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2253 if(SWIG_IsOK(status))
2255 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2258 sw=3; sz=daIntTyypp->getNbOfElems();
2259 return daIntTyypp->begin();
2267 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2268 if(SWIG_IsOK(status))
2270 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2271 sw=4; sz=daIntTuple->getNumberOfCompo();
2272 return daIntTuple->getConstPointer();
2274 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2277 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2280 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2281 if(!SWIG_IsOK(status))
2283 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2284 if(!SWIG_IsOK(status))
2286 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2287 if(!SWIG_IsOK(status))
2289 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2290 if(!SWIG_IsOK(status))
2292 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2293 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2294 throw INTERP_KERNEL::Exception(oss.str().c_str());
2299 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);