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);
33 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
34 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
36 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
40 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
43 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
44 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
45 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
46 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
47 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
48 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
49 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
50 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
51 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
52 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
54 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
58 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
61 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
62 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
64 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
68 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
71 PyObject *ret=PyList_New(size);
72 for(int i=0;i<size;i++)
73 PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
76 npy_intp dim = (npy_intp) size;
77 int *tmp=new int[size];
78 std::copy(ptr,ptr+size,tmp);
79 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,const_cast<int *>(tmp));
83 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
87 PyObject *ret=PyList_New(size);
88 for(int i=0;i<size;i++)
89 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
92 npy_intp dim = (npy_intp) v.size();
93 int *tmp=new int[v.size()];
94 std::copy(v.begin(),v.end(),tmp);
95 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,tmp);
99 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
102 PyObject *ret=PyList_New(size);
103 std::set<int>::const_iterator it=v.begin();
104 for(int i=0;i<size;i++,it++)
105 PyList_SetItem(ret,i,PyInt_FromLong(*it));
109 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
111 PyObject *ret=PyList_New(nbOfTuples);
112 for(int i=0;i<nbOfTuples;i++)
114 PyObject *t=PyTuple_New(nbOfComp);
115 for(int j=0;j<nbOfComp;j++)
116 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
117 PyList_SetItem(ret,i,t);
122 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
124 if(PyList_Check(pyLi))
126 *size=PyList_Size(pyLi);
127 int *tmp=new int[*size];
128 for(int i=0;i<*size;i++)
130 PyObject *o=PyList_GetItem(pyLi,i);
133 int val=(int)PyInt_AS_LONG(o);
139 throw INTERP_KERNEL::Exception("list must contain integers only");
144 else if(PyTuple_Check(pyLi))
146 *size=PyTuple_Size(pyLi);
147 int *tmp=new int[*size];
148 for(int i=0;i<*size;i++)
150 PyObject *o=PyTuple_GetItem(pyLi,i);
153 int val=(int)PyInt_AS_LONG(o);
159 throw INTERP_KERNEL::Exception("tuple must contain integers only");
167 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
169 if(PyArray_Check(pyLi))
171 npy_intp mySize = PyArray_SIZE(pyLi);
172 int *ret=(int *)PyArray_BYTES(pyLi);
178 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
184 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
186 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
187 if(PyList_Check(pyLi))
189 int size=PyList_Size(pyLi);
191 for(int i=0;i<size;i++)
193 PyObject *o=PyList_GetItem(pyLi,i);
196 int sz2=PyTuple_Size(o);
198 throw INTERP_KERNEL::Exception(msg);
199 PyObject *o_0=PyTuple_GetItem(o,0);
200 if(!PyInt_Check(o_0))
201 throw INTERP_KERNEL::Exception(msg);
202 PyObject *o_1=PyTuple_GetItem(o,1);
203 if(!PyInt_Check(o_1))
204 throw INTERP_KERNEL::Exception(msg);
205 arr[i].first=(int)PyInt_AS_LONG(o_0);
206 arr[i].second=(int)PyInt_AS_LONG(o_1);
209 throw INTERP_KERNEL::Exception(msg);
212 else if(PyTuple_Check(pyLi))
214 int size=PyTuple_Size(pyLi);
216 for(int i=0;i<size;i++)
218 PyObject *o=PyTuple_GetItem(pyLi,i);
221 int sz2=PyTuple_Size(o);
223 throw INTERP_KERNEL::Exception(msg);
224 PyObject *o_0=PyTuple_GetItem(o,0);
225 if(!PyInt_Check(o_0))
226 throw INTERP_KERNEL::Exception(msg);
227 PyObject *o_1=PyTuple_GetItem(o,1);
228 if(!PyInt_Check(o_1))
229 throw INTERP_KERNEL::Exception(msg);
230 arr[i].first=(int)PyInt_AS_LONG(o_0);
231 arr[i].second=(int)PyInt_AS_LONG(o_1);
234 throw INTERP_KERNEL::Exception(msg);
238 throw INTERP_KERNEL::Exception(msg);
241 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
243 if(PyList_Check(pyLi))
245 int size=PyList_Size(pyLi);
247 for(int i=0;i<size;i++)
249 PyObject *o=PyList_GetItem(pyLi,i);
252 int val=(int)PyInt_AS_LONG(o);
256 throw INTERP_KERNEL::Exception("list must contain integers only");
259 else if(PyTuple_Check(pyLi))
261 int size=PyTuple_Size(pyLi);
263 for(int i=0;i<size;i++)
265 PyObject *o=PyTuple_GetItem(pyLi,i);
268 int val=(int)PyInt_AS_LONG(o);
272 throw INTERP_KERNEL::Exception("tuple must contain integers only");
278 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
280 if(PyArray_Check(pyLi))
282 npy_intp mySize = PyArray_SIZE(pyLi);
283 int *ret=(int *)PyArray_BYTES(pyLi);
285 std::copy(ret,ret+mySize,arr.begin());
289 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
294 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
297 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
299 if(PyList_Check(pyLi))
301 int size=PyList_Size(pyLi);
302 for(int i=0;i<size;i++)
304 PyObject *o=PyList_GetItem(pyLi,i);
307 int val=(int)PyInt_AS_LONG(o);
312 std::vector<int> arr2;
313 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
314 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
316 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
317 throw INTERP_KERNEL::Exception(oss.str().c_str());
319 arr.insert(arr.end(),arr2.begin(),arr2.end());
323 else if(PyTuple_Check(pyLi))
325 int size=PyTuple_Size(pyLi);
326 for(int i=0;i<size;i++)
328 PyObject *o=PyTuple_GetItem(pyLi,i);
331 int val=(int)PyInt_AS_LONG(o);
336 std::vector<int> arr2;
337 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
338 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
340 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
341 throw INTERP_KERNEL::Exception(oss.str().c_str());
343 arr.insert(arr.end(),arr2.begin(),arr2.end());
348 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
351 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
355 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
356 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
358 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
359 oss << " whereas nb of components expected is " << nbOfComp << " !";
360 throw INTERP_KERNEL::Exception(oss.str().c_str());
367 if((nbOfTuples!=size1 || nbOfComp!=size2))
369 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
371 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
372 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
373 throw INTERP_KERNEL::Exception(oss.str().c_str());
379 if(nbOfTuples==size1)
383 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
384 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
385 throw INTERP_KERNEL::Exception(oss.str().c_str());
391 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
393 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
394 if(PyInt_Check(pyLi))
396 long val=PyInt_AS_LONG(pyLi);
401 throw INTERP_KERNEL::Exception(MSG);
404 else if(PyList_Check(pyLi))
406 int size=PyList_Size(pyLi);
408 for(int i=0;i<size;i++)
410 PyObject *o=PyList_GetItem(pyLi,i);
412 fillArrayWithPyListInt3(o,tmp1,ret);
420 throw INTERP_KERNEL::Exception(MSG);
423 else if(PyTuple_Check(pyLi))
425 int size=PyTuple_Size(pyLi);
427 for(int i=0;i<size;i++)
429 PyObject *o=PyTuple_GetItem(pyLi,i);
431 fillArrayWithPyListInt3(o,tmp1,ret);
439 throw INTERP_KERNEL::Exception(MSG);
443 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
446 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
448 std::vector<int> ret;
449 int size1=-1,size2=-1;
450 if(PyList_Check(pyLi))
452 size1=PyList_Size(pyLi);
453 for(int i=0;i<size1;i++)
455 PyObject *o=PyList_GetItem(pyLi,i);
456 fillArrayWithPyListInt3(o,size2,ret);
461 else if(PyTuple_Check(pyLi))
463 size1=PyTuple_Size(pyLi);
464 for(int i=0;i<size1;i++)
466 PyObject *o=PyTuple_GetItem(pyLi,i);
467 fillArrayWithPyListInt3(o,size2,ret);
473 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
475 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
479 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
481 PyObject *ret=PyList_New(size);
482 for(int i=0;i<size;i++)
483 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
487 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
490 PyObject *ret=PyList_New(size);
491 for(int i=0;i<size;i++)
492 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
496 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
498 PyObject *ret=PyList_New(nbOfTuples);
499 for(int i=0;i<nbOfTuples;i++)
501 PyObject *t=PyTuple_New(nbOfComp);
502 for(int j=0;j<nbOfComp;j++)
503 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
504 PyList_SetItem(ret,i,t);
509 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
511 if(PyList_Check(pyLi))
513 *size=PyList_Size(pyLi);
514 double *tmp=new double[*size];
515 for(int i=0;i<*size;i++)
517 PyObject *o=PyList_GetItem(pyLi,i);
520 double val=PyFloat_AS_DOUBLE(o);
523 else if(PyInt_Check(o))
525 long val0=PyInt_AS_LONG(o);
532 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
537 else if(PyTuple_Check(pyLi))
539 *size=PyTuple_Size(pyLi);
540 double *tmp=new double[*size];
541 for(int i=0;i<*size;i++)
543 PyObject *o=PyTuple_GetItem(pyLi,i);
546 double val=PyFloat_AS_DOUBLE(o);
549 else if(PyInt_Check(o))
551 long val0=PyInt_AS_LONG(o);
558 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
564 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
567 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
569 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
570 if(PyFloat_Check(pyLi))
576 throw INTERP_KERNEL::Exception(MSG);
577 double val=PyFloat_AS_DOUBLE(pyLi);
580 else if(PyInt_Check(pyLi))
582 long val0=PyInt_AS_LONG(pyLi);
588 throw INTERP_KERNEL::Exception(MSG);
591 else if(PyList_Check(pyLi))
593 int size=PyList_Size(pyLi);
595 for(int i=0;i<size;i++)
597 PyObject *o=PyList_GetItem(pyLi,i);
599 fillArrayWithPyListDbl3(o,tmp1,ret);
607 throw INTERP_KERNEL::Exception(MSG);
610 else if(PyTuple_Check(pyLi))
612 int size=PyTuple_Size(pyLi);
614 for(int i=0;i<size;i++)
616 PyObject *o=PyTuple_GetItem(pyLi,i);
618 fillArrayWithPyListDbl3(o,tmp1,ret);
626 throw INTERP_KERNEL::Exception(MSG);
630 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
633 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
635 std::vector<double> ret;
636 int size1=-1,size2=-1;
637 if(PyList_Check(pyLi))
639 size1=PyList_Size(pyLi);
640 for(int i=0;i<size1;i++)
642 PyObject *o=PyList_GetItem(pyLi,i);
643 fillArrayWithPyListDbl3(o,size2,ret);
648 else if(PyTuple_Check(pyLi))
650 size1=PyTuple_Size(pyLi);
651 for(int i=0;i<size1;i++)
653 PyObject *o=PyTuple_GetItem(pyLi,i);
654 fillArrayWithPyListDbl3(o,size2,ret);
660 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
662 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
666 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
668 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
671 if(PyList_Check(pyLi))
673 int size=PyList_Size(pyLi);
675 for(int i=0;i<size;i++)
677 PyObject *obj=PyList_GetItem(pyLi,i);
678 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
679 if(!SWIG_IsOK(status))
680 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
681 T arg=reinterpret_cast< T >(argp);
685 else if(PyTuple_Check(pyLi))
687 int size=PyTuple_Size(pyLi);
689 for(int i=0;i<size;i++)
691 PyObject *obj=PyTuple_GetItem(pyLi,i);
692 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
693 if(!SWIG_IsOK(status))
695 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
696 throw INTERP_KERNEL::Exception(oss.str().c_str());
698 T arg=reinterpret_cast< T >(argp);
702 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
705 T arg=reinterpret_cast< T >(argp);
709 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
713 * if python int -> cpp int sw=1
714 * if python list[int] -> cpp vector<int> sw=2
715 * if python tuple[int] -> cpp vector<int> sw=2
716 * if python DataArrayInt -> cpp DataArrayInt sw=3
717 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
719 * switch between (int,vector<int>,DataArrayInt)
721 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
724 if(PyInt_Check(value))
726 iTyypp=(int)PyInt_AS_LONG(value);
730 if(PyTuple_Check(value))
732 int size=PyTuple_Size(value);
733 stdvecTyypp.resize(size);
734 for(int i=0;i<size;i++)
736 PyObject *o=PyTuple_GetItem(value,i);
738 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
741 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
742 throw INTERP_KERNEL::Exception(oss.str().c_str());
748 if(PyList_Check(value))
750 int size=PyList_Size(value);
751 stdvecTyypp.resize(size);
752 for(int i=0;i<size;i++)
754 PyObject *o=PyList_GetItem(value,i);
756 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
759 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
760 throw INTERP_KERNEL::Exception(oss.str().c_str());
767 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
768 if(SWIG_IsOK(status))
770 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
774 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
775 if(SWIG_IsOK(status))
777 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
781 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
785 * if python double -> cpp double sw=1
786 * if python int -> cpp double sw=1
787 * if python list[double] -> cpp vector<double> sw=2
788 * if python list[int] -> cpp vector<double> sw=2
789 * if python tuple[double] -> cpp vector<double> sw=2
790 * if python tuple[int] -> cpp vector<double> sw=2
791 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
793 * switch between (int,vector<int>,DataArrayInt)
795 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
798 if(PyFloat_Check(value))
800 iTyypp=PyFloat_AS_DOUBLE(value);
804 if(PyInt_Check(value))
806 iTyypp=(double)PyInt_AS_LONG(value);
810 if(PyTuple_Check(value))
812 int size=PyTuple_Size(value);
813 stdvecTyypp.resize(size);
814 for(int i=0;i<size;i++)
816 PyObject *o=PyTuple_GetItem(value,i);
818 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
819 else if(PyInt_Check(o))
820 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
823 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
824 throw INTERP_KERNEL::Exception(oss.str().c_str());
830 if(PyList_Check(value))
832 int size=PyList_Size(value);
833 stdvecTyypp.resize(size);
834 for(int i=0;i<size;i++)
836 PyObject *o=PyList_GetItem(value,i);
838 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
839 else if(PyInt_Check(o))
840 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
843 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
844 throw INTERP_KERNEL::Exception(oss.str().c_str());
851 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
852 if(!SWIG_IsOK(status))
853 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
854 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
859 * if python double -> cpp double sw=1
860 * if python int -> cpp double sw=1
861 * if python list[double] -> cpp vector<double> sw=2
862 * if python list[int] -> cpp vector<double> sw=2
863 * if python tuple[double] -> cpp vector<double> sw=2
864 * if python tuple[int] -> cpp vector<double> sw=2
865 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
867 * switch between (int,vector<int>,DataArrayInt)
869 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
872 if(PyFloat_Check(value))
874 iTyypp=PyFloat_AS_DOUBLE(value);
878 if(PyInt_Check(value))
880 iTyypp=(double)PyInt_AS_LONG(value);
884 if(PyTuple_Check(value))
886 int size=PyTuple_Size(value);
887 stdvecTyypp.resize(size);
888 for(int i=0;i<size;i++)
890 PyObject *o=PyTuple_GetItem(value,i);
892 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
893 else if(PyInt_Check(o))
894 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
897 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
898 throw INTERP_KERNEL::Exception(oss.str().c_str());
904 if(PyList_Check(value))
906 int size=PyList_Size(value);
907 stdvecTyypp.resize(size);
908 for(int i=0;i<size;i++)
910 PyObject *o=PyList_GetItem(value,i);
912 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
913 else if(PyInt_Check(o))
914 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
917 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
918 throw INTERP_KERNEL::Exception(oss.str().c_str());
925 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
926 if(!SWIG_IsOK(status))
927 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
928 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
933 * if python int -> cpp int sw=1
934 * if python list[int] -> cpp vector<int> sw=2
935 * if python tuple[int] -> cpp vector<int> sw=2
936 * if python slicp -> cpp pair sw=3
937 * if python DataArrayInt -> cpp DataArrayInt sw=4
939 * switch between (int,vector<int>,DataArrayInt)
941 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)
943 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
945 if(PyInt_Check(value))
947 iTyypp=(int)PyInt_AS_LONG(value);
951 if(PyTuple_Check(value))
953 int size=PyTuple_Size(value);
954 stdvecTyypp.resize(size);
955 for(int i=0;i<size;i++)
957 PyObject *o=PyTuple_GetItem(value,i);
959 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
962 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
963 throw INTERP_KERNEL::Exception(oss.str().c_str());
969 if(PyList_Check(value))
971 int size=PyList_Size(value);
972 stdvecTyypp.resize(size);
973 for(int i=0;i<size;i++)
975 PyObject *o=PyList_GetItem(value,i);
977 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
980 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
981 throw INTERP_KERNEL::Exception(oss.str().c_str());
987 if(PySlice_Check(value))
989 Py_ssize_t strt=2,stp=2,step=2;
990 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
991 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
992 if(nbelem!=0 || strt!=0 || stp!=0)
994 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
995 throw INTERP_KERNEL::Exception(oss.str().c_str());
999 p.second.second=step;
1004 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1005 if(SWIG_IsOK(status))
1007 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1010 std::ostringstream oss; oss << msg << " Instance in null !";
1011 throw INTERP_KERNEL::Exception(oss.str().c_str());
1016 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
1017 if(SWIG_IsOK(status))
1019 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1022 std::ostringstream oss; oss << msg << " Instance in null !";
1023 throw INTERP_KERNEL::Exception(oss.str().c_str());
1025 stdvecTyypp.resize(tmp->getNumberOfCompo());
1026 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1030 throw INTERP_KERNEL::Exception(msg);
1033 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)
1036 if(PyInt_Check(value))
1038 iTyypp=(int)PyInt_AS_LONG(value);
1042 if(PyTuple_Check(value))
1044 int size=PyTuple_Size(value);
1045 stdvecTyypp.resize(size);
1046 for(int i=0;i<size;i++)
1048 PyObject *o=PyTuple_GetItem(value,i);
1050 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1053 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1054 throw INTERP_KERNEL::Exception(oss.str().c_str());
1060 if(PyList_Check(value))
1062 int size=PyList_Size(value);
1063 stdvecTyypp.resize(size);
1064 for(int i=0;i<size;i++)
1066 PyObject *o=PyList_GetItem(value,i);
1068 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1071 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1072 throw INTERP_KERNEL::Exception(oss.str().c_str());
1078 if(PySlice_Check(value))
1080 Py_ssize_t strt=2,stp=2,step=2;
1081 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1082 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1083 if(nbelem!=0 || strt!=0 || stp!=0)
1085 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1086 throw INTERP_KERNEL::Exception(oss.str().c_str());
1090 p.second.second=step;
1095 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1096 if(!SWIG_IsOK(status))
1097 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1098 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1103 * if value int -> cpp it sw=1
1104 * if value list[int] -> vt sw=2
1105 * if value tuple[int] -> vt sw=2
1106 * if value slice -> pt sw=3
1107 * if value DataArrayInt -> dt sw=4
1108 * if value tuple [int,int] -> cpp it,ip sw=5
1109 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1110 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1111 * if value tuple [slice,int] -> cpp pt,ip sw=7
1112 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1113 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1114 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1115 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1116 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1117 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1118 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1119 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1120 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1121 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1122 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1123 * if value tuple [int,slice] -> cpp it,pc sw=13
1124 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1125 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1126 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1127 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1129 * switch between (int,vector<int>,DataArrayInt)
1131 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1132 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1133 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1135 if(!PyTuple_Check(value))
1137 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1142 int sz=PyTuple_Size(value);
1144 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1145 PyObject *ob0=PyTuple_GetItem(value,0);
1147 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1148 PyObject *ob1=PyTuple_GetItem(value,1);
1149 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1155 * if value int -> cpp val sw=1
1156 * if value double -> cpp val sw=1
1157 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1158 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1159 * if value list[int,double] -> cpp std::vector<double> sw=4
1160 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1162 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1165 if(PyFloat_Check(value))
1167 val=PyFloat_AS_DOUBLE(value);
1171 if(PyInt_Check(value))
1173 val=(double)PyInt_AS_LONG(value);
1177 if(PyTuple_Check(value))
1179 int size=PyTuple_Size(value);
1181 for(int i=0;i<size;i++)
1183 PyObject *o=PyTuple_GetItem(value,i);
1184 if(PyFloat_Check(o))
1185 f[i]=PyFloat_AS_DOUBLE(o);
1186 else if(PyInt_Check(o))
1187 f[i]=(double)PyInt_AS_LONG(o);
1190 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1191 throw INTERP_KERNEL::Exception(oss.str().c_str());
1197 if(PyList_Check(value))
1199 int size=PyList_Size(value);
1201 for(int i=0;i<size;i++)
1203 PyObject *o=PyList_GetItem(value,i);
1204 if(PyFloat_Check(o))
1205 f[i]=PyFloat_AS_DOUBLE(o);
1206 else if(PyInt_Check(o))
1207 f[i]=(double)PyInt_AS_LONG(o);
1210 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1211 throw INTERP_KERNEL::Exception(oss.str().c_str());
1218 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1219 if(SWIG_IsOK(status))
1221 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1225 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1226 if(SWIG_IsOK(status))
1228 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1232 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1236 * if value int -> cpp val sw=1
1237 * if value double -> cpp val sw=1
1238 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1239 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1240 * if value list[int,double] -> cpp std::vector<double> sw=4
1241 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1243 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1244 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1247 if(PyFloat_Check(value))
1249 val=PyFloat_AS_DOUBLE(value);
1251 if(nbTuplesExpected*nbCompExpected!=1)
1253 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1254 throw INTERP_KERNEL::Exception(oss.str().c_str());
1258 if(PyInt_Check(value))
1260 val=(double)PyInt_AS_LONG(value);
1262 if(nbTuplesExpected*nbCompExpected!=1)
1264 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1265 throw INTERP_KERNEL::Exception(oss.str().c_str());
1269 if(PyTuple_Check(value) || PyList_Check(value))
1273 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1274 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1279 catch(INTERP_KERNEL::Exception& e) { throw e; }
1282 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1283 if(SWIG_IsOK(status))
1285 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1289 if(d->getNumberOfTuples()==nbTuplesExpected)
1291 if(d->getNumberOfComponents()==nbCompExpected)
1293 return d->getConstPointer();
1297 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1298 throw INTERP_KERNEL::Exception(oss.str().c_str());
1303 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1304 throw INTERP_KERNEL::Exception(oss.str().c_str());
1311 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1312 throw INTERP_KERNEL::Exception(oss.str().c_str());
1318 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1319 if(SWIG_IsOK(status))
1321 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1323 if(e->getNumberOfCompo()==nbCompExpected)
1325 if(nbTuplesExpected==1)
1326 return e->getConstPointer();
1329 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1330 throw INTERP_KERNEL::Exception(oss.str().c_str());
1335 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1336 throw INTERP_KERNEL::Exception(oss.str().c_str());
1339 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1343 * if value int -> cpp val sw=1
1344 * if value double -> cpp val sw=1
1345 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1346 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1347 * if value list[int,double] -> cpp std::vector<double> sw=4
1348 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1350 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1351 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1354 if(PyFloat_Check(value))
1356 val=PyFloat_AS_DOUBLE(value);
1358 if(nbCompExpected!=1)
1360 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1361 throw INTERP_KERNEL::Exception(oss.str().c_str());
1366 if(PyInt_Check(value))
1368 val=(double)PyInt_AS_LONG(value);
1370 if(nbCompExpected!=1)
1372 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1373 throw INTERP_KERNEL::Exception(oss.str().c_str());
1378 if(PyTuple_Check(value))
1380 int size=PyTuple_Size(value);
1382 for(int i=0;i<size;i++)
1384 PyObject *o=PyTuple_GetItem(value,i);
1385 if(PyFloat_Check(o))
1386 f[i]=PyFloat_AS_DOUBLE(o);
1387 else if(PyInt_Check(o))
1388 f[i]=(double)PyInt_AS_LONG(o);
1391 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1392 throw INTERP_KERNEL::Exception(oss.str().c_str());
1396 if(size%nbCompExpected!=0)
1398 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1399 throw INTERP_KERNEL::Exception(oss.str().c_str());
1401 nbTuples=size/nbCompExpected;
1404 if(PyList_Check(value))
1406 int size=PyList_Size(value);
1408 for(int i=0;i<size;i++)
1410 PyObject *o=PyList_GetItem(value,i);
1411 if(PyFloat_Check(o))
1412 f[i]=PyFloat_AS_DOUBLE(o);
1413 else if(PyInt_Check(o))
1414 f[i]=(double)PyInt_AS_LONG(o);
1417 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1418 throw INTERP_KERNEL::Exception(oss.str().c_str());
1422 if(size%nbCompExpected!=0)
1424 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1425 throw INTERP_KERNEL::Exception(oss.str().c_str());
1427 nbTuples=size/nbCompExpected;
1431 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1432 if(SWIG_IsOK(status))
1434 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1438 if(d->getNumberOfComponents()==nbCompExpected)
1440 nbTuples=d->getNumberOfTuples();
1441 return d->getConstPointer();
1445 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1446 throw INTERP_KERNEL::Exception(oss.str().c_str());
1453 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1454 throw INTERP_KERNEL::Exception(oss.str().c_str());
1460 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1461 if(SWIG_IsOK(status))
1463 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1465 if(e->getNumberOfCompo()==nbCompExpected)
1468 return e->getConstPointer();
1472 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1473 throw INTERP_KERNEL::Exception(oss.str().c_str());
1476 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1480 * if python int -> cpp int sw=1
1481 * if python list[int] -> cpp vector<int> sw=2
1482 * if python tuple[int] -> cpp vector<int> sw=2
1483 * if python DataArrayInt -> cpp DataArrayInt sw=3
1484 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1486 * switch between (int,vector<int>,DataArrayInt)
1488 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1491 if(PyInt_Check(value))
1493 iTyypp=(int)PyInt_AS_LONG(value);
1497 if(PyTuple_Check(value))
1499 int size=PyTuple_Size(value);
1500 stdvecTyypp.resize(size);
1501 for(int i=0;i<size;i++)
1503 PyObject *o=PyTuple_GetItem(value,i);
1505 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1508 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1509 throw INTERP_KERNEL::Exception(oss.str().c_str());
1513 return &stdvecTyypp[0];
1515 if(PyList_Check(value))
1517 int size=PyList_Size(value);
1518 stdvecTyypp.resize(size);
1519 for(int i=0;i<size;i++)
1521 PyObject *o=PyList_GetItem(value,i);
1523 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1526 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1527 throw INTERP_KERNEL::Exception(oss.str().c_str());
1531 return &stdvecTyypp[0];
1534 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1535 if(SWIG_IsOK(status))
1537 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1540 sw=3; sz=daIntTyypp->getNbOfElems();
1541 return daIntTyypp->begin();
1549 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1550 if(SWIG_IsOK(status))
1552 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1553 sw=4; sz=daIntTuple->getNumberOfCompo();
1554 return daIntTuple->getConstPointer();
1556 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");