1 // Copyright (C) 2007-2013 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
20 #include "InterpKernelAutoPtr.hxx"
23 #include <numpy/arrayobject.h>
26 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
29 if(dynamic_cast<ParaMEDMEM::MEDCouplingUMesh *>(mesh))
30 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner);
31 if(dynamic_cast<ParaMEDMEM::MEDCouplingExtrudedMesh *>(mesh))
32 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
33 if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
34 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
35 if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
36 ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
38 throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
42 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
45 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP0 *>(fd))
46 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner);
47 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationP1 *>(fd))
48 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP1,owner);
49 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGauss *>(fd))
50 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGauss,owner);
51 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationGaussNE *>(fd))
52 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationGaussNE,owner);
53 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldDiscretizationKriging *>(fd))
54 ret=SWIG_NewPointerObj(reinterpret_cast<void*>(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationKriging,owner);
56 throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
60 static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
63 if(dynamic_cast<ParaMEDMEM::DataArrayByte *>(dac))
64 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner);
65 if(dynamic_cast<ParaMEDMEM::DataArrayAsciiChar *>(dac))
66 ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner);
68 throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !");
72 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
75 if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
76 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
78 ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
82 static PyObject *convertIntArrToPyList(const int *ptr, int size) 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(ptr[i]));
90 npy_intp dim = (npy_intp) size;
91 int *tmp=new int[size];
92 std::copy(ptr,ptr+size,tmp);
93 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,const_cast<int *>(tmp));
97 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
101 PyObject *ret=PyList_New(size);
102 for(int i=0;i<size;i++)
103 PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
106 npy_intp dim = (npy_intp) v.size();
107 int *tmp=new int[v.size()];
108 std::copy(v.begin(),v.end(),tmp);
109 return PyArray_SimpleNewFromData(1,&dim,NPY_INT,tmp);
113 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
116 PyObject *ret=PyList_New(size);
117 std::set<int>::const_iterator it=v.begin();
118 for(int i=0;i<size;i++,it++)
119 PyList_SetItem(ret,i,PyInt_FromLong(*it));
123 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
125 PyObject *ret=PyList_New(nbOfTuples);
126 for(int i=0;i<nbOfTuples;i++)
128 PyObject *t=PyTuple_New(nbOfComp);
129 for(int j=0;j<nbOfComp;j++)
130 PyTuple_SetItem(t,j,PyInt_FromLong(vals[i*nbOfComp+j]));
131 PyList_SetItem(ret,i,t);
136 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
138 if(PyList_Check(pyLi))
140 *size=PyList_Size(pyLi);
141 int *tmp=new int[*size];
142 for(int i=0;i<*size;i++)
144 PyObject *o=PyList_GetItem(pyLi,i);
147 int val=(int)PyInt_AS_LONG(o);
153 throw INTERP_KERNEL::Exception("list must contain integers only");
158 else if(PyTuple_Check(pyLi))
160 *size=PyTuple_Size(pyLi);
161 int *tmp=new int[*size];
162 for(int i=0;i<*size;i++)
164 PyObject *o=PyTuple_GetItem(pyLi,i);
167 int val=(int)PyInt_AS_LONG(o);
173 throw INTERP_KERNEL::Exception("tuple must contain integers only");
181 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
183 if(PyArray_Check(pyLi))
185 npy_intp mySize = PyArray_SIZE(pyLi);
186 int *ret=(int *)PyArray_BYTES(pyLi);
192 throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
198 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
200 const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !";
201 if(PyList_Check(pyLi))
203 int size=PyList_Size(pyLi);
205 for(int i=0;i<size;i++)
207 PyObject *o=PyList_GetItem(pyLi,i);
210 int sz2=PyTuple_Size(o);
212 throw INTERP_KERNEL::Exception(msg);
213 PyObject *o_0=PyTuple_GetItem(o,0);
214 if(!PyInt_Check(o_0))
215 throw INTERP_KERNEL::Exception(msg);
216 PyObject *o_1=PyTuple_GetItem(o,1);
217 if(!PyInt_Check(o_1))
218 throw INTERP_KERNEL::Exception(msg);
219 arr[i].first=(int)PyInt_AS_LONG(o_0);
220 arr[i].second=(int)PyInt_AS_LONG(o_1);
223 throw INTERP_KERNEL::Exception(msg);
226 else if(PyTuple_Check(pyLi))
228 int size=PyTuple_Size(pyLi);
230 for(int i=0;i<size;i++)
232 PyObject *o=PyTuple_GetItem(pyLi,i);
235 int sz2=PyTuple_Size(o);
237 throw INTERP_KERNEL::Exception(msg);
238 PyObject *o_0=PyTuple_GetItem(o,0);
239 if(!PyInt_Check(o_0))
240 throw INTERP_KERNEL::Exception(msg);
241 PyObject *o_1=PyTuple_GetItem(o,1);
242 if(!PyInt_Check(o_1))
243 throw INTERP_KERNEL::Exception(msg);
244 arr[i].first=(int)PyInt_AS_LONG(o_0);
245 arr[i].second=(int)PyInt_AS_LONG(o_1);
248 throw INTERP_KERNEL::Exception(msg);
252 throw INTERP_KERNEL::Exception(msg);
255 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
257 if(PyList_Check(pyLi))
259 int size=PyList_Size(pyLi);
261 for(int i=0;i<size;i++)
263 PyObject *o=PyList_GetItem(pyLi,i);
266 int val=(int)PyInt_AS_LONG(o);
270 throw INTERP_KERNEL::Exception("list must contain integers only");
273 else if(PyTuple_Check(pyLi))
275 int size=PyTuple_Size(pyLi);
277 for(int i=0;i<size;i++)
279 PyObject *o=PyTuple_GetItem(pyLi,i);
282 int val=(int)PyInt_AS_LONG(o);
286 throw INTERP_KERNEL::Exception("tuple must contain integers only");
292 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
294 if(PyArray_Check(pyLi))
296 npy_intp mySize = PyArray_SIZE(pyLi);
297 int *ret=(int *)PyArray_BYTES(pyLi);
299 std::copy(ret,ret+mySize,arr.begin());
303 throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
308 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
311 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
313 if(PyList_Check(pyLi))
315 int size=PyList_Size(pyLi);
316 for(int i=0;i<size;i++)
318 PyObject *o=PyList_GetItem(pyLi,i);
321 int val=(int)PyInt_AS_LONG(o);
326 std::vector<int> arr2;
327 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
328 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
330 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
331 throw INTERP_KERNEL::Exception(oss.str().c_str());
333 arr.insert(arr.end(),arr2.begin(),arr2.end());
337 else if(PyTuple_Check(pyLi))
339 int size=PyTuple_Size(pyLi);
340 for(int i=0;i<size;i++)
342 PyObject *o=PyTuple_GetItem(pyLi,i);
345 int val=(int)PyInt_AS_LONG(o);
350 std::vector<int> arr2;
351 convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
352 if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
354 std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
355 throw INTERP_KERNEL::Exception(oss.str().c_str());
357 arr.insert(arr.end(),arr2.begin(),arr2.end());
362 throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
365 static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
369 if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
370 else { if(nbOfComp==size2) { nbOfTuples=size1; } else
372 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
373 oss << " whereas nb of components expected is " << nbOfComp << " !";
374 throw INTERP_KERNEL::Exception(oss.str().c_str());
381 if((nbOfTuples!=size1 || nbOfComp!=size2))
383 if(size2!=1 || size1!=nbOfComp*nbOfTuples)
385 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
386 oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
387 throw INTERP_KERNEL::Exception(oss.str().c_str());
393 if(nbOfTuples==size1)
397 std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
398 oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
399 throw INTERP_KERNEL::Exception(oss.str().c_str());
405 static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
407 static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
408 if(PyInt_Check(pyLi))
410 long val=PyInt_AS_LONG(pyLi);
415 throw INTERP_KERNEL::Exception(MSG);
418 else if(PyList_Check(pyLi))
420 int size=PyList_Size(pyLi);
422 for(int i=0;i<size;i++)
424 PyObject *o=PyList_GetItem(pyLi,i);
426 fillArrayWithPyListInt3(o,tmp1,ret);
434 throw INTERP_KERNEL::Exception(MSG);
437 else if(PyTuple_Check(pyLi))
439 int size=PyTuple_Size(pyLi);
441 for(int i=0;i<size;i++)
443 PyObject *o=PyTuple_GetItem(pyLi,i);
445 fillArrayWithPyListInt3(o,tmp1,ret);
453 throw INTERP_KERNEL::Exception(MSG);
457 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
460 static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
462 std::vector<int> ret;
463 int size1=-1,size2=-1;
464 if(PyList_Check(pyLi))
466 size1=PyList_Size(pyLi);
467 for(int i=0;i<size1;i++)
469 PyObject *o=PyList_GetItem(pyLi,i);
470 fillArrayWithPyListInt3(o,size2,ret);
475 else if(PyTuple_Check(pyLi))
477 size1=PyTuple_Size(pyLi);
478 for(int i=0;i<size1;i++)
480 PyObject *o=PyTuple_GetItem(pyLi,i);
481 fillArrayWithPyListInt3(o,size2,ret);
487 throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
489 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
493 static bool fillStringVector(PyObject *pyLi, std::vector<std::string>& vec) throw(INTERP_KERNEL::Exception)
495 if(PyList_Check(pyLi))
497 Py_ssize_t sz=PyList_Size(pyLi);
499 for(int i=0;i<sz;i++)
501 PyObject *o=PyList_GetItem(pyLi,i);
502 if(PyString_Check(o))
503 vec[i]=PyString_AsString(o);
509 else if(PyTuple_Check(pyLi))
511 Py_ssize_t sz=PyTuple_Size(pyLi);
513 for(int i=0;i<sz;i++)
515 PyObject *o=PyTuple_GetItem(pyLi,i);
516 if(PyString_Check(o))
517 vec[i]=PyString_AsString(o);
527 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
529 PyObject *ret=PyList_New(size);
530 for(int i=0;i<size;i++)
531 PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
535 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
538 PyObject *ret=PyList_New(size);
539 for(int i=0;i<size;i++)
540 PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
544 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
546 PyObject *ret=PyList_New(nbOfTuples);
547 for(int i=0;i<nbOfTuples;i++)
549 PyObject *t=PyTuple_New(nbOfComp);
550 for(int j=0;j<nbOfComp;j++)
551 PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
552 PyList_SetItem(ret,i,t);
557 static PyObject *convertCharArrToPyListOfTuple(const char *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
559 PyObject *ret=PyList_New(nbOfTuples);
560 INTERP_KERNEL::AutoPtr<char> tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0';
561 for(int i=0;i<nbOfTuples;i++)
563 std::copy(vals+i*nbOfComp,vals+(i+1)*nbOfComp,(char *)tmp);
564 PyList_SetItem(ret,i,PyString_FromString(tmp));
569 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
571 if(PyList_Check(pyLi))
573 *size=PyList_Size(pyLi);
574 double *tmp=new double[*size];
575 for(int i=0;i<*size;i++)
577 PyObject *o=PyList_GetItem(pyLi,i);
580 double val=PyFloat_AS_DOUBLE(o);
583 else if(PyInt_Check(o))
585 long val0=PyInt_AS_LONG(o);
592 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
597 else if(PyTuple_Check(pyLi))
599 *size=PyTuple_Size(pyLi);
600 double *tmp=new double[*size];
601 for(int i=0;i<*size;i++)
603 PyObject *o=PyTuple_GetItem(pyLi,i);
606 double val=PyFloat_AS_DOUBLE(o);
609 else if(PyInt_Check(o))
611 long val0=PyInt_AS_LONG(o);
618 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
624 throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
627 static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
629 static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
630 if(PyFloat_Check(pyLi))
636 throw INTERP_KERNEL::Exception(MSG);
637 double val=PyFloat_AS_DOUBLE(pyLi);
640 else if(PyInt_Check(pyLi))
642 long val0=PyInt_AS_LONG(pyLi);
648 throw INTERP_KERNEL::Exception(MSG);
651 else if(PyList_Check(pyLi))
653 int size=PyList_Size(pyLi);
655 for(int i=0;i<size;i++)
657 PyObject *o=PyList_GetItem(pyLi,i);
659 fillArrayWithPyListDbl3(o,tmp1,ret);
667 throw INTERP_KERNEL::Exception(MSG);
670 else if(PyTuple_Check(pyLi))
672 int size=PyTuple_Size(pyLi);
674 for(int i=0;i<size;i++)
676 PyObject *o=PyTuple_GetItem(pyLi,i);
678 fillArrayWithPyListDbl3(o,tmp1,ret);
686 throw INTERP_KERNEL::Exception(MSG);
690 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
693 static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
695 std::vector<double> ret;
696 int size1=-1,size2=-1;
697 if(PyList_Check(pyLi))
699 size1=PyList_Size(pyLi);
700 for(int i=0;i<size1;i++)
702 PyObject *o=PyList_GetItem(pyLi,i);
703 fillArrayWithPyListDbl3(o,size2,ret);
708 else if(PyTuple_Check(pyLi))
710 size1=PyTuple_Size(pyLi);
711 for(int i=0;i<size1;i++)
713 PyObject *o=PyTuple_GetItem(pyLi,i);
714 fillArrayWithPyListDbl3(o,size2,ret);
720 throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
722 checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
726 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
728 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
731 if(PyList_Check(pyLi))
733 int size=PyList_Size(pyLi);
735 for(int i=0;i<size;i++)
737 PyObject *obj=PyList_GetItem(pyLi,i);
738 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
739 if(!SWIG_IsOK(status))
740 throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
741 T arg=reinterpret_cast< T >(argp);
745 else if(PyTuple_Check(pyLi))
747 int size=PyTuple_Size(pyLi);
749 for(int i=0;i<size;i++)
751 PyObject *obj=PyTuple_GetItem(pyLi,i);
752 int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
753 if(!SWIG_IsOK(status))
755 std::ostringstream oss; oss << "tuple must contain only " << typeStr;
756 throw INTERP_KERNEL::Exception(oss.str().c_str());
758 T arg=reinterpret_cast< T >(argp);
762 else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
765 T arg=reinterpret_cast< T >(argp);
769 throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
773 * if python int -> cpp int sw=1
774 * if python list[int] -> cpp vector<int> sw=2
775 * if python tuple[int] -> cpp vector<int> sw=2
776 * if python DataArrayInt -> cpp DataArrayInt sw=3
777 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
779 * switch between (int,vector<int>,DataArrayInt)
781 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
784 if(PyInt_Check(value))
786 iTyypp=(int)PyInt_AS_LONG(value);
790 if(PyTuple_Check(value))
792 int size=PyTuple_Size(value);
793 stdvecTyypp.resize(size);
794 for(int i=0;i<size;i++)
796 PyObject *o=PyTuple_GetItem(value,i);
798 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
801 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
802 throw INTERP_KERNEL::Exception(oss.str().c_str());
808 if(PyList_Check(value))
810 int size=PyList_Size(value);
811 stdvecTyypp.resize(size);
812 for(int i=0;i<size;i++)
814 PyObject *o=PyList_GetItem(value,i);
816 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
819 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
820 throw INTERP_KERNEL::Exception(oss.str().c_str());
827 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
828 if(SWIG_IsOK(status))
830 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
834 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
835 if(SWIG_IsOK(status))
837 daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
841 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
845 * if python double -> cpp double sw=1
846 * if python int -> cpp double sw=1
847 * if python list[double] -> cpp vector<double> sw=2
848 * if python list[int] -> cpp vector<double> sw=2
849 * if python tuple[double] -> cpp vector<double> sw=2
850 * if python tuple[int] -> cpp vector<double> sw=2
851 * if python DataArrayDouble -> cpp DataArrayDouble sw=3
853 * switch between (int,vector<int>,DataArrayInt)
855 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
858 if(PyFloat_Check(value))
860 iTyypp=PyFloat_AS_DOUBLE(value);
864 if(PyInt_Check(value))
866 iTyypp=(double)PyInt_AS_LONG(value);
870 if(PyTuple_Check(value))
872 int size=PyTuple_Size(value);
873 stdvecTyypp.resize(size);
874 for(int i=0;i<size;i++)
876 PyObject *o=PyTuple_GetItem(value,i);
878 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
879 else if(PyInt_Check(o))
880 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
883 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
884 throw INTERP_KERNEL::Exception(oss.str().c_str());
890 if(PyList_Check(value))
892 int size=PyList_Size(value);
893 stdvecTyypp.resize(size);
894 for(int i=0;i<size;i++)
896 PyObject *o=PyList_GetItem(value,i);
898 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
899 else if(PyInt_Check(o))
900 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
903 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
904 throw INTERP_KERNEL::Exception(oss.str().c_str());
911 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
912 if(!SWIG_IsOK(status))
913 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
914 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
919 * if python double -> cpp double sw=1
920 * if python int -> cpp double sw=1
921 * if python list[double] -> cpp vector<double> sw=2
922 * if python list[int] -> cpp vector<double> sw=2
923 * if python tuple[double] -> cpp vector<double> sw=2
924 * if python tuple[int] -> cpp vector<double> sw=2
925 * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
927 * switch between (int,vector<int>,DataArrayInt)
929 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
932 if(PyFloat_Check(value))
934 iTyypp=PyFloat_AS_DOUBLE(value);
938 if(PyInt_Check(value))
940 iTyypp=(double)PyInt_AS_LONG(value);
944 if(PyTuple_Check(value))
946 int size=PyTuple_Size(value);
947 stdvecTyypp.resize(size);
948 for(int i=0;i<size;i++)
950 PyObject *o=PyTuple_GetItem(value,i);
952 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
953 else if(PyInt_Check(o))
954 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
957 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
958 throw INTERP_KERNEL::Exception(oss.str().c_str());
964 if(PyList_Check(value))
966 int size=PyList_Size(value);
967 stdvecTyypp.resize(size);
968 for(int i=0;i<size;i++)
970 PyObject *o=PyList_GetItem(value,i);
972 stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
973 else if(PyInt_Check(o))
974 stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
977 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
978 throw INTERP_KERNEL::Exception(oss.str().c_str());
985 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
986 if(!SWIG_IsOK(status))
987 throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
988 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
993 * if python int -> cpp int sw=1
994 * if python list[int] -> cpp vector<int> sw=2
995 * if python tuple[int] -> cpp vector<int> sw=2
996 * if python slicp -> cpp pair sw=3 (begin,end,step)
997 * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown.
999 * switch between (int,vector<int>,DataArrayInt)
1001 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)
1003 const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
1005 if(PyInt_Check(value))
1007 iTyypp=(int)PyInt_AS_LONG(value);
1011 if(PyTuple_Check(value))
1013 int size=PyTuple_Size(value);
1014 stdvecTyypp.resize(size);
1015 for(int i=0;i<size;i++)
1017 PyObject *o=PyTuple_GetItem(value,i);
1019 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1022 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1023 throw INTERP_KERNEL::Exception(oss.str().c_str());
1029 if(PyList_Check(value))
1031 int size=PyList_Size(value);
1032 stdvecTyypp.resize(size);
1033 for(int i=0;i<size;i++)
1035 PyObject *o=PyList_GetItem(value,i);
1037 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1040 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1041 throw INTERP_KERNEL::Exception(oss.str().c_str());
1047 if(PySlice_Check(value))
1049 Py_ssize_t strt=2,stp=2,step=2;
1050 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1051 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1052 if(nbelem!=0 || strt!=0 || stp!=0)
1054 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1055 throw INTERP_KERNEL::Exception(oss.str().c_str());
1059 p.second.second=step;
1064 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1065 if(SWIG_IsOK(status))
1067 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1070 std::ostringstream oss; oss << msg << " Instance in null !";
1071 throw INTERP_KERNEL::Exception(oss.str().c_str());
1076 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1077 if(SWIG_IsOK(status))
1079 ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1082 std::ostringstream oss; oss << msg << " Instance in null !";
1083 throw INTERP_KERNEL::Exception(oss.str().c_str());
1085 stdvecTyypp.resize(tmp->getNumberOfCompo());
1086 std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
1090 throw INTERP_KERNEL::Exception(msg);
1094 * if python int -> cpp int sw=1
1095 * if python tuple[int] -> cpp vector<int> sw=2
1096 * if python list[int] -> cpp vector<int> sw=2
1097 * if python slice -> cpp pair sw=3
1098 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer !
1100 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)
1103 if(PyInt_Check(value))
1105 iTyypp=(int)PyInt_AS_LONG(value);
1109 if(PyTuple_Check(value))
1111 int size=PyTuple_Size(value);
1112 stdvecTyypp.resize(size);
1113 for(int i=0;i<size;i++)
1115 PyObject *o=PyTuple_GetItem(value,i);
1117 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1120 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1121 throw INTERP_KERNEL::Exception(oss.str().c_str());
1127 if(PyList_Check(value))
1129 int size=PyList_Size(value);
1130 stdvecTyypp.resize(size);
1131 for(int i=0;i<size;i++)
1133 PyObject *o=PyList_GetItem(value,i);
1135 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1138 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1139 throw INTERP_KERNEL::Exception(oss.str().c_str());
1145 if(PySlice_Check(value))
1147 Py_ssize_t strt=2,stp=2,step=2;
1148 PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
1149 if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
1150 if(nbelem!=0 || strt!=0 || stp!=0)
1152 std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
1153 throw INTERP_KERNEL::Exception(oss.str().c_str());
1157 p.second.second=step;
1162 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1163 if(!SWIG_IsOK(status))
1164 throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
1165 daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1170 * if python string with size one -> cpp char sw=1
1171 * if python string with size different from one -> cpp string sw=2
1172 * if python tuple[string] or list[string] -> vector<string> sw=3
1173 * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4
1174 * switch between (int,string,vector<string>,DataArrayChar)
1176 static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector<std::string>& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception)
1178 const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance.";
1180 if(PyString_Check(value))
1182 const char *pt=PyString_AsString(value);
1183 Py_ssize_t sz=PyString_Size(value);
1197 if(PyTuple_Check(value))
1199 int size=PyTuple_Size(value);
1200 vsType.resize(size);
1201 for(int i=0;i<size;i++)
1203 PyObject *o=PyTuple_GetItem(value,i);
1204 if(PyString_Check(o))
1205 vsType[i]=PyString_AsString(o);
1208 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not a string ! only tuples of strings accepted !";
1209 throw INTERP_KERNEL::Exception(oss.str().c_str());
1215 if(PyList_Check(value))
1217 int size=PyList_Size(value);
1218 vsType.resize(size);
1219 for(int i=0;i<size;i++)
1221 PyObject *o=PyList_GetItem(value,i);
1222 if(PyString_Check(o))
1223 vsType[i]=PyString_AsString(o);
1226 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not string ! only lists of strings accepted !";
1227 throw INTERP_KERNEL::Exception(oss.str().c_str());
1234 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0);
1235 if(SWIG_IsOK(status))
1237 dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp);
1240 std::ostringstream oss; oss << msg << " Instance in null !";
1241 throw INTERP_KERNEL::Exception(oss.str().c_str());
1246 throw INTERP_KERNEL::Exception(msg);
1250 * if value int -> cpp it sw=1
1251 * if value list[int] -> vt sw=2
1252 * if value tuple[int] -> vt sw=2
1253 * if value slice -> pt sw=3
1254 * if value DataArrayInt -> dt sw=4
1255 * if value tuple [int,int] -> cpp it,ip sw=5
1256 * if value tuple [list[int],int] -> cpp vt,ip sw=6
1257 * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1258 * if value tuple [slice,int] -> cpp pt,ip sw=7
1259 * if value tuple [DaI,int] -> cpp dt,ip sw=8
1260 * if value tuple [int,list[int]] -> cpp it,vc sw=9
1261 * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1262 * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1263 * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1264 * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1265 * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1266 * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1267 * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1268 * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1269 * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1270 * if value tuple [int,slice] -> cpp it,pc sw=13
1271 * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1272 * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1273 * if value tuple [slice,slice] -> cpp pt,pc sw=15
1274 * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1276 * switch between (int,vector<int>,DataArrayInt)
1278 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1279 std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1280 ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1282 if(!PyTuple_Check(value))
1284 convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1289 int sz=PyTuple_Size(value);
1291 throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1292 PyObject *ob0=PyTuple_GetItem(value,0);
1294 convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1295 PyObject *ob1=PyTuple_GetItem(value,1);
1296 convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1302 * if value int -> cpp val sw=1
1303 * if value double -> cpp val sw=1
1304 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1305 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1306 * if value list[int,double] -> cpp std::vector<double> sw=4
1307 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1309 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1312 if(PyFloat_Check(value))
1314 val=PyFloat_AS_DOUBLE(value);
1318 if(PyInt_Check(value))
1320 val=(double)PyInt_AS_LONG(value);
1324 if(PyTuple_Check(value))
1326 int size=PyTuple_Size(value);
1328 for(int i=0;i<size;i++)
1330 PyObject *o=PyTuple_GetItem(value,i);
1331 if(PyFloat_Check(o))
1332 f[i]=PyFloat_AS_DOUBLE(o);
1333 else if(PyInt_Check(o))
1334 f[i]=(double)PyInt_AS_LONG(o);
1337 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1338 throw INTERP_KERNEL::Exception(oss.str().c_str());
1344 if(PyList_Check(value))
1346 int size=PyList_Size(value);
1348 for(int i=0;i<size;i++)
1350 PyObject *o=PyList_GetItem(value,i);
1351 if(PyFloat_Check(o))
1352 f[i]=PyFloat_AS_DOUBLE(o);
1353 else if(PyInt_Check(o))
1354 f[i]=(double)PyInt_AS_LONG(o);
1357 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1358 throw INTERP_KERNEL::Exception(oss.str().c_str());
1365 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1366 if(SWIG_IsOK(status))
1368 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1372 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1373 if(SWIG_IsOK(status))
1375 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1379 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1383 * if value int -> cpp val sw=1
1384 * if value double -> cpp val sw=1
1385 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1386 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1387 * if value list[int,double] -> cpp std::vector<double> sw=4
1388 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1390 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1391 const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1394 if(PyFloat_Check(value))
1396 val=PyFloat_AS_DOUBLE(value);
1398 if(nbTuplesExpected*nbCompExpected!=1)
1400 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1401 throw INTERP_KERNEL::Exception(oss.str().c_str());
1405 if(PyInt_Check(value))
1407 val=(double)PyInt_AS_LONG(value);
1409 if(nbTuplesExpected*nbCompExpected!=1)
1411 std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1412 throw INTERP_KERNEL::Exception(oss.str().c_str());
1416 if(PyTuple_Check(value) || PyList_Check(value))
1420 int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
1421 std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
1426 catch(INTERP_KERNEL::Exception& e) { throw e; }
1429 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1430 if(SWIG_IsOK(status))
1432 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1436 if(d->getNumberOfTuples()==nbTuplesExpected)
1438 if(d->getNumberOfComponents()==nbCompExpected)
1440 return d->getConstPointer();
1444 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1445 throw INTERP_KERNEL::Exception(oss.str().c_str());
1450 std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1451 throw INTERP_KERNEL::Exception(oss.str().c_str());
1458 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1459 throw INTERP_KERNEL::Exception(oss.str().c_str());
1465 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1466 if(SWIG_IsOK(status))
1468 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1470 if(e->getNumberOfCompo()==nbCompExpected)
1472 if(nbTuplesExpected==1)
1473 return e->getConstPointer();
1476 std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1477 throw INTERP_KERNEL::Exception(oss.str().c_str());
1482 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1483 throw INTERP_KERNEL::Exception(oss.str().c_str());
1486 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1490 * if value int -> cpp val sw=1
1491 * if value double -> cpp val sw=1
1492 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1493 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1494 * if value list[int,double] -> cpp std::vector<double> sw=4
1495 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1497 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1498 const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1501 if(PyFloat_Check(value))
1503 val=PyFloat_AS_DOUBLE(value);
1505 if(nbCompExpected!=1)
1507 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !";
1508 throw INTERP_KERNEL::Exception(oss.str().c_str());
1513 if(PyInt_Check(value))
1515 val=(double)PyInt_AS_LONG(value);
1517 if(nbCompExpected!=1)
1519 std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !";
1520 throw INTERP_KERNEL::Exception(oss.str().c_str());
1525 if(PyTuple_Check(value))
1527 int size=PyTuple_Size(value);
1529 for(int i=0;i<size;i++)
1531 PyObject *o=PyTuple_GetItem(value,i);
1532 if(PyFloat_Check(o))
1533 f[i]=PyFloat_AS_DOUBLE(o);
1534 else if(PyInt_Check(o))
1535 f[i]=(double)PyInt_AS_LONG(o);
1538 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1539 throw INTERP_KERNEL::Exception(oss.str().c_str());
1543 if(size%nbCompExpected!=0)
1545 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1546 throw INTERP_KERNEL::Exception(oss.str().c_str());
1548 nbTuples=size/nbCompExpected;
1551 if(PyList_Check(value))
1553 int size=PyList_Size(value);
1555 for(int i=0;i<size;i++)
1557 PyObject *o=PyList_GetItem(value,i);
1558 if(PyFloat_Check(o))
1559 f[i]=PyFloat_AS_DOUBLE(o);
1560 else if(PyInt_Check(o))
1561 f[i]=(double)PyInt_AS_LONG(o);
1564 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1565 throw INTERP_KERNEL::Exception(oss.str().c_str());
1569 if(size%nbCompExpected!=0)
1571 std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
1572 throw INTERP_KERNEL::Exception(oss.str().c_str());
1574 nbTuples=size/nbCompExpected;
1578 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1579 if(SWIG_IsOK(status))
1581 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1585 if(d->getNumberOfComponents()==nbCompExpected)
1587 nbTuples=d->getNumberOfTuples();
1588 return d->getConstPointer();
1592 std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1593 throw INTERP_KERNEL::Exception(oss.str().c_str());
1600 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1601 throw INTERP_KERNEL::Exception(oss.str().c_str());
1604 { nbTuples=0; return 0; }
1607 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1608 if(SWIG_IsOK(status))
1610 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1614 if(e->getNumberOfCompo()==nbCompExpected)
1617 return e->getConstPointer();
1621 std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1622 throw INTERP_KERNEL::Exception(oss.str().c_str());
1629 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1630 throw INTERP_KERNEL::Exception(oss.str().c_str());
1633 { nbTuples=0; return 0; }
1636 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1640 * if value int -> cpp val sw=1
1641 * if value double -> cpp val sw=1
1642 * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1643 * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1644 * if value list[int,double] -> cpp std::vector<double> sw=4
1645 * if value tuple[int,double] -> cpp std::vector<double> sw=4
1647 static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector<double>& f,
1648 const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1650 ParaMEDMEM::DataArrayDouble *d=0;
1651 ParaMEDMEM::DataArrayDoubleTuple *e=0;
1653 if(PyFloat_Check(value))
1655 val=PyFloat_AS_DOUBLE(value);
1660 if(PyInt_Check(value))
1662 val=(double)PyInt_AS_LONG(value);
1667 if(PyTuple_Check(value))
1669 int size=PyTuple_Size(value);
1671 for(int i=0;i<size;i++)
1673 PyObject *o=PyTuple_GetItem(value,i);
1674 if(PyFloat_Check(o))
1675 f[i]=PyFloat_AS_DOUBLE(o);
1676 else if(PyInt_Check(o))
1677 f[i]=(double)PyInt_AS_LONG(o);
1680 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1681 throw INTERP_KERNEL::Exception(oss.str().c_str());
1688 if(PyList_Check(value))
1690 int size=PyList_Size(value);
1692 for(int i=0;i<size;i++)
1694 PyObject *o=PyList_GetItem(value,i);
1695 if(PyFloat_Check(o))
1696 f[i]=PyFloat_AS_DOUBLE(o);
1697 else if(PyInt_Check(o))
1698 f[i]=(double)PyInt_AS_LONG(o);
1701 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1702 throw INTERP_KERNEL::Exception(oss.str().c_str());
1710 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1711 if(SWIG_IsOK(status))
1713 d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1717 if(d->getNumberOfComponents()==1)
1719 nbTuples=d->getNumberOfTuples();
1720 return d->getConstPointer();
1724 std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !";
1725 throw INTERP_KERNEL::Exception(oss.str().c_str());
1732 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1733 throw INTERP_KERNEL::Exception(oss.str().c_str());
1736 { nbTuples=0; return 0; }
1739 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1740 if(SWIG_IsOK(status))
1742 e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1746 nbTuples=e->getNumberOfCompo();
1747 return e->getConstPointer();
1753 std::ostringstream oss; oss << msg << " null pointer not accepted!";
1754 throw INTERP_KERNEL::Exception(oss.str().c_str());
1757 { nbTuples=0; return 0; }
1760 throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1764 * if python int -> cpp int sw=1
1765 * if python list[int] -> cpp vector<int> sw=2
1766 * if python tuple[int] -> cpp vector<int> sw=2
1767 * if python DataArrayInt -> cpp DataArrayInt sw=3
1768 * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
1770 * switch between (int,vector<int>,DataArrayInt)
1772 static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
1775 if(PyInt_Check(value))
1777 iTyypp=(int)PyInt_AS_LONG(value);
1781 if(PyTuple_Check(value))
1783 int size=PyTuple_Size(value);
1784 stdvecTyypp.resize(size);
1785 for(int i=0;i<size;i++)
1787 PyObject *o=PyTuple_GetItem(value,i);
1789 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1792 std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
1793 throw INTERP_KERNEL::Exception(oss.str().c_str());
1797 return &stdvecTyypp[0];
1799 if(PyList_Check(value))
1801 int size=PyList_Size(value);
1802 stdvecTyypp.resize(size);
1803 for(int i=0;i<size;i++)
1805 PyObject *o=PyList_GetItem(value,i);
1807 stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
1810 std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
1811 throw INTERP_KERNEL::Exception(oss.str().c_str());
1815 return &stdvecTyypp[0];
1818 int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
1819 if(SWIG_IsOK(status))
1821 ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
1824 sw=3; sz=daIntTyypp->getNbOfElems();
1825 return daIntTyypp->begin();
1833 status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
1834 if(SWIG_IsOK(status))
1836 ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
1837 sw=4; sz=daIntTuple->getNumberOfCompo();
1838 return daIntTuple->getConstPointer();
1840 throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");