1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <numpy/arrayobject.h>
24 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
27 if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
28 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
29 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
30 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
31 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
32 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
34 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
38 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
41 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
42 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
43 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
44 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
45 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
46 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
47 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
48 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
49 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
50 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
52 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
56 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
59 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
60 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
62 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
66 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
69 PyObject *ret=PyList_New(size);
70 for(int i=0;i<size;i++)
71 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
74 npy_intp dim = (npy_intp) size;
75 int *tmp=new int[size];
76 std::copy(ptr,ptr+size,tmp);
77 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,const_cast<int *>(tmp));
81 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
85 PyObject *ret=PyList_New(size);
86 for(int i=0;i<size;i++)
87 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
90 npy_intp dim = (npy_intp) v.size();
91 int *tmp=new int[v.size()];
92 std::copy(v.begin(),v.end(),tmp);
93 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,tmp);
97 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
100 PyObject *ret=PyList_New(size);
101 std::set<int>::const_iterator it=v.begin();
102 for(int i=0;i<size;i++,it++)
103 PyList_SetItem(ret,i,PyInt_FromLong(*it));
107 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
109 PyObject *ret=PyList_New(nbOfTuples);
110 for(int i=0;i<nbOfTuples;i++)
112 PyObject *t=PyTuple_New(nbOfComp);
113 for(int j=0;j<nbOfComp;j++)
114 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
115 PyList_SetItem(ret,i,t);
120 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
122 if(PyList_Check(pyLi))
124 *size=PyList_Size(pyLi);
125 int *tmp=new int[*size];
126 for(int i=0;i<*size;i++)
128 PyObject *o=PyList_GetItem(pyLi,i);
131 int val=(int)PyInt_AS_LONG(o);
137 throw INTERP_KERNEL::Exception("list must contain integers only");
142 else if(PyTuple_Check(pyLi))
144 *size=PyTuple_Size(pyLi);
145 int *tmp=new int[*size];
146 for(int i=0;i<*size;i++)
148 PyObject *o=PyTuple_GetItem(pyLi,i);
151 int val=(int)PyInt_AS_LONG(o);
157 throw INTERP_KERNEL::Exception("tuple must contain integers only");
165 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
167 if(PyArray_Check(pyLi))
169 npy_intp mySize = PyArray_SIZE(pyLi);
170 int *ret=(int *)PyArray_BYTES(pyLi);
176 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
182 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
184 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
185 if(PyList_Check(pyLi))
187 int size=PyList_Size(pyLi);
189 for(int i=0;i<size;i++)
191 PyObject *o=PyList_GetItem(pyLi,i);
194 int sz2=PyTuple_Size(o);
196 throw INTERP_KERNEL::Exception(msg);
197 PyObject *o_0=PyTuple_GetItem(o,0);
198 if(!PyInt_Check(o_0))
199 throw INTERP_KERNEL::Exception(msg);
200 PyObject *o_1=PyTuple_GetItem(o,1);
201 if(!PyInt_Check(o_1))
202 throw INTERP_KERNEL::Exception(msg);
203 arr[i].first=(int)PyInt_AS_LONG(o_0);
204 arr[i].second=(int)PyInt_AS_LONG(o_1);
207 throw INTERP_KERNEL::Exception(msg);
210 else if(PyTuple_Check(pyLi))
212 int size=PyTuple_Size(pyLi);
214 for(int i=0;i<size;i++)
216 PyObject *o=PyTuple_GetItem(pyLi,i);
219 int sz2=PyTuple_Size(o);
221 throw INTERP_KERNEL::Exception(msg);
222 PyObject *o_0=PyTuple_GetItem(o,0);
223 if(!PyInt_Check(o_0))
224 throw INTERP_KERNEL::Exception(msg);
225 PyObject *o_1=PyTuple_GetItem(o,1);
226 if(!PyInt_Check(o_1))
227 throw INTERP_KERNEL::Exception(msg);
228 arr[i].first=(int)PyInt_AS_LONG(o_0);
229 arr[i].second=(int)PyInt_AS_LONG(o_1);
232 throw INTERP_KERNEL::Exception(msg);
236 throw INTERP_KERNEL::Exception(msg);
239 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
241 if(PyList_Check(pyLi))
243 int size=PyList_Size(pyLi);
245 for(int i=0;i<size;i++)
247 PyObject *o=PyList_GetItem(pyLi,i);
250 int val=(int)PyInt_AS_LONG(o);
254 throw INTERP_KERNEL::Exception("list must contain integers only");
257 else if(PyTuple_Check(pyLi))
259 int size=PyTuple_Size(pyLi);
261 for(int i=0;i<size;i++)
263 PyObject *o=PyTuple_GetItem(pyLi,i);
266 int val=(int)PyInt_AS_LONG(o);
270 throw INTERP_KERNEL::Exception("tuple must contain integers only");
276 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
278 if(PyArray_Check(pyLi))
280 npy_intp mySize = PyArray_SIZE(pyLi);
281 int *ret=(int *)PyArray_BYTES(pyLi);
283 std::copy(ret,ret+mySize,arr.begin());
287 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
292 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
295 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
297 if(PyList_Check(pyLi))
299 int size=PyList_Size(pyLi);
300 for(int i=0;i<size;i++)
302 PyObject *o=PyList_GetItem(pyLi,i);
305 int val=(int)PyInt_AS_LONG(o);
310 std::vector<int> arr2;
311 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
312 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
314 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
315 throw INTERP_KERNEL::Exception(oss.str().c_str());
317 arr.insert(arr.end(),arr2.begin(),arr2.end());
321 else if(PyTuple_Check(pyLi))
323 int size=PyTuple_Size(pyLi);
324 for(int i=0;i<size;i++)
326 PyObject *o=PyTuple_GetItem(pyLi,i);
329 int val=(int)PyInt_AS_LONG(o);
334 std::vector<int> arr2;
335 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
336 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
338 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
339 throw INTERP_KERNEL::Exception(oss.str().c_str());
341 arr.insert(arr.end(),arr2.begin(),arr2.end());
346 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
349 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
353 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
354 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
356 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
357 oss << " whereas nb of components expected is " << nbOfComp << " !";
358 throw INTERP_KERNEL::Exception(oss.str().c_str());
365 if((nbOfTuples!=size1 || nbOfComp!=size2))
367 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
369 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
370 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
371 throw INTERP_KERNEL::Exception(oss.str().c_str());
377 if(nbOfTuples==size1)
381 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
382 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
383 throw INTERP_KERNEL::Exception(oss.str().c_str());
389 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
391 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
392 if(PyInt_Check(pyLi))
394 long val=PyInt_AS_LONG(pyLi);
399 throw INTERP_KERNEL::Exception(MSG);
402 else if(PyList_Check(pyLi))
404 int size=PyList_Size(pyLi);
406 for(int i=0;i<size;i++)
408 PyObject *o=PyList_GetItem(pyLi,i);
410 fillArrayWithPyListInt3(o,tmp1,ret);
418 throw INTERP_KERNEL::Exception(MSG);
421 else if(PyTuple_Check(pyLi))
423 int size=PyTuple_Size(pyLi);
425 for(int i=0;i<size;i++)
427 PyObject *o=PyTuple_GetItem(pyLi,i);
429 fillArrayWithPyListInt3(o,tmp1,ret);
437 throw INTERP_KERNEL::Exception(MSG);
441 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
444 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
446 std::vector<int> ret;
447 int size1=-1,size2=-1;
448 if(PyList_Check(pyLi))
450 size1=PyList_Size(pyLi);
451 for(int i=0;i<size1;i++)
453 PyObject *o=PyList_GetItem(pyLi,i);
454 fillArrayWithPyListInt3(o,size2,ret);
457 else if(PyTuple_Check(pyLi))
459 size1=PyTuple_Size(pyLi);
460 for(int i=0;i<size1;i++)
462 PyObject *o=PyTuple_GetItem(pyLi,i);
463 fillArrayWithPyListInt3(o,size2,ret);
467 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
469 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
474 * will become obsolete -> fillArrayWithPyListInt2
476 static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
478 if(PyList_Check(pyLi))
480 int size=PyList_Size(pyLi);
482 if(size!=sizeOfArray)
484 std::ostringstream oss; oss << "fillArrayWithPyListInt : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
485 throw INTERP_KERNEL::Exception(oss.str().c_str());
487 for(int i=0;i<size;i++)
489 PyObject *o=PyList_GetItem(pyLi,i);
492 int val=(int)PyInt_AS_LONG(o);
497 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : List must contain integers only !");
499 for(int i=size;i<sizeOfArray;i++)
504 else if(PyTuple_Check(pyLi))
506 int size=PyTuple_Size(pyLi);
508 if(size!=sizeOfArray)
510 std::ostringstream oss; oss << "fillArrayWithPyListInt : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
511 throw INTERP_KERNEL::Exception(oss.str().c_str());
513 for(int i=0;i<size;i++)
515 PyObject *o=PyTuple_GetItem(pyLi,i);
518 int val=(int)PyInt_AS_LONG(o);
523 throw INTERP_KERNEL::Exception("tuple must contain integers only");
525 for(int i=size;i<sizeOfArray;i++)
530 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : not a list");
533 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
535 PyObject *ret=PyList_New(size);
536 for(int i=0;i<size;i++)
537 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
541 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
544 PyObject *ret=PyList_New(size);
545 for(int i=0;i<size;i++)
546 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
550 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
552 PyObject *ret=PyList_New(nbOfTuples);
553 for(int i=0;i<nbOfTuples;i++)
555 PyObject *t=PyTuple_New(nbOfComp);
556 for(int j=0;j<nbOfComp;j++)
557 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
558 PyList_SetItem(ret,i,t);
563 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
565 if(PyList_Check(pyLi))
567 *size=PyList_Size(pyLi);
568 double *tmp=new double[*size];
569 for(int i=0;i<*size;i++)
571 PyObject *o=PyList_GetItem(pyLi,i);
574 double val=PyFloat_AS_DOUBLE(o);
577 else if(PyInt_Check(o))
579 long val0=PyInt_AS_LONG(o);
586 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
591 else if(PyTuple_Check(pyLi))
593 *size=PyTuple_Size(pyLi);
594 double *tmp=new double[*size];
595 for(int i=0;i<*size;i++)
597 PyObject *o=PyTuple_GetItem(pyLi,i);
600 double val=PyFloat_AS_DOUBLE(o);
603 else if(PyInt_Check(o))
605 long val0=PyInt_AS_LONG(o);
612 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
618 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
621 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
623 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
624 if(PyFloat_Check(pyLi))
630 throw INTERP_KERNEL::Exception(MSG);
631 double val=PyFloat_AS_DOUBLE(pyLi);
634 else if(PyInt_Check(pyLi))
636 long val0=PyInt_AS_LONG(pyLi);
642 throw INTERP_KERNEL::Exception(MSG);
645 else if(PyList_Check(pyLi))
647 int size=PyList_Size(pyLi);
649 for(int i=0;i<size;i++)
651 PyObject *o=PyList_GetItem(pyLi,i);
653 fillArrayWithPyListDbl3(o,tmp1,ret);
661 throw INTERP_KERNEL::Exception(MSG);
664 else if(PyTuple_Check(pyLi))
666 int size=PyTuple_Size(pyLi);
668 for(int i=0;i<size;i++)
670 PyObject *o=PyTuple_GetItem(pyLi,i);
672 fillArrayWithPyListDbl3(o,tmp1,ret);
680 throw INTERP_KERNEL::Exception(MSG);
684 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
687 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
689 std::vector<double> ret;
690 int size1=-1,size2=-1;
691 if(PyList_Check(pyLi))
693 size1=PyList_Size(pyLi);
694 for(int i=0;i<size1;i++)
696 PyObject *o=PyList_GetItem(pyLi,i);
697 fillArrayWithPyListDbl3(o,size2,ret);
700 else if(PyTuple_Check(pyLi))
702 size1=PyTuple_Size(pyLi);
703 for(int i=0;i<size1;i++)
705 PyObject *o=PyTuple_GetItem(pyLi,i);
706 fillArrayWithPyListDbl3(o,size2,ret);
710 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
712 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
717 * will become obsolete -> fillArrayWithPyListDbl2
719 static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
721 if(PyList_Check(pyLi))
723 int size=PyList_Size(pyLi);
725 if(size!=sizeOfArray)
727 std::ostringstream oss; oss << "fillArrayWithPyListDbl : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
728 throw INTERP_KERNEL::Exception(oss.str().c_str());
730 for(int i=0;i<size;i++)
732 PyObject *o=PyList_GetItem(pyLi,i);
735 double val=PyFloat_AS_DOUBLE(o);
739 else if(PyInt_Check(o))
741 long val0=PyInt_AS_LONG(o);
747 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : list must contain floats/integers only");
749 for(int i=size;i<sizeOfArray;i++)
753 else if(PyTuple_Check(pyLi))
755 int size=PyTuple_Size(pyLi);
757 if(size!=sizeOfArray)
759 std::ostringstream oss; oss << "fillArrayWithPyListDbl : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
760 throw INTERP_KERNEL::Exception(oss.str().c_str());
762 for(int i=0;i<size;i++)
764 PyObject *o=PyTuple_GetItem(pyLi,i);
767 double val=PyFloat_AS_DOUBLE(o);
770 else if(PyInt_Check(o))
772 long val0=PyInt_AS_LONG(o);
777 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : tuple must contain floats/integers only");
779 for(int i=size;i<sizeOfArray;i++)
784 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : not a list nor a tuple");
787 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
789 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
792 if(PyList_Check(pyLi))
794 int size=PyList_Size(pyLi);
796 for(int i=0;i<size;i++)
798 PyObject *obj=PyList_GetItem(pyLi,i);
799 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
800 if(!SWIG_IsOK(status))
801 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
802 T arg=reinterpret_cast< T >(argp);
806 else if(PyTuple_Check(pyLi))
808 int size=PyTuple_Size(pyLi);
810 for(int i=0;i<size;i++)
812 PyObject *obj=PyTuple_GetItem(pyLi,i);
813 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
814 if(!SWIG_IsOK(status))
816 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
817 throw INTERP_KERNEL::Exception(oss.str().c_str());
819 T arg=reinterpret_cast< T >(argp);
823 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
826 T arg=reinterpret_cast< T >(argp);
830 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
834 * if python int -> cpp int sw=1
835 * if python list[int] -> cpp vector<int> sw=2
836 * if python tuple[int] -> cpp vector<int> sw=2
837 * if python DataArrayInt -> cpp DataArrayInt sw=3
838 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
840 * switch between (int,vector<int>,DataArrayInt)
842 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
845 if(PyInt_Check(value))
847 iTyypp=(int)PyInt_AS_LONG(value);
851 if(PyTuple_Check(value))
853 int size=PyTuple_Size(value);
854 stdvecTyypp.resize(size);
855 for(int i=0;i<size;i++)
857 PyObject *o=PyTuple_GetItem(value,i);
859 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
862 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
863 throw INTERP_KERNEL::Exception(oss.str().c_str());
869 if(PyList_Check(value))
871 int size=PyList_Size(value);
872 stdvecTyypp.resize(size);
873 for(int i=0;i<size;i++)
875 PyObject *o=PyList_GetItem(value,i);
877 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
880 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
881 throw INTERP_KERNEL::Exception(oss.str().c_str());
888 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
889 if(SWIG_IsOK(status))
891 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
895 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
896 if(SWIG_IsOK(status))
898 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
902 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
906 * if python double -> cpp double sw=1
907 * if python int -> cpp double sw=1
908 * if python list[double] -> cpp vector<double> sw=2
909 * if python list[int] -> cpp vector<double> sw=2
910 * if python tuple[double] -> cpp vector<double> sw=2
911 * if python tuple[int] -> cpp vector<double> sw=2
912 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
914 * switch between (int,vector<int>,DataArrayInt)
916 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
919 if(PyFloat_Check(value))
921 iTyypp=PyFloat_AS_DOUBLE(value);
925 if(PyInt_Check(value))
927 iTyypp=(double)PyInt_AS_LONG(value);
931 if(PyTuple_Check(value))
933 int size=PyTuple_Size(value);
934 stdvecTyypp.resize(size);
935 for(int i=0;i<size;i++)
937 PyObject *o=PyTuple_GetItem(value,i);
939 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
940 else if(PyInt_Check(o))
941 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
944 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
945 throw INTERP_KERNEL::Exception(oss.str().c_str());
951 if(PyList_Check(value))
953 int size=PyList_Size(value);
954 stdvecTyypp.resize(size);
955 for(int i=0;i<size;i++)
957 PyObject *o=PyList_GetItem(value,i);
959 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
960 else if(PyInt_Check(o))
961 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
964 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
965 throw INTERP_KERNEL::Exception(oss.str().c_str());
972 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
973 if(!SWIG_IsOK(status))
974 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
975 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
980 * if python double -> cpp double sw=1
981 * if python int -> cpp double sw=1
982 * if python list[double] -> cpp vector<double> sw=2
983 * if python list[int] -> cpp vector<double> sw=2
984 * if python tuple[double] -> cpp vector<double> sw=2
985 * if python tuple[int] -> cpp vector<double> sw=2
986 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
988 * switch between (int,vector<int>,DataArrayInt)
990 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
993 if(PyFloat_Check(value))
995 iTyypp=PyFloat_AS_DOUBLE(value);
999 if(PyInt_Check(value))
1001 iTyypp=(double)PyInt_AS_LONG(value);
1005 if(PyTuple_Check(value))
1007 int size=PyTuple_Size(value);
1008 stdvecTyypp.resize(size);
1009 for(int i=0;i<size;i++)
1011 PyObject *o=PyTuple_GetItem(value,i);
1012 if(PyFloat_Check(o))
1013 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1014 else if(PyInt_Check(o))
1015 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1018 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1019 throw INTERP_KERNEL::Exception(oss.str().c_str());
1025 if(PyList_Check(value))
1027 int size=PyList_Size(value);
1028 stdvecTyypp.resize(size);
1029 for(int i=0;i<size;i++)
1031 PyObject *o=PyList_GetItem(value,i);
1032 if(PyFloat_Check(o))
1033 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
1034 else if(PyInt_Check(o))
1035 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
1038 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1039 throw INTERP_KERNEL::Exception(oss.str().c_str());
1046 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1047 if(!SWIG_IsOK(status))
1048 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
1049 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1054 * if python int -> cpp int sw=1
1055 * if python list[int] -> cpp vector<int> sw=2
1056 * if python tuple[int] -> cpp vector<int> sw=2
1057 * if python slicp -> cpp pair sw=3
1058 * if python DataArrayInt -> cpp DataArrayInt sw=4
1060 * switch between (int,vector<int>,DataArrayInt)
1062 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)
1064 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1066 if(PyInt_Check(value))
1068 iTyypp=(int)PyInt_AS_LONG(value);
1072 if(PyTuple_Check(value))
1074 int size=PyTuple_Size(value);
1075 stdvecTyypp.resize(size);
1076 for(int i=0;i<size;i++)
1078 PyObject *o=PyTuple_GetItem(value,i);
1080 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1083 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1084 throw INTERP_KERNEL::Exception(oss.str().c_str());
1090 if(PyList_Check(value))
1092 int size=PyList_Size(value);
1093 stdvecTyypp.resize(size);
1094 for(int i=0;i<size;i++)
1096 PyObject *o=PyList_GetItem(value,i);
1098 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1101 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1102 throw INTERP_KERNEL::Exception(oss.str().c_str());
1108 if(PySlice_Check(value))
1110 Py_ssize_t strt,stp,step;
1111 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1112 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1114 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
1115 throw INTERP_KERNEL::Exception(oss.str().c_str());
1119 p.second.second=step;
1124 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1125 if(SWIG_IsOK(status))
1127 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1130 std::ostringstream oss; oss << msg << " Instance in null !";
1131 throw INTERP_KERNEL::Exception(oss.str().c_str());
1136 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
1137 if(SWIG_IsOK(status))
1139 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1142 std::ostringstream oss; oss << msg << " Instance in null !";
1143 throw INTERP_KERNEL::Exception(oss.str().c_str());
1145 stdvecTyypp.resize(tmp->getNumberOfCompo());
1146 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1150 throw INTERP_KERNEL::Exception(msg);
1153 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)
1156 if(PyInt_Check(value))
1158 iTyypp=(int)PyInt_AS_LONG(value);
1162 if(PyTuple_Check(value))
1164 int size=PyTuple_Size(value);
1165 stdvecTyypp.resize(size);
1166 for(int i=0;i<size;i++)
1168 PyObject *o=PyTuple_GetItem(value,i);
1170 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1173 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1174 throw INTERP_KERNEL::Exception(oss.str().c_str());
1180 if(PyList_Check(value))
1182 int size=PyList_Size(value);
1183 stdvecTyypp.resize(size);
1184 for(int i=0;i<size;i++)
1186 PyObject *o=PyList_GetItem(value,i);
1188 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1191 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1192 throw INTERP_KERNEL::Exception(oss.str().c_str());
1198 if(PySlice_Check(value))
1200 Py_ssize_t strt,stp,step;
1201 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1202 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1204 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
1205 throw INTERP_KERNEL::Exception(oss.str().c_str());
1209 p.second.second=step;
1214 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1215 if(!SWIG_IsOK(status))
1216 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1217 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1222 * if value int -> cpp it sw=1
1223 * if value list[int] -> vt sw=2
1224 * if value tuple[int] -> vt sw=2
1225 * if value slice -> pt sw=3
1226 * if value DataArrayInt -> dt sw=4
1227 * if value tuple [int,int] -> cpp it,ip sw=5
1228 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1229 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1230 * if value tuple [slice,int] -> cpp pt,ip sw=7
1231 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1232 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1233 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1234 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1235 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1236 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1237 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1238 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1239 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1240 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1241 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1242 * if value tuple [int,slice] -> cpp it,pc sw=13
1243 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1244 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1245 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1246 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1248 * switch between (int,vector<int>,DataArrayInt)
1250 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1251 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1252 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1254 if(!PyTuple_Check(value))
1256 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1261 int sz=PyTuple_Size(value);
1263 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1264 PyObject *ob0=PyTuple_GetItem(value,0);
1266 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1267 PyObject *ob1=PyTuple_GetItem(value,1);
1268 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1274 * if value int -> cpp val sw=1
1275 * if value double -> cpp val sw=1
1276 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1277 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1278 * if value list[int,double] -> cpp std::vector<double> sw=4
1279 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1281 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1284 if(PyFloat_Check(value))
1286 val=PyFloat_AS_DOUBLE(value);
1290 if(PyInt_Check(value))
1292 val=(double)PyInt_AS_LONG(value);
1296 if(PyTuple_Check(value))
1298 int size=PyTuple_Size(value);
1300 for(int i=0;i<size;i++)
1302 PyObject *o=PyTuple_GetItem(value,i);
1303 if(PyFloat_Check(o))
1304 f[i]=PyFloat_AS_DOUBLE(o);
1305 else if(PyInt_Check(o))
1306 f[i]=(double)PyInt_AS_LONG(o);
1309 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1310 throw INTERP_KERNEL::Exception(oss.str().c_str());
1316 if(PyList_Check(value))
1318 int size=PyList_Size(value);
1320 for(int i=0;i<size;i++)
1322 PyObject *o=PyList_GetItem(value,i);
1323 if(PyFloat_Check(o))
1324 f[i]=PyFloat_AS_DOUBLE(o);
1325 else if(PyInt_Check(o))
1326 f[i]=(double)PyInt_AS_LONG(o);
1329 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1330 throw INTERP_KERNEL::Exception(oss.str().c_str());
1337 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1338 if(SWIG_IsOK(status))
1340 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1344 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1345 if(SWIG_IsOK(status))
1347 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1351 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1355 * if value int -> cpp val sw=1
1356 * if value double -> cpp val sw=1
1357 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1358 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1359 * if value list[int,double] -> cpp std::vector<double> sw=4
1360 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1362 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1363 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1366 if(PyFloat_Check(value))
1368 val=PyFloat_AS_DOUBLE(value);
1370 if(nbTuplesExpected*nbCompExpected!=1)
1372 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1373 throw INTERP_KERNEL::Exception(oss.str().c_str());
1377 if(PyInt_Check(value))
1379 val=(double)PyInt_AS_LONG(value);
1381 if(nbTuplesExpected*nbCompExpected!=1)
1383 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1384 throw INTERP_KERNEL::Exception(oss.str().c_str());
1388 if(PyTuple_Check(value) || PyList_Check(value))
1392 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1393 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1398 catch(INTERP_KERNEL::Exception& e) { throw e; }
1401 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1402 if(SWIG_IsOK(status))
1404 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1408 if(d->getNumberOfTuples()==nbTuplesExpected)
1410 if(d->getNumberOfComponents()==nbCompExpected)
1412 return d->getConstPointer();
1416 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1417 throw INTERP_KERNEL::Exception(oss.str().c_str());
1422 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1423 throw INTERP_KERNEL::Exception(oss.str().c_str());
1430 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1431 throw INTERP_KERNEL::Exception(oss.str().c_str());
1437 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1438 if(SWIG_IsOK(status))
1440 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1442 if(e->getNumberOfCompo()==nbCompExpected)
1444 if(nbTuplesExpected==1)
1445 return e->getConstPointer();
1448 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1449 throw INTERP_KERNEL::Exception(oss.str().c_str());
1454 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1455 throw INTERP_KERNEL::Exception(oss.str().c_str());
1458 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1462 * if value int -> cpp val sw=1
1463 * if value double -> cpp val sw=1
1464 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1465 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1466 * if value list[int,double] -> cpp std::vector<double> sw=4
1467 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1469 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1470 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1473 if(PyFloat_Check(value))
1475 val=PyFloat_AS_DOUBLE(value);
1477 if(nbCompExpected!=1)
1479 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1480 throw INTERP_KERNEL::Exception(oss.str().c_str());
1485 if(PyInt_Check(value))
1487 val=(double)PyInt_AS_LONG(value);
1489 if(nbCompExpected!=1)
1491 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1492 throw INTERP_KERNEL::Exception(oss.str().c_str());
1497 if(PyTuple_Check(value))
1499 int size=PyTuple_Size(value);
1501 for(int i=0;i<size;i++)
1503 PyObject *o=PyTuple_GetItem(value,i);
1504 if(PyFloat_Check(o))
1505 f[i]=PyFloat_AS_DOUBLE(o);
1506 else if(PyInt_Check(o))
1507 f[i]=(double)PyInt_AS_LONG(o);
1510 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1511 throw INTERP_KERNEL::Exception(oss.str().c_str());
1515 if(size%nbCompExpected!=0)
1517 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1518 throw INTERP_KERNEL::Exception(oss.str().c_str());
1520 nbTuples=size/nbCompExpected;
1523 if(PyList_Check(value))
1525 int size=PyList_Size(value);
1527 for(int i=0;i<size;i++)
1529 PyObject *o=PyList_GetItem(value,i);
1530 if(PyFloat_Check(o))
1531 f[i]=PyFloat_AS_DOUBLE(o);
1532 else if(PyInt_Check(o))
1533 f[i]=(double)PyInt_AS_LONG(o);
1536 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1537 throw INTERP_KERNEL::Exception(oss.str().c_str());
1541 if(size%nbCompExpected!=0)
1543 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1544 throw INTERP_KERNEL::Exception(oss.str().c_str());
1546 nbTuples=size/nbCompExpected;
1550 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1551 if(SWIG_IsOK(status))
1553 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1557 if(d->getNumberOfComponents()==nbCompExpected)
1559 nbTuples=d->getNumberOfTuples();
1560 return d->getConstPointer();
1564 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1572 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1573 throw INTERP_KERNEL::Exception(oss.str().c_str());
1579 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1580 if(SWIG_IsOK(status))
1582 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1584 if(e->getNumberOfCompo()==nbCompExpected)
1587 return e->getConstPointer();
1591 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1592 throw INTERP_KERNEL::Exception(oss.str().c_str());
1595 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1599 * if python int -> cpp int sw=1
1600 * if python list[int] -> cpp vector<int> sw=2
1601 * if python tuple[int] -> cpp vector<int> sw=2
1602 * if python DataArrayInt -> cpp DataArrayInt sw=3
1603 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1605 * switch between (int,vector<int>,DataArrayInt)
1607 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1610 if(PyInt_Check(value))
1612 iTyypp=(int)PyInt_AS_LONG(value);
1616 if(PyTuple_Check(value))
1618 int size=PyTuple_Size(value);
1619 stdvecTyypp.resize(size);
1620 for(int i=0;i<size;i++)
1622 PyObject *o=PyTuple_GetItem(value,i);
1624 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1627 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1628 throw INTERP_KERNEL::Exception(oss.str().c_str());
1632 return &stdvecTyypp[0];
1634 if(PyList_Check(value))
1636 int size=PyList_Size(value);
1637 stdvecTyypp.resize(size);
1638 for(int i=0;i<size;i++)
1640 PyObject *o=PyList_GetItem(value,i);
1642 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1645 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1646 throw INTERP_KERNEL::Exception(oss.str().c_str());
1650 return &stdvecTyypp[0];
1653 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1654 if(SWIG_IsOK(status))
1656 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1659 sw=3; sz=daIntTyypp->getNbOfElems();
1660 return daIntTyypp->begin();
1668 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1669 if(SWIG_IsOK(status))
1671 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1672 sw=4; sz=daIntTuple->getNumberOfCompo();
1673 return daIntTuple->getConstPointer();
1675 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");