1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelAutoPtr.hxx"
24 * This method is an extention of PySlice_GetIndices but less
25 * open than PySlice_GetIndicesEx that accepts too many situations.
27 void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
29 int ret(PySlice_GetIndices(slice,length,start,stop,step));
32 if(*step>0 && *start==*stop && length==*start)
34 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
38 * This method allows to retrieve slice info from \a slice.
40 void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
42 int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
45 if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
47 std::ostringstream oss;
48 oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
49 throw INTERP_KERNEL::Exception(oss.str().c_str());
51 throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
54 int InterpreteNegativeInt(int val, int nbelem)
58 int newVal(nbelem+val);
61 std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
62 throw INTERP_KERNEL::Exception(oss.str().c_str());
71 #include <numpy/arrayobject.h>
73 // specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
74 // method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
75 // if no more alive the "standart" DataArray deallocator is called.
76 void numarrdeal(void *pt, void *wron)
78 void **wronc=(void **)wron;
79 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
80 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
84 PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
85 objC->flags|=NPY_OWNDATA;
86 Py_XDECREF(weakRefOnOwner);
91 typedef void (*MyDeallocator)(void *,void *);
92 MyDeallocator deall=(MyDeallocator)wronc[1];
94 Py_XDECREF(weakRefOnOwner);
99 template<class MCData>
100 struct PyCallBackDataArraySt {
105 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayInt> PyCallBackDataArrayInt;
106 typedef struct PyCallBackDataArraySt<ParaMEDMEM::DataArrayDouble> PyCallBackDataArrayDouble;
110 static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
112 static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
114 PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
115 return (PyObject *)self;
118 static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
120 PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
121 return (PyObject *)self;
124 static void callbackmcdataarray_dealloc(PyObject *self)
126 Py_TYPE(self)->tp_free(self);
129 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
130 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
131 static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
135 ParaMEDMEM::MemArray<int>& mma=self->_pt_mc->accessToMemArray();
142 // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
143 // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
144 static PyObject *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
148 ParaMEDMEM::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
156 PyTypeObject PyCallBackDataArrayInt_RefType = {
157 PyVarObject_HEAD_INIT(&PyType_Type, 0)
158 "callbackmcdataarrayint",
159 sizeof(PyCallBackDataArrayInt),
161 callbackmcdataarray_dealloc, /*tp_dealloc*/
168 0, /*tp_as_sequence*/
171 (ternaryfunc)callbackmcdataarrayint_call, /*tp_call*/
176 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
180 0, /*tp_richcompare*/
181 0, /*tp_weaklistoffset*/
192 callbackmcdataarray___init__, /*tp_init*/
193 PyType_GenericAlloc, /*tp_alloc*/
194 callbackmcdataarrayint___new__, /*tp_new*/
195 PyObject_GC_Del, /*tp_free*/
198 PyTypeObject PyCallBackDataArrayDouble_RefType = {
199 PyVarObject_HEAD_INIT(&PyType_Type, 0)
200 "callbackmcdataarraydouble",
201 sizeof(PyCallBackDataArrayDouble),
203 callbackmcdataarray_dealloc, /*tp_dealloc*/
210 0, /*tp_as_sequence*/
213 (ternaryfunc)callbackmcdataarraydouble_call, /*tp_call*/
218 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /*tp_flags*/
222 0, /*tp_richcompare*/
223 0, /*tp_weaklistoffset*/
234 callbackmcdataarray___init__, /*tp_init*/
235 PyType_GenericAlloc, /*tp_alloc*/
236 callbackmcdataarraydouble___new__, /*tp_new*/
237 PyObject_GC_Del, /*tp_free*/
240 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
241 // in input when an another DataArray is already client of this.
242 template<class MCData>
243 void numarrdeal2(void *pt, void *obj)
245 typedef struct PyCallBackDataArraySt<MCData> PyCallBackDataArray;
246 void **obj1=(void **)obj;
247 PyCallBackDataArray *cbdaic=reinterpret_cast<PyCallBackDataArray *>(obj1[0]);
248 PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(obj1[1]);
250 Py_XDECREF(weakRefOnOwner);
255 template<class MCData, class T>
256 MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype, const char *msg)
258 int ndim=PyArray_NDIM(elt0);
259 if(ndim!=1 && ndim!=2)
260 throw INTERP_KERNEL::Exception("Input numpy array should have dimension equal to 1 or 2 !");
261 if(PyArray_DESCR(elt0)->type_num != npyObjectType)
263 std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
264 throw INTERP_KERNEL::Exception(oss.str().c_str());
266 npy_intp sz0=PyArray_DIM(elt0,0);
267 npy_intp sz1=ndim==2?PyArray_DIM(elt0,1):1;
269 int itemSize=PyArray_ITEMSIZE(elt0);
270 if(itemSize!=sizeof(T))
272 std::ostringstream oss; oss << "Input numpy array has not itemSize set to " << sizeof(T) << " !";
273 throw INTERP_KERNEL::Exception(oss.str().c_str());
275 if(itemSize*sz1!=PyArray_STRIDE(elt0,0))
276 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays !");
278 if(itemSize!=PyArray_STRIDE(elt0,1))
279 throw INTERP_KERNEL::Exception("Input numpy array has stride that mismatches the item size ! Data are not packed in the right way for DataArrays for component #1 !");
280 const char *data=PyArray_BYTES(elt0);
281 typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<MCData> ret=MCData::New();
282 if(PyArray_ISBEHAVED(elt0))//aligned and writeable and in machine byte-order
284 PyArrayObject *elt0C=reinterpret_cast<PyArrayObject *>(elt0);
285 PyArrayObject *eltOwning=(PyArray_FLAGS(elt0C) & NPY_OWNDATA)?elt0C:NULL;
286 int mask=NPY_OWNDATA; mask=~mask;
288 PyObject *deepestObj=elt0;
289 PyObject *base=elt0C->base;
290 if(base) deepestObj=base;
293 if(PyArray_Check(base))
295 PyArrayObject *baseC=reinterpret_cast<PyArrayObject *>(base);
296 eltOwning=(PyArray_FLAGS(baseC) & NPY_OWNDATA)?baseC:eltOwning;
299 if(base) deepestObj=base;
304 typename ParaMEDMEM::MemArray<T>& mma=ret->accessToMemArray();
307 PyCallBackDataArraySt<MCData> *cb=PyObject_GC_New(PyCallBackDataArraySt<MCData>,pytype);
309 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
310 PyObject *ref=PyWeakref_NewRef(deepestObj,(PyObject *)cb);
311 void **objs=new void *[2]; objs[0]=cb; objs[1]=ref;
312 mma.setParameterForDeallocator(objs);
313 mma.setSpecificDeallocator(numarrdeal2<MCData>);
314 //"Impossible to share this numpy array chunk of data, because already shared by an another non numpy array object (maybe an another DataArrayInt instance) ! Release it, or perform a copy on the input array !");
318 ret->useArray(reinterpret_cast<const T *>(data),true,ParaMEDMEM::C_DEALLOC,sz0,sz1);
319 PyObject *ref=PyWeakref_NewRef(reinterpret_cast<PyObject *>(eltOwning),NULL);
320 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(ParaMEDMEM::MemArray<T>::CDeallocator);
321 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
322 void **objs=new void *[2]; objs[0]=ref; objs[1]=*tmp2;
323 mma.setParameterForDeallocator(objs);
324 mma.setSpecificDeallocator(numarrdeal);
327 else if(PyArray_ISBEHAVED_RO(elt0))
328 ret->useArray(reinterpret_cast<const T *>(data),false,ParaMEDMEM::CPP_DEALLOC,sz0,sz1);
333 int NumpyArrSetBaseObjectExt(PyArrayObject *arr, PyObject *obj)
336 PyErr_SetString(PyExc_ValueError,
337 "Cannot set the NumPy array 'base' "
338 "dependency to NULL after initialization");
342 * Allow the base to be set only once. Once the object which
343 * owns the data is set, it doesn't make sense to change it.
345 if (PyArray_BASE(arr) != NULL) {
347 PyErr_SetString(PyExc_ValueError,
348 "Cannot set the NumPy array 'base' "
349 "dependency more than once");
354 * Don't allow infinite chains of views, always set the base
355 * to the first owner of the data.
356 * That is, either the first object which isn't an array,
357 * or the first object which owns its own data.
360 while (PyArray_Check(obj) && (PyObject *)arr != obj) {
361 PyArrayObject *obj_arr = (PyArrayObject *)obj;
365 /* If this array owns its own data, stop collapsing */
366 if (PyArray_CHKFLAGS(obj_arr, NPY_OWNDATA)) {
370 tmp = PyArray_BASE(obj_arr);
371 /* If there's no base, stop collapsing */
375 /* Stop the collapse new base when the would not be of the same
376 * type (i.e. different subclass).
378 if (Py_TYPE(tmp) != Py_TYPE(arr)) {
388 /* Disallow circular references */
389 if ((PyObject *)arr == obj) {
391 PyErr_SetString(PyExc_ValueError,
392 "Cannot create a circular NumPy array 'base' dependency");
401 template<class MCData, class T>
402 PyObject *ToNumPyArrayUnderground(MCData *self, int npyObjectType, const char *MCDataStr, int nbTuples, int nbComp)
404 if(!self->isAllocated())
406 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : this is not allocated !";
407 throw INTERP_KERNEL::Exception(oss.str().c_str());
409 ParaMEDMEM::MemArray<T>& mem=self->accessToMemArray();
412 std::ostringstream oss; oss << MCDataStr << "::toNumPyArray : number of components of this is 0 ! Should be > 0 !";
413 throw INTERP_KERNEL::Exception(oss.str().c_str());
415 int nbDims=nbComp==1?1:2;
417 dim[0]=(npy_intp)nbTuples; dim[1]=nbComp;
418 const T *bg=self->getConstPointer();
419 PyObject *ret(PyArray_SimpleNewFromData(nbDims,dim,npyObjectType,const_cast<T *>(bg)));
420 if(mem.isDeallocatorCalled())
422 if(mem.getDeallocator()!=numarrdeal)
423 {// case for the first call of toNumPyArray
424 PyObject *ref(PyWeakref_NewRef(ret,NULL));
425 typename ParaMEDMEM::MemArray<T>::Deallocator tmp(mem.getDeallocator());
426 void **tmp2 = reinterpret_cast<void**>(&tmp); // MSVC2010 does not support constructor()
427 void **objs=new void *[2]; objs[0]=reinterpret_cast<void*>(ref); objs[1]=*tmp2;
428 mem.setParameterForDeallocator(objs);
429 mem.setSpecificDeallocator(numarrdeal);
433 {// case for the second and other call of toNumPyArray
434 void **objs=(void **)mem.getParameterForDeallocator();
435 PyObject *weakRefOnOwner=(PyObject *)objs[0];
436 PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
438 {//the previous numArray exists let numpy deals the numpy array each other by declaring the still alive instance as base
440 NumpyArrSetBaseObjectExt((PyArrayObject*)ret,obj);
443 {//the previous numArray no more exists -> declare the newly created numpy array as the first one.
444 Py_XDECREF(weakRefOnOwner);
445 PyObject *ref=PyWeakref_NewRef(ret,NULL);
453 template<class MCData, class T>
454 PyObject *ToNumPyArray(MCData *self, int npyObjectType, const char *MCDataStr)
456 return ToNumPyArrayUnderground<MCData,T>(self,npyObjectType,MCDataStr,self->getNumberOfTuples(),self->getNumberOfComponents());
459 SWIGINTERN PyObject *ParaMEDMEM_DataArrayInt_toNumPyArray(ParaMEDMEM::DataArrayInt *self);
460 SWIGINTERN PyObject *ParaMEDMEM_DataArrayDouble_toNumPyArray(ParaMEDMEM::DataArrayDouble *self);
462 PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) throw(INTERP_KERNEL::Exception)
464 int nbRows((int)m.size());
465 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayInt> indPtr(ParaMEDMEM::DataArrayInt::New()),indices(ParaMEDMEM::DataArrayInt::New());
466 ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<ParaMEDMEM::DataArrayDouble> data(ParaMEDMEM::DataArrayDouble::New());
467 indPtr->alloc(nbRows+1,1);
468 int *intPtr_ptr(indPtr->getPointer()); intPtr_ptr[0]=0; intPtr_ptr++;
470 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++,intPtr_ptr++)
472 sz2+=(int)(*it0).size();
475 indices->alloc(sz2,1); data->alloc(sz2,1);
476 int *indices_ptr(indices->getPointer());
477 double *data_ptr(data->getPointer());
478 for(std::vector<std::map<int,double> >::const_iterator it0=m.begin();it0!=m.end();it0++)
479 for(std::map<int,double>::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++,indices_ptr++,data_ptr++)
481 *indices_ptr=(*it1).first;
482 *data_ptr=(*it1).second;
484 PyObject *a(ParaMEDMEM_DataArrayDouble_toNumPyArray(data)),*b(ParaMEDMEM_DataArrayInt_toNumPyArray(indices)),*c(ParaMEDMEM_DataArrayInt_toNumPyArray(indPtr));
486 PyObject *args(PyTuple_New(1)),*args0(PyTuple_New(3)),*kw(PyDict_New()),*kw1(PyTuple_New(2));
487 PyTuple_SetItem(args0,0,a); PyTuple_SetItem(args0,1,b); PyTuple_SetItem(args0,2,c); PyTuple_SetItem(args,0,args0);
488 PyTuple_SetItem(kw1,0,PyInt_FromLong(nbRows)); PyTuple_SetItem(kw1,1,PyInt_FromLong(nbCols));
489 PyObject *tmp1(PyString_FromString("shape"));
490 PyDict_SetItem(kw,tmp1,kw1); Py_DECREF(tmp1); Py_DECREF(kw1);
491 PyObject* pdict=PyDict_New();
492 PyDict_SetItemString(pdict, "__builtins__", PyEval_GetBuiltins());
493 PyObject *tmp(PyRun_String("from scipy.sparse import csr_matrix", Py_single_input, pdict, pdict));
495 throw INTERP_KERNEL::Exception("Problem during loading csr_matrix in scipy.sparse ! Is Scipy module available in present ?");
496 PyObject *csrMatrixCls=PyDict_GetItemString(pdict,"csr_matrix");
498 throw INTERP_KERNEL::Exception("csr_matrix not found in scipy.sparse ! Is Scipy module available in present ?");
499 PyObject *ret(PyObject_Call(csrMatrixCls,args,kw));
500 Py_DECREF(pdict); Py_XDECREF(tmp); Py_DECREF(args); Py_DECREF(kw);
506 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
514 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
515 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
516 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
517 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
519 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
523 static PyObject *convertDataArray(ParaMEDMEM::DataArray *dac, int owner) throw(INTERP_KERNEL::Exception)
531 if(dynamic_cast<ParaMEDMEM::DataArrayDouble *>(dac))
532 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,owner);
533 if(dynamic_cast<ParaMEDMEM::DataArrayInt *>(dac))
534 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,owner);
535 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
536 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
537 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
538 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
540 throw INTERP_KERNEL::Exception("Not recognized type of DataArray on downcast !");
544 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
546 PyObject *ret=PyList_New(size);
547 for(int i=0;i<size;i++)
548 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
552 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
555 PyObject *ret=PyList_New(size);
556 for(int i=0;i<size;i++)
557 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
561 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
564 PyObject *ret=PyList_New(size);
565 std::set<int>::const_iterator it=v.begin();
566 for(int i=0;i<size;i++,it++)
567 PyList_SetItem(ret,i,PyInt_FromLong(*it));
571 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
573 PyObject *ret=PyList_New(nbOfTuples);
574 for(int i=0;i<nbOfTuples;i++)
576 PyObject *t=PyTuple_New(nbOfComp);
577 for(int j=0;j<nbOfComp;j++)
578 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
579 PyList_SetItem(ret,i,t);
584 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
586 if(PyList_Check(pyLi))
588 *size=PyList_Size(pyLi);
589 int *tmp=new int[*size];
590 for(int i=0;i<*size;i++)
592 PyObject *o=PyList_GetItem(pyLi,i);
595 int val=(int)PyInt_AS_LONG(o);
601 throw INTERP_KERNEL::Exception("list must contain integers only");
606 else if(PyTuple_Check(pyLi))
608 *size=PyTuple_Size(pyLi);
609 int *tmp=new int[*size];
610 for(int i=0;i<*size;i++)
612 PyObject *o=PyTuple_GetItem(pyLi,i);
615 int val=(int)PyInt_AS_LONG(o);
621 throw INTERP_KERNEL::Exception("tuple must contain integers only");
628 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
632 static PyObject *convertFromVectorPairInt(const std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
634 PyObject *ret=PyList_New(arr.size());
635 for(std::size_t i=0;i<arr.size();i++)
637 PyObject *t=PyTuple_New(2);
638 PyTuple_SetItem(t,0,PyInt_FromLong(arr[i].first));
639 PyTuple_SetItem(t,1,PyInt_FromLong(arr[i].second));
640 PyList_SetItem(ret,i,t);
645 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
647 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
648 if(PyList_Check(pyLi))
650 int size=PyList_Size(pyLi);
652 for(int i=0;i<size;i++)
654 PyObject *o=PyList_GetItem(pyLi,i);
657 int sz2=PyTuple_Size(o);
659 throw INTERP_KERNEL::Exception(msg);
660 PyObject *o_0=PyTuple_GetItem(o,0);
661 if(!PyInt_Check(o_0))
662 throw INTERP_KERNEL::Exception(msg);
663 PyObject *o_1=PyTuple_GetItem(o,1);
664 if(!PyInt_Check(o_1))
665 throw INTERP_KERNEL::Exception(msg);
666 arr[i].first=(int)PyInt_AS_LONG(o_0);
667 arr[i].second=(int)PyInt_AS_LONG(o_1);
670 throw INTERP_KERNEL::Exception(msg);
673 else if(PyTuple_Check(pyLi))
675 int size=PyTuple_Size(pyLi);
677 for(int i=0;i<size;i++)
679 PyObject *o=PyTuple_GetItem(pyLi,i);
682 int sz2=PyTuple_Size(o);
684 throw INTERP_KERNEL::Exception(msg);
685 PyObject *o_0=PyTuple_GetItem(o,0);
686 if(!PyInt_Check(o_0))
687 throw INTERP_KERNEL::Exception(msg);
688 PyObject *o_1=PyTuple_GetItem(o,1);
689 if(!PyInt_Check(o_1))
690 throw INTERP_KERNEL::Exception(msg);
691 arr[i].first=(int)PyInt_AS_LONG(o_0);
692 arr[i].second=(int)PyInt_AS_LONG(o_1);
695 throw INTERP_KERNEL::Exception(msg);
699 throw INTERP_KERNEL::Exception(msg);
702 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
704 if(PyList_Check(pyLi))
706 int size=PyList_Size(pyLi);
708 for(int i=0;i<size;i++)
710 PyObject *o=PyList_GetItem(pyLi,i);
713 int val=(int)PyInt_AS_LONG(o);
717 throw INTERP_KERNEL::Exception("list must contain integers only");
720 else if(PyTuple_Check(pyLi))
722 int size=PyTuple_Size(pyLi);
724 for(int i=0;i<size;i++)
726 PyObject *o=PyTuple_GetItem(pyLi,i);
729 int val=(int)PyInt_AS_LONG(o);
733 throw INTERP_KERNEL::Exception("tuple must contain integers only");
738 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
742 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
745 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
747 if(PyList_Check(pyLi))
749 int size=PyList_Size(pyLi);
750 for(int i=0;i<size;i++)
752 PyObject *o=PyList_GetItem(pyLi,i);
755 int val=(int)PyInt_AS_LONG(o);
760 std::vector<int> arr2;
761 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
762 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
764 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
765 throw INTERP_KERNEL::Exception(oss.str().c_str());
767 arr.insert(arr.end(),arr2.begin(),arr2.end());
771 else if(PyTuple_Check(pyLi))
773 int size=PyTuple_Size(pyLi);
774 for(int i=0;i<size;i++)
776 PyObject *o=PyTuple_GetItem(pyLi,i);
779 int val=(int)PyInt_AS_LONG(o);
784 std::vector<int> arr2;
785 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
786 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
788 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
789 throw INTERP_KERNEL::Exception(oss.str().c_str());
791 arr.insert(arr.end(),arr2.begin(),arr2.end());
796 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
799 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
803 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
804 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
806 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
807 oss << " whereas nb of components expected is " << nbOfComp << " !";
808 throw INTERP_KERNEL::Exception(oss.str().c_str());
815 if((nbOfTuples!=size1 || nbOfComp!=size2))
817 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
819 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
820 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
821 throw INTERP_KERNEL::Exception(oss.str().c_str());
827 if(nbOfTuples==size1)
831 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
832 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
833 throw INTERP_KERNEL::Exception(oss.str().c_str());
839 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
841 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
842 if(PyInt_Check(pyLi))
844 long val=PyInt_AS_LONG(pyLi);
849 throw INTERP_KERNEL::Exception(MSG);
852 else if(PyList_Check(pyLi))
854 int size=PyList_Size(pyLi);
856 for(int i=0;i<size;i++)
858 PyObject *o=PyList_GetItem(pyLi,i);
860 fillArrayWithPyListInt3(o,tmp1,ret);
868 throw INTERP_KERNEL::Exception(MSG);
871 else if(PyTuple_Check(pyLi))
873 int size=PyTuple_Size(pyLi);
875 for(int i=0;i<size;i++)
877 PyObject *o=PyTuple_GetItem(pyLi,i);
879 fillArrayWithPyListInt3(o,tmp1,ret);
887 throw INTERP_KERNEL::Exception(MSG);
891 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
894 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
896 std::vector<int> ret;
897 int size1=-1,size2=-1;
898 if(PyList_Check(pyLi))
900 size1=PyList_Size(pyLi);
901 for(int i=0;i<size1;i++)
903 PyObject *o=PyList_GetItem(pyLi,i);
904 fillArrayWithPyListInt3(o,size2,ret);
909 else if(PyTuple_Check(pyLi))
911 size1=PyTuple_Size(pyLi);
912 for(int i=0;i<size1;i++)
914 PyObject *o=PyTuple_GetItem(pyLi,i);
915 fillArrayWithPyListInt3(o,size2,ret);
921 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
923 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
927 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
929 if(PyList_Check(pyLi))
931 Py_ssize_t sz=PyList_Size(pyLi);
933 for(int i=0;i<sz;i++)
935 PyObject *o=PyList_GetItem(pyLi,i);
936 if(PyString_Check(o))
937 vec[i]=PyString_AsString(o);
943 else if(PyTuple_Check(pyLi))
945 Py_ssize_t sz=PyTuple_Size(pyLi);
947 for(int i=0;i<sz;i++)
949 PyObject *o=PyTuple_GetItem(pyLi,i);
950 if(PyString_Check(o))
951 vec[i]=PyString_AsString(o);
961 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
963 PyObject *ret=PyList_New(size);
964 for(int i=0;i<size;i++)
965 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
969 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
972 PyObject *ret=PyList_New(size);
973 for(int i=0;i<size;i++)
974 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
978 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
980 PyObject *ret=PyList_New(nbOfTuples);
981 for(int i=0;i<nbOfTuples;i++)
983 PyObject *t=PyTuple_New(nbOfComp);
984 for(int j=0;j<nbOfComp;j++)
985 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
986 PyList_SetItem(ret,i,t);
991 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
993 PyObject *ret=PyList_New(nbOfTuples);
994 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
995 for(int i=0;i<nbOfTuples;i++)
997 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
998 PyList_SetItem(ret,i,PyString_FromString(tmp));
1003 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
1005 if(PyList_Check(pyLi))
1007 *size=PyList_Size(pyLi);
1008 double *tmp=(double *)malloc((*size)*sizeof(double));
1009 for(int i=0;i<*size;i++)
1011 PyObject *o=PyList_GetItem(pyLi,i);
1012 if(PyFloat_Check(o))
1014 double val=PyFloat_AS_DOUBLE(o);
1017 else if(PyInt_Check(o))
1019 long val0=PyInt_AS_LONG(o);
1026 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
1031 else if(PyTuple_Check(pyLi))
1033 *size=PyTuple_Size(pyLi);
1034 double *tmp=(double *)malloc((*size)*sizeof(double));
1035 for(int i=0;i<*size;i++)
1037 PyObject *o=PyTuple_GetItem(pyLi,i);
1038 if(PyFloat_Check(o))
1040 double val=PyFloat_AS_DOUBLE(o);
1043 else if(PyInt_Check(o))
1045 long val0=PyInt_AS_LONG(o);
1052 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
1058 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
1061 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
1063 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
1064 if(PyFloat_Check(pyLi))
1070 throw INTERP_KERNEL::Exception(MSG);
1071 double val=PyFloat_AS_DOUBLE(pyLi);
1074 else if(PyInt_Check(pyLi))
1076 long val0=PyInt_AS_LONG(pyLi);
1082 throw INTERP_KERNEL::Exception(MSG);
1085 else if(PyList_Check(pyLi))
1087 int size=PyList_Size(pyLi);
1089 for(int i=0;i<size;i++)
1091 PyObject *o=PyList_GetItem(pyLi,i);
1093 fillArrayWithPyListDbl3(o,tmp1,ret);
1101 throw INTERP_KERNEL::Exception(MSG);
1104 else if(PyTuple_Check(pyLi))
1106 int size=PyTuple_Size(pyLi);
1108 for(int i=0;i<size;i++)
1110 PyObject *o=PyTuple_GetItem(pyLi,i);
1112 fillArrayWithPyListDbl3(o,tmp1,ret);
1120 throw INTERP_KERNEL::Exception(MSG);
1124 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
1127 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
1129 std::vector<double> ret;
1130 int size1=-1,size2=-1;
1131 if(PyList_Check(pyLi))
1133 size1=PyList_Size(pyLi);
1134 for(int i=0;i<size1;i++)
1136 PyObject *o=PyList_GetItem(pyLi,i);
1137 fillArrayWithPyListDbl3(o,size2,ret);
1142 else if(PyTuple_Check(pyLi))
1144 size1=PyTuple_Size(pyLi);
1145 for(int i=0;i<size1;i++)
1147 PyObject *o=PyTuple_GetItem(pyLi,i);
1148 fillArrayWithPyListDbl3(o,size2,ret);
1154 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
1156 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
1160 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
1162 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
1165 if(PyList_Check(pyLi))
1167 int size=PyList_Size(pyLi);
1169 for(int i=0;i<size;i++)
1171 PyObject *obj=PyList_GetItem(pyLi,i);
1172 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1173 if(!SWIG_IsOK(status))
1175 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : list is excepted to contain only " << typeStr << " instances !";
1176 throw INTERP_KERNEL::Exception(oss.str().c_str());
1178 T arg=reinterpret_cast< T >(argp);
1182 else if(PyTuple_Check(pyLi))
1184 int size=PyTuple_Size(pyLi);
1186 for(int i=0;i<size;i++)
1188 PyObject *obj=PyTuple_GetItem(pyLi,i);
1189 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
1190 if(!SWIG_IsOK(status))
1192 std::ostringstream oss; oss << "convertFromPyObjVectorOfObj : tuple is excepted to contain only " << typeStr << " instances !";
1193 throw INTERP_KERNEL::Exception(oss.str().c_str());
1195 T arg=reinterpret_cast< T >(argp);
1199 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
1202 T arg=reinterpret_cast< T >(argp);
1206 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
1210 * if python int -> cpp int sw=1
1211 * if python list[int] -> cpp vector<int> sw=2
1212 * if python tuple[int] -> cpp vector<int> sw=2
1213 * if python DataArrayInt -> cpp DataArrayInt sw=3
1214 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1216 * switch between (int,vector<int>,DataArrayInt)
1218 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
1221 if(PyInt_Check(value))
1223 iTyypp=(int)PyInt_AS_LONG(value);
1227 if(PyTuple_Check(value))
1229 int size=PyTuple_Size(value);
1230 stdvecTyypp.resize(size);
1231 for(int i=0;i<size;i++)
1233 PyObject *o=PyTuple_GetItem(value,i);
1235 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1238 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1239 throw INTERP_KERNEL::Exception(oss.str().c_str());
1245 if(PyList_Check(value))
1247 int size=PyList_Size(value);
1248 stdvecTyypp.resize(size);
1249 for(int i=0;i<size;i++)
1251 PyObject *o=PyList_GetItem(value,i);
1253 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1256 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1257 throw INTERP_KERNEL::Exception(oss.str().c_str());
1264 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1265 if(SWIG_IsOK(status))
1267 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1271 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1272 if(SWIG_IsOK(status))
1274 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1278 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
1282 * if python double -> cpp double sw=1
1283 * if python int -> cpp double sw=1
1284 * if python list[double] -> cpp vector<double> sw=2
1285 * if python list[int] -> cpp vector<double> sw=2
1286 * if python tuple[double] -> cpp vector<double> sw=2
1287 * if python tuple[int] -> cpp vector<double> sw=2
1288 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
1290 * switch between (int,vector<int>,DataArrayInt)
1292 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1295 if(PyFloat_Check(value))
1297 iTyypp=PyFloat_AS_DOUBLE(value);
1301 if(PyInt_Check(value))
1303 iTyypp=(double)PyInt_AS_LONG(value);
1307 if(PyTuple_Check(value))
1309 int size=PyTuple_Size(value);
1310 stdvecTyypp.resize(size);
1311 for(int i=0;i<size;i++)
1313 PyObject *o=PyTuple_GetItem(value,i);
1314 if(PyFloat_Check(o))
1315 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1316 else if(PyInt_Check(o))
1317 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1320 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1321 throw INTERP_KERNEL::Exception(oss.str().c_str());
1327 if(PyList_Check(value))
1329 int size=PyList_Size(value);
1330 stdvecTyypp.resize(size);
1331 for(int i=0;i<size;i++)
1333 PyObject *o=PyList_GetItem(value,i);
1334 if(PyFloat_Check(o))
1335 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1336 else if(PyInt_Check(o))
1337 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1340 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1341 throw INTERP_KERNEL::Exception(oss.str().c_str());
1348 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1349 if(!SWIG_IsOK(status))
1350 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
1351 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1356 * if python double -> cpp double sw=1
1357 * if python int -> cpp double sw=1
1358 * if python list[double] -> cpp vector<double> sw=2
1359 * if python list[int] -> cpp vector<double> sw=2
1360 * if python tuple[double] -> cpp vector<double> sw=2
1361 * if python tuple[int] -> cpp vector<double> sw=2
1362 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1364 * switch between (int,vector<int>,DataArrayInt)
1366 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
1369 if(PyFloat_Check(value))
1371 iTyypp=PyFloat_AS_DOUBLE(value);
1375 if(PyInt_Check(value))
1377 iTyypp=(double)PyInt_AS_LONG(value);
1381 if(PyTuple_Check(value))
1383 int size=PyTuple_Size(value);
1384 stdvecTyypp.resize(size);
1385 for(int i=0;i<size;i++)
1387 PyObject *o=PyTuple_GetItem(value,i);
1388 if(PyFloat_Check(o))
1389 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1390 else if(PyInt_Check(o))
1391 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1394 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1395 throw INTERP_KERNEL::Exception(oss.str().c_str());
1401 if(PyList_Check(value))
1403 int size=PyList_Size(value);
1404 stdvecTyypp.resize(size);
1405 for(int i=0;i<size;i++)
1407 PyObject *o=PyList_GetItem(value,i);
1408 if(PyFloat_Check(o))
1409 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1410 else if(PyInt_Check(o))
1411 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1414 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1415 throw INTERP_KERNEL::Exception(oss.str().c_str());
1422 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1423 if(!SWIG_IsOK(status))
1424 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1425 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1430 * if python int -> cpp int sw=1
1431 * if python list[int] -> cpp vector<int> sw=2
1432 * if python tuple[int] -> cpp vector<int> sw=2
1433 * if python slicp -> cpp pair sw=3 (begin,end,step)
1434 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
1436 * switch between (int,vector<int>,DataArrayInt)
1438 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)
1440 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1442 if(PyInt_Check(value))
1444 iTyypp=(int)PyInt_AS_LONG(value);
1448 if(PyTuple_Check(value))
1450 int size=PyTuple_Size(value);
1451 stdvecTyypp.resize(size);
1452 for(int i=0;i<size;i++)
1454 PyObject *o=PyTuple_GetItem(value,i);
1456 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1459 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1460 throw INTERP_KERNEL::Exception(oss.str().c_str());
1466 if(PyList_Check(value))
1468 int size=PyList_Size(value);
1469 stdvecTyypp.resize(size);
1470 for(int i=0;i<size;i++)
1472 PyObject *o=PyList_GetItem(value,i);
1474 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1477 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1478 throw INTERP_KERNEL::Exception(oss.str().c_str());
1484 if(PySlice_Check(value))
1486 Py_ssize_t strt=2,stp=2,step=2;
1487 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1488 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1491 p.second.second=step;
1496 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1497 if(SWIG_IsOK(status))
1499 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1502 std::ostringstream oss; oss << msg << " Instance in null !";
1503 throw INTERP_KERNEL::Exception(oss.str().c_str());
1508 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1509 if(SWIG_IsOK(status))
1511 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1514 std::ostringstream oss; oss << msg << " Instance in null !";
1515 throw INTERP_KERNEL::Exception(oss.str().c_str());
1517 stdvecTyypp.resize(tmp->getNumberOfCompo());
1518 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1522 throw INTERP_KERNEL::Exception(msg);
1526 * Idem than convertObjToPossibleCpp2
1528 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)
1530 convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
1533 iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
1538 * if python int -> cpp int sw=1
1539 * if python tuple[int] -> cpp vector<int> sw=2
1540 * if python list[int] -> cpp vector<int> sw=2
1541 * if python slice -> cpp pair sw=3
1542 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1544 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)
1547 if(PyInt_Check(value))
1549 iTyypp=(int)PyInt_AS_LONG(value);
1553 if(PyTuple_Check(value))
1555 int size=PyTuple_Size(value);
1556 stdvecTyypp.resize(size);
1557 for(int i=0;i<size;i++)
1559 PyObject *o=PyTuple_GetItem(value,i);
1561 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1564 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1571 if(PyList_Check(value))
1573 int size=PyList_Size(value);
1574 stdvecTyypp.resize(size);
1575 for(int i=0;i<size;i++)
1577 PyObject *o=PyList_GetItem(value,i);
1579 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1582 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1583 throw INTERP_KERNEL::Exception(oss.str().c_str());
1589 if(PySlice_Check(value))
1591 Py_ssize_t strt=2,stp=2,step=2;
1592 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1593 GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
1596 p.second.second=step;
1601 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1602 if(!SWIG_IsOK(status))
1603 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1604 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1609 * if python string with size one -> cpp char sw=1
1610 * if python string with size different from one -> cpp string sw=2
1611 * if python tuple[string] or list[string] -> vector<string> sw=3
1612 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1613 * switch between (int,string,vector<string>,DataArrayChar)
1615 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1617 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1619 if(PyString_Check(value))
1621 const char *pt=PyString_AsString(value);
1622 Py_ssize_t sz=PyString_Size(value);
1636 if(PyTuple_Check(value))
1638 int size=PyTuple_Size(value);
1639 vsType.resize(size);
1640 for(int i=0;i<size;i++)
1642 PyObject *o=PyTuple_GetItem(value,i);
1643 if(PyString_Check(o))
1644 vsType[i]=PyString_AsString(o);
1647 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1648 throw INTERP_KERNEL::Exception(oss.str().c_str());
1654 if(PyList_Check(value))
1656 int size=PyList_Size(value);
1657 vsType.resize(size);
1658 for(int i=0;i<size;i++)
1660 PyObject *o=PyList_GetItem(value,i);
1661 if(PyString_Check(o))
1662 vsType[i]=PyString_AsString(o);
1665 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1666 throw INTERP_KERNEL::Exception(oss.str().c_str());
1673 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1674 if(SWIG_IsOK(status))
1676 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1679 std::ostringstream oss; oss << msg << " Instance in null !";
1680 throw INTERP_KERNEL::Exception(oss.str().c_str());
1685 throw INTERP_KERNEL::Exception(msg);
1689 * if value int -> cpp it sw=1
1690 * if value list[int] -> vt sw=2
1691 * if value tuple[int] -> vt sw=2
1692 * if value slice -> pt sw=3
1693 * if value DataArrayInt -> dt sw=4
1694 * if value tuple [int,int] -> cpp it,ip sw=5
1695 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1696 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1697 * if value tuple [slice,int] -> cpp pt,ip sw=7
1698 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1699 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1700 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1701 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1702 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1703 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1704 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1705 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1706 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1707 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1708 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1709 * if value tuple [int,slice] -> cpp it,pc sw=13
1710 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1711 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1712 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1713 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1715 * switch between (int,vector<int>,DataArrayInt)
1717 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1718 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1719 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1721 if(!PyTuple_Check(value))
1723 convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
1728 int sz=PyTuple_Size(value);
1730 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1731 PyObject *ob0=PyTuple_GetItem(value,0);
1733 convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
1734 PyObject *ob1=PyTuple_GetItem(value,1);
1735 convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
1741 * if value int -> cpp val sw=1
1742 * if value double -> cpp val sw=1
1743 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1744 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1745 * if value list[int,double] -> cpp std::vector<double> sw=4
1746 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1748 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1751 if(PyFloat_Check(value))
1753 val=PyFloat_AS_DOUBLE(value);
1757 if(PyInt_Check(value))
1759 val=(double)PyInt_AS_LONG(value);
1763 if(PyTuple_Check(value))
1765 int size=PyTuple_Size(value);
1767 for(int i=0;i<size;i++)
1769 PyObject *o=PyTuple_GetItem(value,i);
1770 if(PyFloat_Check(o))
1771 f[i]=PyFloat_AS_DOUBLE(o);
1772 else if(PyInt_Check(o))
1773 f[i]=(double)PyInt_AS_LONG(o);
1776 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1777 throw INTERP_KERNEL::Exception(oss.str().c_str());
1783 if(PyList_Check(value))
1785 int size=PyList_Size(value);
1787 for(int i=0;i<size;i++)
1789 PyObject *o=PyList_GetItem(value,i);
1790 if(PyFloat_Check(o))
1791 f[i]=PyFloat_AS_DOUBLE(o);
1792 else if(PyInt_Check(o))
1793 f[i]=(double)PyInt_AS_LONG(o);
1796 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1797 throw INTERP_KERNEL::Exception(oss.str().c_str());
1804 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1805 if(SWIG_IsOK(status))
1807 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1811 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1812 if(SWIG_IsOK(status))
1814 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1818 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1822 * if value int -> cpp val sw=1
1823 * if value double -> cpp val sw=1
1824 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1825 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1826 * if value list[int,double] -> cpp std::vector<double> sw=4
1827 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1829 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1830 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1833 if(PyFloat_Check(value))
1835 val=PyFloat_AS_DOUBLE(value);
1837 if(nbTuplesExpected*nbCompExpected!=1)
1839 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1840 throw INTERP_KERNEL::Exception(oss.str().c_str());
1844 if(PyInt_Check(value))
1846 val=(double)PyInt_AS_LONG(value);
1848 if(nbTuplesExpected*nbCompExpected!=1)
1850 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1851 throw INTERP_KERNEL::Exception(oss.str().c_str());
1855 if(PyTuple_Check(value) || PyList_Check(value))
1859 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1860 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1865 catch(INTERP_KERNEL::Exception& exc) { throw exc; }
1868 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1869 if(SWIG_IsOK(status))
1871 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1875 if(d->getNumberOfTuples()==nbTuplesExpected)
1877 if(d->getNumberOfComponents()==nbCompExpected)
1879 return d->getConstPointer();
1883 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1884 throw INTERP_KERNEL::Exception(oss.str().c_str());
1889 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1890 throw INTERP_KERNEL::Exception(oss.str().c_str());
1897 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1898 throw INTERP_KERNEL::Exception(oss.str().c_str());
1904 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1905 if(SWIG_IsOK(status))
1907 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1909 if(e->getNumberOfCompo()==nbCompExpected)
1911 if(nbTuplesExpected==1)
1912 return e->getConstPointer();
1915 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1916 throw INTERP_KERNEL::Exception(oss.str().c_str());
1921 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1922 throw INTERP_KERNEL::Exception(oss.str().c_str());
1925 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1929 * if value int -> cpp val sw=1
1930 * if value double -> cpp val sw=1
1931 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1932 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1933 * if value list[int,double] -> cpp std::vector<double> sw=4
1934 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1936 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1937 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1940 if(PyFloat_Check(value))
1942 val=PyFloat_AS_DOUBLE(value);
1944 if(nbCompExpected!=1)
1946 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1947 throw INTERP_KERNEL::Exception(oss.str().c_str());
1952 if(PyInt_Check(value))
1954 val=(double)PyInt_AS_LONG(value);
1956 if(nbCompExpected!=1)
1958 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1959 throw INTERP_KERNEL::Exception(oss.str().c_str());
1964 if(PyTuple_Check(value))
1966 int size=PyTuple_Size(value);
1968 for(int i=0;i<size;i++)
1970 PyObject *o=PyTuple_GetItem(value,i);
1971 if(PyFloat_Check(o))
1972 f[i]=PyFloat_AS_DOUBLE(o);
1973 else if(PyInt_Check(o))
1974 f[i]=(double)PyInt_AS_LONG(o);
1977 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1978 throw INTERP_KERNEL::Exception(oss.str().c_str());
1982 if(size%nbCompExpected!=0)
1984 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1985 throw INTERP_KERNEL::Exception(oss.str().c_str());
1987 nbTuples=size/nbCompExpected;
1990 if(PyList_Check(value))
1992 int size=PyList_Size(value);
1994 for(int i=0;i<size;i++)
1996 PyObject *o=PyList_GetItem(value,i);
1997 if(PyFloat_Check(o))
1998 f[i]=PyFloat_AS_DOUBLE(o);
1999 else if(PyInt_Check(o))
2000 f[i]=(double)PyInt_AS_LONG(o);
2003 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2004 throw INTERP_KERNEL::Exception(oss.str().c_str());
2008 if(size%nbCompExpected!=0)
2010 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
2011 throw INTERP_KERNEL::Exception(oss.str().c_str());
2013 nbTuples=size/nbCompExpected;
2017 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2018 if(SWIG_IsOK(status))
2020 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2024 if(d->getNumberOfComponents()==nbCompExpected)
2026 nbTuples=d->getNumberOfTuples();
2027 return d->getConstPointer();
2031 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
2032 throw INTERP_KERNEL::Exception(oss.str().c_str());
2039 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2040 throw INTERP_KERNEL::Exception(oss.str().c_str());
2043 { nbTuples=0; return 0; }
2046 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2047 if(SWIG_IsOK(status))
2049 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2053 if(e->getNumberOfCompo()==nbCompExpected)
2056 return e->getConstPointer();
2060 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
2061 throw INTERP_KERNEL::Exception(oss.str().c_str());
2068 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2069 throw INTERP_KERNEL::Exception(oss.str().c_str());
2072 { nbTuples=0; return 0; }
2075 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2079 * if value int -> cpp val sw=1
2080 * if value double -> cpp val sw=1
2081 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
2082 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
2083 * if value list[int,double] -> cpp std::vector<double> sw=4
2084 * if value tuple[int,double] -> cpp std::vector<double> sw=4
2086 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
2087 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
2089 ParaMEDMEM::DataArrayDouble *d=0;
2090 ParaMEDMEM::DataArrayDoubleTuple *e=0;
2092 if(PyFloat_Check(value))
2094 val=PyFloat_AS_DOUBLE(value);
2099 if(PyInt_Check(value))
2101 val=(double)PyInt_AS_LONG(value);
2106 if(PyTuple_Check(value))
2108 int size=PyTuple_Size(value);
2110 for(int i=0;i<size;i++)
2112 PyObject *o=PyTuple_GetItem(value,i);
2113 if(PyFloat_Check(o))
2114 f[i]=PyFloat_AS_DOUBLE(o);
2115 else if(PyInt_Check(o))
2116 f[i]=(double)PyInt_AS_LONG(o);
2119 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
2120 throw INTERP_KERNEL::Exception(oss.str().c_str());
2127 if(PyList_Check(value))
2129 int size=PyList_Size(value);
2131 for(int i=0;i<size;i++)
2133 PyObject *o=PyList_GetItem(value,i);
2134 if(PyFloat_Check(o))
2135 f[i]=PyFloat_AS_DOUBLE(o);
2136 else if(PyInt_Check(o))
2137 f[i]=(double)PyInt_AS_LONG(o);
2140 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
2141 throw INTERP_KERNEL::Exception(oss.str().c_str());
2149 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2150 if(SWIG_IsOK(status))
2152 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
2156 if(d->getNumberOfComponents()==1)
2158 nbTuples=d->getNumberOfTuples();
2159 return d->getConstPointer();
2163 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
2164 throw INTERP_KERNEL::Exception(oss.str().c_str());
2171 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2172 throw INTERP_KERNEL::Exception(oss.str().c_str());
2175 { nbTuples=0; return 0; }
2178 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
2179 if(SWIG_IsOK(status))
2181 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
2185 nbTuples=e->getNumberOfCompo();
2186 return e->getConstPointer();
2192 std::ostringstream oss; oss << msg << " null pointer not accepted!";
2193 throw INTERP_KERNEL::Exception(oss.str().c_str());
2196 { nbTuples=0; return 0; }
2199 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
2203 * if python int -> cpp int sw=1
2204 * if python list[int] -> cpp vector<int> sw=2
2205 * if python tuple[int] -> cpp vector<int> sw=2
2206 * if python DataArrayInt -> cpp DataArrayInt sw=3
2207 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
2209 * switch between (int,vector<int>,DataArrayInt)
2211 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
2214 if(PyInt_Check(value))
2216 iTyypp=(int)PyInt_AS_LONG(value);
2220 if(PyTuple_Check(value))
2222 int size=PyTuple_Size(value);
2223 stdvecTyypp.resize(size);
2224 for(int i=0;i<size;i++)
2226 PyObject *o=PyTuple_GetItem(value,i);
2228 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2231 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
2232 throw INTERP_KERNEL::Exception(oss.str().c_str());
2236 return &stdvecTyypp[0];
2238 if(PyList_Check(value))
2240 int size=PyList_Size(value);
2241 stdvecTyypp.resize(size);
2242 for(int i=0;i<size;i++)
2244 PyObject *o=PyList_GetItem(value,i);
2246 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
2249 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
2250 throw INTERP_KERNEL::Exception(oss.str().c_str());
2254 return &stdvecTyypp[0];
2257 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2258 if(SWIG_IsOK(status))
2260 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
2263 sw=3; sz=daIntTyypp->getNbOfElems();
2264 return daIntTyypp->begin();
2272 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
2273 if(SWIG_IsOK(status))
2275 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
2276 sw=4; sz=daIntTuple->getNumberOfCompo();
2277 return daIntTuple->getConstPointer();
2279 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
2282 static ParaMEDMEM::DataArray *CheckAndRetrieveDataArrayInstance(PyObject *obj, const char *msg)
2285 int status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArray,0|0);
2286 if(!SWIG_IsOK(status))
2288 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
2289 if(!SWIG_IsOK(status))
2291 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
2292 if(!SWIG_IsOK(status))
2294 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,0|0);
2295 if(!SWIG_IsOK(status))
2297 status=SWIG_ConvertPtr(obj,&aBasePtrVS,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,0|0);
2298 std::ostringstream oss; oss << msg << " ! Accepted instances are DataArrayDouble, DataArrayInt, DataArrayAsciiChar, DataArrayByte !";
2299 throw INTERP_KERNEL::Exception(oss.str().c_str());
2304 return reinterpret_cast< ParaMEDMEM::DataArray * >(aBasePtrVS);