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 void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
629 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
630 if(PyList_Check(pyLi))
632 int size=PyList_Size(pyLi);
634 for(int i=0;i<size;i++)
636 PyObject *o=PyList_GetItem(pyLi,i);
639 int sz2=PyTuple_Size(o);
641 throw INTERP_KERNEL::Exception(msg);
642 PyObject *o_0=PyTuple_GetItem(o,0);
643 if(!PyInt_Check(o_0))
644 throw INTERP_KERNEL::Exception(msg);
645 PyObject *o_1=PyTuple_GetItem(o,1);
646 if(!PyInt_Check(o_1))
647 throw INTERP_KERNEL::Exception(msg);
648 arr[i].first=(int)PyInt_AS_LONG(o_0);
649 arr[i].second=(int)PyInt_AS_LONG(o_1);
652 throw INTERP_KERNEL::Exception(msg);
655 else if(PyTuple_Check(pyLi))
657 int size=PyTuple_Size(pyLi);
659 for(int i=0;i<size;i++)
661 PyObject *o=PyTuple_GetItem(pyLi,i);
664 int sz2=PyTuple_Size(o);
666 throw INTERP_KERNEL::Exception(msg);
667 PyObject *o_0=PyTuple_GetItem(o,0);
668 if(!PyInt_Check(o_0))
669 throw INTERP_KERNEL::Exception(msg);
670 PyObject *o_1=PyTuple_GetItem(o,1);
671 if(!PyInt_Check(o_1))
672 throw INTERP_KERNEL::Exception(msg);
673 arr[i].first=(int)PyInt_AS_LONG(o_0);
674 arr[i].second=(int)PyInt_AS_LONG(o_1);
677 throw INTERP_KERNEL::Exception(msg);
681 throw INTERP_KERNEL::Exception(msg);
684 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
686 if(PyList_Check(pyLi))
688 int size=PyList_Size(pyLi);
690 for(int i=0;i<size;i++)
692 PyObject *o=PyList_GetItem(pyLi,i);
695 int val=(int)PyInt_AS_LONG(o);
699 throw INTERP_KERNEL::Exception("list must contain integers only");
702 else if(PyTuple_Check(pyLi))
704 int size=PyTuple_Size(pyLi);
706 for(int i=0;i<size;i++)
708 PyObject *o=PyTuple_GetItem(pyLi,i);
711 int val=(int)PyInt_AS_LONG(o);
715 throw INTERP_KERNEL::Exception("tuple must contain integers only");
720 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
724 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
727 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
729 if(PyList_Check(pyLi))
731 int size=PyList_Size(pyLi);
732 for(int i=0;i<size;i++)
734 PyObject *o=PyList_GetItem(pyLi,i);
737 int val=(int)PyInt_AS_LONG(o);
742 std::vector<int> arr2;
743 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
744 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
746 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
747 throw INTERP_KERNEL::Exception(oss.str().c_str());
749 arr.insert(arr.end(),arr2.begin(),arr2.end());
753 else if(PyTuple_Check(pyLi))
755 int size=PyTuple_Size(pyLi);
756 for(int i=0;i<size;i++)
758 PyObject *o=PyTuple_GetItem(pyLi,i);
761 int val=(int)PyInt_AS_LONG(o);
766 std::vector<int> arr2;
767 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
768 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
770 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
771 throw INTERP_KERNEL::Exception(oss.str().c_str());
773 arr.insert(arr.end(),arr2.begin(),arr2.end());
778 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
781 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
785 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
786 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
788 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
789 oss << " whereas nb of components expected is " << nbOfComp << " !";
790 throw INTERP_KERNEL::Exception(oss.str().c_str());
797 if((nbOfTuples!=size1 || nbOfComp!=size2))
799 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
801 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
802 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
803 throw INTERP_KERNEL::Exception(oss.str().c_str());
809 if(nbOfTuples==size1)
813 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
814 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
815 throw INTERP_KERNEL::Exception(oss.str().c_str());
821 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
823 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
824 if(PyInt_Check(pyLi))
826 long val=PyInt_AS_LONG(pyLi);
831 throw INTERP_KERNEL::Exception(MSG);
834 else if(PyList_Check(pyLi))
836 int size=PyList_Size(pyLi);
838 for(int i=0;i<size;i++)
840 PyObject *o=PyList_GetItem(pyLi,i);
842 fillArrayWithPyListInt3(o,tmp1,ret);
850 throw INTERP_KERNEL::Exception(MSG);
853 else if(PyTuple_Check(pyLi))
855 int size=PyTuple_Size(pyLi);
857 for(int i=0;i<size;i++)
859 PyObject *o=PyTuple_GetItem(pyLi,i);
861 fillArrayWithPyListInt3(o,tmp1,ret);
869 throw INTERP_KERNEL::Exception(MSG);
873 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
876 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
878 std::vector<int> ret;
879 int size1=-1,size2=-1;
880 if(PyList_Check(pyLi))
882 size1=PyList_Size(pyLi);
883 for(int i=0;i<size1;i++)
885 PyObject *o=PyList_GetItem(pyLi,i);
886 fillArrayWithPyListInt3(o,size2,ret);
891 else if(PyTuple_Check(pyLi))
893 size1=PyTuple_Size(pyLi);
894 for(int i=0;i<size1;i++)
896 PyObject *o=PyTuple_GetItem(pyLi,i);
897 fillArrayWithPyListInt3(o,size2,ret);
903 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
905 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
909 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
911 if(PyList_Check(pyLi))
913 Py_ssize_t sz=PyList_Size(pyLi);
915 for(int i=0;i<sz;i++)
917 PyObject *o=PyList_GetItem(pyLi,i);
918 if(PyString_Check(o))
919 vec[i]=PyString_AsString(o);
925 else if(PyTuple_Check(pyLi))
927 Py_ssize_t sz=PyTuple_Size(pyLi);
929 for(int i=0;i<sz;i++)
931 PyObject *o=PyTuple_GetItem(pyLi,i);
932 if(PyString_Check(o))
933 vec[i]=PyString_AsString(o);
943 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
945 PyObject *ret=PyList_New(size);
946 for(int i=0;i<size;i++)
947 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
951 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
954 PyObject *ret=PyList_New(size);
955 for(int i=0;i<size;i++)
956 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
960 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
962 PyObject *ret=PyList_New(nbOfTuples);
963 for(int i=0;i<nbOfTuples;i++)
965 PyObject *t=PyTuple_New(nbOfComp);
966 for(int j=0;j<nbOfComp;j++)
967 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
968 PyList_SetItem(ret,i,t);
973 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
975 PyObject *ret=PyList_New(nbOfTuples);
976 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
977 for(int i=0;i<nbOfTuples;i++)
979 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
980 PyList_SetItem(ret,i,PyString_FromString(tmp));
985 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
987 if(PyList_Check(pyLi))
989 *size=PyList_Size(pyLi);
990 double *tmp=(double *)malloc((*size)*sizeof(double));
991 for(int i=0;i<*size;i++)
993 PyObject *o=PyList_GetItem(pyLi,i);
996 double val=PyFloat_AS_DOUBLE(o);
999 else if(PyInt_Check(o))
1001 long val0=PyInt_AS_LONG(o);
1008 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1013 else if(PyTuple_Check(pyLi))
1015 *size=PyTuple_Size(pyLi);
1016 double *tmp=(double *)malloc((*size)*sizeof(double));
1017 for(int i=0;i<*size;i++)
1019 PyObject *o=PyTuple_GetItem(pyLi,i);
1020 if(PyFloat_Check(o))
1022 double val=PyFloat_AS_DOUBLE(o);
1025 else if(PyInt_Check(o))
1027 long val0=PyInt_AS_LONG(o);
1034 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1040 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1043 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1045 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1046 if(PyFloat_Check(pyLi))
1052 throw INTERP_KERNEL::Exception(MSG);
1053 double val=PyFloat_AS_DOUBLE(pyLi);
1056 else if(PyInt_Check(pyLi))
1058 long val0=PyInt_AS_LONG(pyLi);
1064 throw INTERP_KERNEL::Exception(MSG);
1067 else if(PyList_Check(pyLi))
1069 int size=PyList_Size(pyLi);
1071 for(int i=0;i<size;i++)
1073 PyObject *o=PyList_GetItem(pyLi,i);
1075 fillArrayWithPyListDbl3(o,tmp1,ret);
1083 throw INTERP_KERNEL::Exception(MSG);
1086 else if(PyTuple_Check(pyLi))
1088 int size=PyTuple_Size(pyLi);
1090 for(int i=0;i<size;i++)
1092 PyObject *o=PyTuple_GetItem(pyLi,i);
1094 fillArrayWithPyListDbl3(o,tmp1,ret);
1102 throw INTERP_KERNEL::Exception(MSG);
1106 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1109 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1111 std::vector<double> ret;
1112 int size1=-1,size2=-1;
1113 if(PyList_Check(pyLi))
1115 size1=PyList_Size(pyLi);
1116 for(int i=0;i<size1;i++)
1118 PyObject *o=PyList_GetItem(pyLi,i);
1119 fillArrayWithPyListDbl3(o,size2,ret);
1124 else if(PyTuple_Check(pyLi))
1126 size1=PyTuple_Size(pyLi);
1127 for(int i=0;i<size1;i++)
1129 PyObject *o=PyTuple_GetItem(pyLi,i);
1130 fillArrayWithPyListDbl3(o,size2,ret);
1136 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1138 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1142 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1144 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1147 if(PyList_Check(pyLi))
1149 int size=PyList_Size(pyLi);
1151 for(int i=0;i<size;i++)
1153 PyObject *obj=PyList_GetItem(pyLi,i);
1154 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1155 if(!SWIG_IsOK(status))
1157 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1158 throw INTERP_KERNEL::Exception(oss.str().c_str());
1160 T arg=reinterpret_cast< T >(argp);
1164 else if(PyTuple_Check(pyLi))
1166 int size=PyTuple_Size(pyLi);
1168 for(int i=0;i<size;i++)
1170 PyObject *obj=PyTuple_GetItem(pyLi,i);
1171 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1172 if(!SWIG_IsOK(status))
1174 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1175 throw INTERP_KERNEL::Exception(oss.str().c_str());
1177 T arg=reinterpret_cast< T >(argp);
1181 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1184 T arg=reinterpret_cast< T >(argp);
1188 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1192 * if python int -> cpp int sw=1
1193 * if python list[int] -> cpp vector<int> sw=2
1194 * if python tuple[int] -> cpp vector<int> sw=2
1195 * if python DataArrayInt -> cpp DataArrayInt sw=3
1196 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1198 * switch between (int,vector<int>,DataArrayInt)
1200 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1203 if(PyInt_Check(value))
1205 iTyypp=(int)PyInt_AS_LONG(value);
1209 if(PyTuple_Check(value))
1211 int size=PyTuple_Size(value);
1212 stdvecTyypp.resize(size);
1213 for(int i=0;i<size;i++)
1215 PyObject *o=PyTuple_GetItem(value,i);
1217 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1220 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1221 throw INTERP_KERNEL::Exception(oss.str().c_str());
1227 if(PyList_Check(value))
1229 int size=PyList_Size(value);
1230 stdvecTyypp.resize(size);
1231 for(int i=0;i<size;i++)
1233 PyObject *o=PyList_GetItem(value,i);
1235 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1238 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1239 throw INTERP_KERNEL::Exception(oss.str().c_str());
1246 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1247 if(SWIG_IsOK(status))
1249 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1253 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1254 if(SWIG_IsOK(status))
1256 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1260 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1264 * if python double -> cpp double sw=1
1265 * if python int -> cpp double sw=1
1266 * if python list[double] -> cpp vector<double> sw=2
1267 * if python list[int] -> cpp vector<double> sw=2
1268 * if python tuple[double] -> cpp vector<double> sw=2
1269 * if python tuple[int] -> cpp vector<double> sw=2
1270 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1272 * switch between (int,vector<int>,DataArrayInt)
1274 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1277 if(PyFloat_Check(value))
1279 iTyypp=PyFloat_AS_DOUBLE(value);
1283 if(PyInt_Check(value))
1285 iTyypp=(double)PyInt_AS_LONG(value);
1289 if(PyTuple_Check(value))
1291 int size=PyTuple_Size(value);
1292 stdvecTyypp.resize(size);
1293 for(int i=0;i<size;i++)
1295 PyObject *o=PyTuple_GetItem(value,i);
1296 if(PyFloat_Check(o))
1297 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1298 else if(PyInt_Check(o))
1299 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1302 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1303 throw INTERP_KERNEL::Exception(oss.str().c_str());
1309 if(PyList_Check(value))
1311 int size=PyList_Size(value);
1312 stdvecTyypp.resize(size);
1313 for(int i=0;i<size;i++)
1315 PyObject *o=PyList_GetItem(value,i);
1316 if(PyFloat_Check(o))
1317 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1318 else if(PyInt_Check(o))
1319 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1322 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1323 throw INTERP_KERNEL::Exception(oss.str().c_str());
1330 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1331 if(!SWIG_IsOK(status))
1332 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1333 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1338 * if python double -> cpp double sw=1
1339 * if python int -> cpp double sw=1
1340 * if python list[double] -> cpp vector<double> sw=2
1341 * if python list[int] -> cpp vector<double> sw=2
1342 * if python tuple[double] -> cpp vector<double> sw=2
1343 * if python tuple[int] -> cpp vector<double> sw=2
1344 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1346 * switch between (int,vector<int>,DataArrayInt)
1348 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1351 if(PyFloat_Check(value))
1353 iTyypp=PyFloat_AS_DOUBLE(value);
1357 if(PyInt_Check(value))
1359 iTyypp=(double)PyInt_AS_LONG(value);
1363 if(PyTuple_Check(value))
1365 int size=PyTuple_Size(value);
1366 stdvecTyypp.resize(size);
1367 for(int i=0;i<size;i++)
1369 PyObject *o=PyTuple_GetItem(value,i);
1370 if(PyFloat_Check(o))
1371 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1372 else if(PyInt_Check(o))
1373 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1376 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1377 throw INTERP_KERNEL::Exception(oss.str().c_str());
1383 if(PyList_Check(value))
1385 int size=PyList_Size(value);
1386 stdvecTyypp.resize(size);
1387 for(int i=0;i<size;i++)
1389 PyObject *o=PyList_GetItem(value,i);
1390 if(PyFloat_Check(o))
1391 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1392 else if(PyInt_Check(o))
1393 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1396 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1397 throw INTERP_KERNEL::Exception(oss.str().c_str());
1404 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1405 if(!SWIG_IsOK(status))
1406 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1407 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1412 * if python int -> cpp int sw=1
1413 * if python list[int] -> cpp vector<int> sw=2
1414 * if python tuple[int] -> cpp vector<int> sw=2
1415 * if python slicp -> cpp pair sw=3 (begin,end,step)
1416 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1418 * switch between (int,vector<int>,DataArrayInt)
1420 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)
1422 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1424 if(PyInt_Check(value))
1426 iTyypp=(int)PyInt_AS_LONG(value);
1430 if(PyTuple_Check(value))
1432 int size=PyTuple_Size(value);
1433 stdvecTyypp.resize(size);
1434 for(int i=0;i<size;i++)
1436 PyObject *o=PyTuple_GetItem(value,i);
1438 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1441 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1442 throw INTERP_KERNEL::Exception(oss.str().c_str());
1448 if(PyList_Check(value))
1450 int size=PyList_Size(value);
1451 stdvecTyypp.resize(size);
1452 for(int i=0;i<size;i++)
1454 PyObject *o=PyList_GetItem(value,i);
1456 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1459 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1460 throw INTERP_KERNEL::Exception(oss.str().c_str());
1466 if(PySlice_Check(value))
1468 Py_ssize_t strt=2,stp=2,step=2;
1469 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1470 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1473 p.second.second=step;
1478 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1479 if(SWIG_IsOK(status))
1481 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1484 std::ostringstream oss; oss << msg << " Instance in null !";
1485 throw INTERP_KERNEL::Exception(oss.str().c_str());
1490 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1491 if(SWIG_IsOK(status))
1493 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1496 std::ostringstream oss; oss << msg << " Instance in null !";
1497 throw INTERP_KERNEL::Exception(oss.str().c_str());
1499 stdvecTyypp.resize(tmp->getNumberOfCompo());
1500 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1504 throw INTERP_KERNEL::Exception(msg);
1508 * Idem than convertObjToPossibleCpp2
1510 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)
1512 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1515 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1520 * if python int -> cpp int sw=1
1521 * if python tuple[int] -> cpp vector<int> sw=2
1522 * if python list[int] -> cpp vector<int> sw=2
1523 * if python slice -> cpp pair sw=3
1524 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1526 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)
1529 if(PyInt_Check(value))
1531 iTyypp=(int)PyInt_AS_LONG(value);
1535 if(PyTuple_Check(value))
1537 int size=PyTuple_Size(value);
1538 stdvecTyypp.resize(size);
1539 for(int i=0;i<size;i++)
1541 PyObject *o=PyTuple_GetItem(value,i);
1543 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1546 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1547 throw INTERP_KERNEL::Exception(oss.str().c_str());
1553 if(PyList_Check(value))
1555 int size=PyList_Size(value);
1556 stdvecTyypp.resize(size);
1557 for(int i=0;i<size;i++)
1559 PyObject *o=PyList_GetItem(value,i);
1561 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1564 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1571 if(PySlice_Check(value))
1573 Py_ssize_t strt=2,stp=2,step=2;
1574 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1575 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1578 p.second.second=step;
1583 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1584 if(!SWIG_IsOK(status))
1585 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1586 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1591 * if python string with size one -> cpp char sw=1
1592 * if python string with size different from one -> cpp string sw=2
1593 * if python tuple[string] or list[string] -> vector<string> sw=3
1594 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1595 * switch between (int,string,vector<string>,DataArrayChar)
1597 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1599 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1601 if(PyString_Check(value))
1603 const char *pt=PyString_AsString(value);
1604 Py_ssize_t sz=PyString_Size(value);
1618 if(PyTuple_Check(value))
1620 int size=PyTuple_Size(value);
1621 vsType.resize(size);
1622 for(int i=0;i<size;i++)
1624 PyObject *o=PyTuple_GetItem(value,i);
1625 if(PyString_Check(o))
1626 vsType[i]=PyString_AsString(o);
1629 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1630 throw INTERP_KERNEL::Exception(oss.str().c_str());
1636 if(PyList_Check(value))
1638 int size=PyList_Size(value);
1639 vsType.resize(size);
1640 for(int i=0;i<size;i++)
1642 PyObject *o=PyList_GetItem(value,i);
1643 if(PyString_Check(o))
1644 vsType[i]=PyString_AsString(o);
1647 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1648 throw INTERP_KERNEL::Exception(oss.str().c_str());
1655 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1656 if(SWIG_IsOK(status))
1658 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1661 std::ostringstream oss; oss << msg << " Instance in null !";
1662 throw INTERP_KERNEL::Exception(oss.str().c_str());
1667 throw INTERP_KERNEL::Exception(msg);
1671 * if value int -> cpp it sw=1
1672 * if value list[int] -> vt sw=2
1673 * if value tuple[int] -> vt sw=2
1674 * if value slice -> pt sw=3
1675 * if value DataArrayInt -> dt sw=4
1676 * if value tuple [int,int] -> cpp it,ip sw=5
1677 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1678 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1679 * if value tuple [slice,int] -> cpp pt,ip sw=7
1680 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1681 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1682 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1683 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1684 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1685 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1686 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1687 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1688 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1689 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1690 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1691 * if value tuple [int,slice] -> cpp it,pc sw=13
1692 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1693 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1694 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1695 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1697 * switch between (int,vector<int>,DataArrayInt)
1699 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1700 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1701 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1703 if(!PyTuple_Check(value))
1705 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1710 int sz=PyTuple_Size(value);
1712 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1713 PyObject *ob0=PyTuple_GetItem(value,0);
1715 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1716 PyObject *ob1=PyTuple_GetItem(value,1);
1717 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1723 * if value int -> cpp val sw=1
1724 * if value double -> cpp val sw=1
1725 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1726 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1727 * if value list[int,double] -> cpp std::vector<double> sw=4
1728 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1730 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1733 if(PyFloat_Check(value))
1735 val=PyFloat_AS_DOUBLE(value);
1739 if(PyInt_Check(value))
1741 val=(double)PyInt_AS_LONG(value);
1745 if(PyTuple_Check(value))
1747 int size=PyTuple_Size(value);
1749 for(int i=0;i<size;i++)
1751 PyObject *o=PyTuple_GetItem(value,i);
1752 if(PyFloat_Check(o))
1753 f[i]=PyFloat_AS_DOUBLE(o);
1754 else if(PyInt_Check(o))
1755 f[i]=(double)PyInt_AS_LONG(o);
1758 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1759 throw INTERP_KERNEL::Exception(oss.str().c_str());
1765 if(PyList_Check(value))
1767 int size=PyList_Size(value);
1769 for(int i=0;i<size;i++)
1771 PyObject *o=PyList_GetItem(value,i);
1772 if(PyFloat_Check(o))
1773 f[i]=PyFloat_AS_DOUBLE(o);
1774 else if(PyInt_Check(o))
1775 f[i]=(double)PyInt_AS_LONG(o);
1778 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1779 throw INTERP_KERNEL::Exception(oss.str().c_str());
1786 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1787 if(SWIG_IsOK(status))
1789 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1793 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1794 if(SWIG_IsOK(status))
1796 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1800 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1804 * if value int -> cpp val sw=1
1805 * if value double -> cpp val sw=1
1806 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1807 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1808 * if value list[int,double] -> cpp std::vector<double> sw=4
1809 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1811 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1812 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1815 if(PyFloat_Check(value))
1817 val=PyFloat_AS_DOUBLE(value);
1819 if(nbTuplesExpected*nbCompExpected!=1)
1821 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1822 throw INTERP_KERNEL::Exception(oss.str().c_str());
1826 if(PyInt_Check(value))
1828 val=(double)PyInt_AS_LONG(value);
1830 if(nbTuplesExpected*nbCompExpected!=1)
1832 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1833 throw INTERP_KERNEL::Exception(oss.str().c_str());
1837 if(PyTuple_Check(value) || PyList_Check(value))
1841 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1842 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1847 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1850 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1851 if(SWIG_IsOK(status))
1853 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1857 if(d->getNumberOfTuples()==nbTuplesExpected)
1859 if(d->getNumberOfComponents()==nbCompExpected)
1861 return d->getConstPointer();
1865 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1866 throw INTERP_KERNEL::Exception(oss.str().c_str());
1871 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1872 throw INTERP_KERNEL::Exception(oss.str().c_str());
1879 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1880 throw INTERP_KERNEL::Exception(oss.str().c_str());
1886 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1887 if(SWIG_IsOK(status))
1889 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1891 if(e->getNumberOfCompo()==nbCompExpected)
1893 if(nbTuplesExpected==1)
1894 return e->getConstPointer();
1897 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1898 throw INTERP_KERNEL::Exception(oss.str().c_str());
1903 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1904 throw INTERP_KERNEL::Exception(oss.str().c_str());
1907 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1911 * if value int -> cpp val sw=1
1912 * if value double -> cpp val sw=1
1913 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1914 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1915 * if value list[int,double] -> cpp std::vector<double> sw=4
1916 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1918 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1919 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1922 if(PyFloat_Check(value))
1924 val=PyFloat_AS_DOUBLE(value);
1926 if(nbCompExpected!=1)
1928 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1929 throw INTERP_KERNEL::Exception(oss.str().c_str());
1934 if(PyInt_Check(value))
1936 val=(double)PyInt_AS_LONG(value);
1938 if(nbCompExpected!=1)
1940 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1941 throw INTERP_KERNEL::Exception(oss.str().c_str());
1946 if(PyTuple_Check(value))
1948 int size=PyTuple_Size(value);
1950 for(int i=0;i<size;i++)
1952 PyObject *o=PyTuple_GetItem(value,i);
1953 if(PyFloat_Check(o))
1954 f[i]=PyFloat_AS_DOUBLE(o);
1955 else if(PyInt_Check(o))
1956 f[i]=(double)PyInt_AS_LONG(o);
1959 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1960 throw INTERP_KERNEL::Exception(oss.str().c_str());
1964 if(size%nbCompExpected!=0)
1966 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1967 throw INTERP_KERNEL::Exception(oss.str().c_str());
1969 nbTuples=size/nbCompExpected;
1972 if(PyList_Check(value))
1974 int size=PyList_Size(value);
1976 for(int i=0;i<size;i++)
1978 PyObject *o=PyList_GetItem(value,i);
1979 if(PyFloat_Check(o))
1980 f[i]=PyFloat_AS_DOUBLE(o);
1981 else if(PyInt_Check(o))
1982 f[i]=(double)PyInt_AS_LONG(o);
1985 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1986 throw INTERP_KERNEL::Exception(oss.str().c_str());
1990 if(size%nbCompExpected!=0)
1992 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1993 throw INTERP_KERNEL::Exception(oss.str().c_str());
1995 nbTuples=size/nbCompExpected;
1999 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2000 if(SWIG_IsOK(status))
2002 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2006 if(d->getNumberOfComponents()==nbCompExpected)
2008 nbTuples=d->getNumberOfTuples();
2009 return d->getConstPointer();
2013 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2014 throw INTERP_KERNEL::Exception(oss.str().c_str());
2021 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2022 throw INTERP_KERNEL::Exception(oss.str().c_str());
2025 { nbTuples=0; return 0; }
2028 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2029 if(SWIG_IsOK(status))
2031 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2035 if(e->getNumberOfCompo()==nbCompExpected)
2038 return e->getConstPointer();
2042 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2043 throw INTERP_KERNEL::Exception(oss.str().c_str());
2050 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2051 throw INTERP_KERNEL::Exception(oss.str().c_str());
2054 { nbTuples=0; return 0; }
2057 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2061 * if value int -> cpp val sw=1
2062 * if value double -> cpp val sw=1
2063 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2064 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2065 * if value list[int,double] -> cpp std::vector<double> sw=4
2066 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2068 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2069 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2071 ParaMEDMEM::DataArrayDouble *d=0;
2072 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2074 if(PyFloat_Check(value))
2076 val=PyFloat_AS_DOUBLE(value);
2081 if(PyInt_Check(value))
2083 val=(double)PyInt_AS_LONG(value);
2088 if(PyTuple_Check(value))
2090 int size=PyTuple_Size(value);
2092 for(int i=0;i<size;i++)
2094 PyObject *o=PyTuple_GetItem(value,i);
2095 if(PyFloat_Check(o))
2096 f[i]=PyFloat_AS_DOUBLE(o);
2097 else if(PyInt_Check(o))
2098 f[i]=(double)PyInt_AS_LONG(o);
2101 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2102 throw INTERP_KERNEL::Exception(oss.str().c_str());
2109 if(PyList_Check(value))
2111 int size=PyList_Size(value);
2113 for(int i=0;i<size;i++)
2115 PyObject *o=PyList_GetItem(value,i);
2116 if(PyFloat_Check(o))
2117 f[i]=PyFloat_AS_DOUBLE(o);
2118 else if(PyInt_Check(o))
2119 f[i]=(double)PyInt_AS_LONG(o);
2122 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2123 throw INTERP_KERNEL::Exception(oss.str().c_str());
2131 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2132 if(SWIG_IsOK(status))
2134 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2138 if(d->getNumberOfComponents()==1)
2140 nbTuples=d->getNumberOfTuples();
2141 return d->getConstPointer();
2145 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2146 throw INTERP_KERNEL::Exception(oss.str().c_str());
2153 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2154 throw INTERP_KERNEL::Exception(oss.str().c_str());
2157 { nbTuples=0; return 0; }
2160 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2161 if(SWIG_IsOK(status))
2163 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2167 nbTuples=e->getNumberOfCompo();
2168 return e->getConstPointer();
2174 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2175 throw INTERP_KERNEL::Exception(oss.str().c_str());
2178 { nbTuples=0; return 0; }
2181 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2185 * if python int -> cpp int sw=1
2186 * if python list[int] -> cpp vector<int> sw=2
2187 * if python tuple[int] -> cpp vector<int> sw=2
2188 * if python DataArrayInt -> cpp DataArrayInt sw=3
2189 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2191 * switch between (int,vector<int>,DataArrayInt)
2193 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2196 if(PyInt_Check(value))
2198 iTyypp=(int)PyInt_AS_LONG(value);
2202 if(PyTuple_Check(value))
2204 int size=PyTuple_Size(value);
2205 stdvecTyypp.resize(size);
2206 for(int i=0;i<size;i++)
2208 PyObject *o=PyTuple_GetItem(value,i);
2210 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2213 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2214 throw INTERP_KERNEL::Exception(oss.str().c_str());
2218 return &stdvecTyypp[0];
2220 if(PyList_Check(value))
2222 int size=PyList_Size(value);
2223 stdvecTyypp.resize(size);
2224 for(int i=0;i<size;i++)
2226 PyObject *o=PyList_GetItem(value,i);
2228 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2231 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2232 throw INTERP_KERNEL::Exception(oss.str().c_str());
2236 return &stdvecTyypp[0];
2239 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2240 if(SWIG_IsOK(status))
2242 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2245 sw=3; sz=daIntTyypp->getNbOfElems();
2246 return daIntTyypp->begin();
2254 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2255 if(SWIG_IsOK(status))
2257 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2258 sw=4; sz=daIntTuple->getNumberOfCompo();
2259 return daIntTuple->getConstPointer();
2261 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2264 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2267 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2268 if(!SWIG_IsOK(status))
2270 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2271 if(!SWIG_IsOK(status))
2273 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2274 if(!SWIG_IsOK(status))
2276 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2277 if(!SWIG_IsOK(status))
2279 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2280 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2281 throw INTERP_KERNEL::Exception(oss.str().c_str());
2286 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);