Salome HOME
Merge from V6_main (04/10/2012)
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingTypemaps.i
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifdef WITH_NUMPY2
21 #include <numpy/arrayobject.h>
22 #endif
23
24 static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception)
25 {
26   PyObject *ret=0;
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(!ret)
34     throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
35   return ret;
36 }
37
38 static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception)
39 {
40   PyObject *ret=0;
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);
51   if(!ret)
52     throw INTERP_KERNEL::Exception("Not recognized type of field discretization on downcast !");
53   return ret;
54 }
55
56 static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception)
57 {
58   PyObject *ret=0;
59   if(dynamic_cast<ParaMEDMEM::MEDCouplingFieldOverTime *>(mfs))
60     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner);
61   else
62     ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingMultiFields,owner);
63   return ret;
64 }
65
66 static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception)
67 {
68 #ifndef WITH_NUMPY2
69   PyObject *ret=PyList_New(size);
70   for(int i=0;i<size;i++)
71     PyList_SetItem(ret,i,PyInt_FromLong(ptr[i]));
72   return ret;
73 #else
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));
78 #endif
79 }
80
81 static PyObject *convertIntArrToPyList2(const std::vector<int>& v) throw(INTERP_KERNEL::Exception)
82 {
83 #ifndef WITH_NUMPY2
84   int size=v.size();
85   PyObject *ret=PyList_New(size);
86   for(int i=0;i<size;i++)
87     PyList_SetItem(ret,i,PyInt_FromLong(v[i]));
88   return ret;
89 #else
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);
94 #endif
95 }
96
97 static PyObject *convertIntArrToPyList3(const std::set<int>& v) throw(INTERP_KERNEL::Exception)
98 {
99   int size=v.size();
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));
104   return ret;
105 }
106
107 static PyObject *convertIntArrToPyListOfTuple(const int *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
108 {
109   PyObject *ret=PyList_New(nbOfTuples);
110   for(int i=0;i<nbOfTuples;i++)
111     {
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);
116     }
117   return ret;
118 }
119
120 static int *convertPyToNewIntArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
121 {
122   if(PyList_Check(pyLi))
123     {
124       *size=PyList_Size(pyLi);
125       int *tmp=new int[*size];
126       for(int i=0;i<*size;i++)
127         {
128           PyObject *o=PyList_GetItem(pyLi,i);
129           if(PyInt_Check(o))
130             {
131               int val=(int)PyInt_AS_LONG(o);
132               tmp[i]=val;
133             }
134           else
135             {
136               delete [] tmp;
137               throw INTERP_KERNEL::Exception("list must contain integers only");
138             }
139         }
140       return tmp;
141     }
142   else if(PyTuple_Check(pyLi))
143     {
144       *size=PyTuple_Size(pyLi);
145       int *tmp=new int[*size];
146       for(int i=0;i<*size;i++)
147         {
148           PyObject *o=PyTuple_GetItem(pyLi,i);
149           if(PyInt_Check(o))
150             {
151               int val=(int)PyInt_AS_LONG(o);
152               tmp[i]=val;
153             }
154           else
155             {
156               delete [] tmp;
157               throw INTERP_KERNEL::Exception("tuple must contain integers only");
158             }
159         }
160       return tmp;
161     }
162   else
163     {
164 #ifndef WITH_NUMPY2
165       throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list");
166 #else
167       if(PyArray_Check(pyLi))
168         {
169           npy_intp mySize = PyArray_SIZE(pyLi);
170           int *ret=(int *)PyArray_BYTES(pyLi);
171           *size=mySize;
172           return ret;
173         }
174       else
175         {
176           throw INTERP_KERNEL::Exception("convertPyToNewIntArr2 : not a list nor PyArray");
177         }
178 #endif
179     }
180 }
181
182 static void convertPyToVectorPairInt(PyObject *pyLi, std::vector< std::pair<int,int> >& arr) throw(INTERP_KERNEL::Exception)
183 {
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))
186     {
187       int size=PyList_Size(pyLi);
188       arr.resize(size);
189       for(int i=0;i<size;i++)
190         {
191           PyObject *o=PyList_GetItem(pyLi,i);
192           if(PyTuple_Check(o))
193             {
194               int sz2=PyTuple_Size(o);
195               if(sz2!=2)
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);
205             }
206           else
207             throw INTERP_KERNEL::Exception(msg);
208         }
209     }
210   else if(PyTuple_Check(pyLi))
211     {
212       int size=PyTuple_Size(pyLi);
213       arr.resize(size);
214       for(int i=0;i<size;i++)
215         {
216           PyObject *o=PyTuple_GetItem(pyLi,i);
217           if(PyTuple_Check(o))
218             {
219               int sz2=PyTuple_Size(o);
220               if(sz2!=2)
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);
230             }
231           else
232             throw INTERP_KERNEL::Exception(msg);
233         }
234     }
235   else
236     throw INTERP_KERNEL::Exception(msg);
237 }
238
239 static void convertPyToNewIntArr3(PyObject *pyLi, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
240 {
241   if(PyList_Check(pyLi))
242     {
243       int size=PyList_Size(pyLi);
244       arr.resize(size);
245       for(int i=0;i<size;i++)
246         {
247           PyObject *o=PyList_GetItem(pyLi,i);
248           if(PyInt_Check(o))
249             {
250               int val=(int)PyInt_AS_LONG(o);
251               arr[i]=val;
252             }
253           else
254             throw INTERP_KERNEL::Exception("list must contain integers only");
255         }
256     }
257   else if(PyTuple_Check(pyLi))
258     {
259       int size=PyTuple_Size(pyLi);
260       arr.resize(size);
261       for(int i=0;i<size;i++)
262         {
263           PyObject *o=PyTuple_GetItem(pyLi,i);
264           if(PyInt_Check(o))
265             {
266               int val=(int)PyInt_AS_LONG(o);
267               arr[i]=val;
268             }
269           else
270             throw INTERP_KERNEL::Exception("tuple must contain integers only");
271         }
272     }
273   else
274     {
275 #ifndef WITH_NUMPY2
276       throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple");
277 #else
278       if(PyArray_Check(pyLi))
279         {
280           npy_intp mySize = PyArray_SIZE(pyLi);
281           int *ret=(int *)PyArray_BYTES(pyLi);
282           arr.resize(mySize);
283           std::copy(ret,ret+mySize,arr.begin());
284           return ;
285         }
286       else
287         throw INTERP_KERNEL::Exception("convertPyToNewIntArr3 : not a list nor a tuple nor PyArray");
288 #endif
289     }
290 }
291
292 static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPart, std::vector<int>& arr) throw(INTERP_KERNEL::Exception)
293 {
294   if(recurseLev<0)
295     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
296   arr.clear();
297   if(PyList_Check(pyLi))
298     {
299       int size=PyList_Size(pyLi);
300       for(int i=0;i<size;i++)
301         {
302           PyObject *o=PyList_GetItem(pyLi,i);
303           if(PyInt_Check(o))
304             {
305               int val=(int)PyInt_AS_LONG(o);
306               arr.push_back(val);
307             }
308           else
309             {
310               std::vector<int> arr2;
311               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
312               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
313                   {
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());
316                   }
317               arr.insert(arr.end(),arr2.begin(),arr2.end());
318             }
319         }
320     }
321   else if(PyTuple_Check(pyLi))
322     {
323       int size=PyTuple_Size(pyLi);
324       for(int i=0;i<size;i++)
325         {
326           PyObject *o=PyTuple_GetItem(pyLi,i);
327           if(PyInt_Check(o))
328             {
329               int val=(int)PyInt_AS_LONG(o);
330               arr.push_back(val);
331             }
332           else
333             {
334               std::vector<int> arr2;
335               convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
336               if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
337                   {
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());
340                   }
341               arr.insert(arr.end(),arr2.begin(),arr2.end());
342             }
343         }
344     }
345   else
346     throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
347 }
348
349
350 static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
351 {
352   if(PyList_Check(pyLi))
353     {
354       int size=PyList_Size(pyLi);
355       if(chckSize)
356         if(size!=sizeOfArray)
357           {
358             std::ostringstream oss; oss << "fillArrayWithPyListInt : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
359             throw INTERP_KERNEL::Exception(oss.str().c_str());
360           }
361       for(int i=0;i<size;i++)
362         {
363           PyObject *o=PyList_GetItem(pyLi,i);
364           if(PyInt_Check(o))
365             {
366               int val=(int)PyInt_AS_LONG(o);
367               if(i<sizeOfArray)
368                 arrToFill[i]=val;
369             }
370           else
371             throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : List must contain integers only !");
372         }
373       for(int i=size;i<sizeOfArray;i++)
374         arrToFill[i]=dftVal;
375       return;
376       
377     }
378   else if(PyTuple_Check(pyLi))
379     {
380       int size=PyTuple_Size(pyLi);
381       if(chckSize)
382         if(size!=sizeOfArray)
383           {
384             std::ostringstream oss; oss << "fillArrayWithPyListInt : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
385             throw INTERP_KERNEL::Exception(oss.str().c_str());
386           }
387       for(int i=0;i<size;i++)
388         {
389           PyObject *o=PyTuple_GetItem(pyLi,i);
390           if(PyInt_Check(o))
391             {
392               int val=(int)PyInt_AS_LONG(o);
393               if(i<sizeOfArray)
394                 arrToFill[i]=val;
395             }
396           else
397             throw INTERP_KERNEL::Exception("tuple must contain integers only");
398         }
399       for(int i=size;i<sizeOfArray;i++)
400         arrToFill[i]=dftVal;
401       return;
402     }
403   else
404     throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : not a list");
405 }
406
407 static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
408 {
409   PyObject *ret=PyList_New(size);
410   for(int i=0;i<size;i++)
411     PyList_SetItem(ret,i,PyFloat_FromDouble(ptr[i]));
412   return ret;
413 }
414
415 static PyObject *convertDblArrToPyList2(const std::vector<double>& v) throw(INTERP_KERNEL::Exception)
416 {
417   int size=v.size();
418   PyObject *ret=PyList_New(size);
419   for(int i=0;i<size;i++)
420     PyList_SetItem(ret,i,PyFloat_FromDouble(v[i]));
421   return ret;
422 }
423
424 static PyObject *convertDblArrToPyListOfTuple(const double *vals, int nbOfComp, int nbOfTuples) throw(INTERP_KERNEL::Exception)
425 {
426   PyObject *ret=PyList_New(nbOfTuples);
427   for(int i=0;i<nbOfTuples;i++)
428     {
429       PyObject *t=PyTuple_New(nbOfComp);
430       for(int j=0;j<nbOfComp;j++)
431         PyTuple_SetItem(t,j,PyFloat_FromDouble(vals[i*nbOfComp+j]));
432       PyList_SetItem(ret,i,t);
433     }
434   return ret;
435 }
436
437 static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KERNEL::Exception)
438 {
439   if(PyList_Check(pyLi))
440     {
441       *size=PyList_Size(pyLi);
442       double *tmp=new double[*size];
443       for(int i=0;i<*size;i++)
444         {
445           PyObject *o=PyList_GetItem(pyLi,i);
446           if(PyFloat_Check(o))
447             {
448               double val=PyFloat_AS_DOUBLE(o);
449               tmp[i]=val;
450             }
451           else if(PyInt_Check(o))
452             {
453               long val0=PyInt_AS_LONG(o);
454               double val=val0;
455               tmp[i]=val;
456             }
457           else
458             {
459               delete [] tmp;
460               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : list must contain floats/integers only");
461             }
462         }
463       return tmp;
464     }
465   else if(PyTuple_Check(pyLi))
466     {
467       *size=PyTuple_Size(pyLi);
468       double *tmp=new double[*size];
469       for(int i=0;i<*size;i++)
470         {
471           PyObject *o=PyTuple_GetItem(pyLi,i);
472           if(PyFloat_Check(o))
473             {
474               double val=PyFloat_AS_DOUBLE(o);
475               tmp[i]=val;
476             }
477           else if(PyInt_Check(o))
478             {
479               long val0=PyInt_AS_LONG(o);
480               double val=val0;
481               tmp[i]=val;
482             }
483           else
484             {
485               delete [] tmp;
486               throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : tuple must contain floats/integers only");
487             }
488         }
489       return tmp;
490     }
491   else
492     throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
493 }
494
495 static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
496 {
497   if(PyList_Check(pyLi))
498     {
499       int size=PyList_Size(pyLi);
500       if(chckSize)
501         if(size!=sizeOfArray)
502           {
503             std::ostringstream oss; oss << "fillArrayWithPyListDbl : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
504             throw INTERP_KERNEL::Exception(oss.str().c_str());
505           }
506       for(int i=0;i<size;i++)
507         {
508           PyObject *o=PyList_GetItem(pyLi,i);
509           if(PyFloat_Check(o))
510             {
511               double val=PyFloat_AS_DOUBLE(o);
512               if(i<sizeOfArray)
513                 arrToFill[i]=val;
514             }
515           else if(PyInt_Check(o))
516             {
517               long val0=PyInt_AS_LONG(o);
518               double val=val0;
519               if(i<sizeOfArray)
520                 arrToFill[i]=val;
521             }
522           else
523             throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : list must contain floats/integers only");
524         }
525       for(int i=size;i<sizeOfArray;i++)
526         arrToFill[i]=dftVal;
527       return;
528     }
529   else if(PyTuple_Check(pyLi))
530     {
531       int size=PyTuple_Size(pyLi);
532       if(chckSize)
533         if(size!=sizeOfArray)
534           {
535             std::ostringstream oss; oss << "fillArrayWithPyListDbl : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
536             throw INTERP_KERNEL::Exception(oss.str().c_str());
537           }
538       for(int i=0;i<size;i++)
539         {
540           PyObject *o=PyTuple_GetItem(pyLi,i);
541           if(PyFloat_Check(o))
542             {
543               double val=PyFloat_AS_DOUBLE(o);
544               arrToFill[i]=val;
545             }
546           else if(PyInt_Check(o))
547             {
548               long val0=PyInt_AS_LONG(o);
549               double val=val0;
550               arrToFill[i]=val;
551             }
552           else
553             throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : tuple must contain floats/integers only");
554         }
555       for(int i=size;i<sizeOfArray;i++)
556         arrToFill[i]=dftVal;
557       return ;
558     }
559   else
560     throw INTERP_KERNEL::Exception("convertPyToNewIntArr : not a list");
561 }
562
563 //convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
564 template<class T>
565 static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector<T>& ret)
566 {
567   void *argp=0;
568   if(PyList_Check(pyLi))
569     {
570       int size=PyList_Size(pyLi);
571       ret.resize(size);
572       for(int i=0;i<size;i++)
573         {
574           PyObject *obj=PyList_GetItem(pyLi,i);
575           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
576           if(!SWIG_IsOK(status))
577             throw INTERP_KERNEL::Exception("list must contain only MEDCouplingUMesh");
578           T arg=reinterpret_cast< T >(argp);
579           ret[i]=arg;
580         }
581     }
582   else if(PyTuple_Check(pyLi))
583     {
584       int size=PyTuple_Size(pyLi);
585       ret.resize(size);
586       for(int i=0;i<size;i++)
587         {
588           PyObject *obj=PyTuple_GetItem(pyLi,i);
589           void *argp;
590           int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
591           if(!SWIG_IsOK(status))
592             {
593               std::ostringstream oss; oss << "tuple must contain only " << typeStr;
594               throw INTERP_KERNEL::Exception(oss.str().c_str());
595             }
596           T arg=reinterpret_cast< T >(argp);
597           ret[i]=arg;
598         }
599     }
600   else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0)))
601     {
602       ret.resize(1);
603       T arg=reinterpret_cast< T >(argp);
604       ret[0]=arg;
605     }
606   else
607     throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple");
608 }
609
610 /*!
611  * if python int -> cpp int sw=1
612  * if python list[int] -> cpp vector<int> sw=2
613  * if python tuple[int] -> cpp vector<int> sw=2
614  * if python DataArrayInt -> cpp DataArrayInt sw=3
615  * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
616  *
617  * switch between (int,vector<int>,DataArrayInt)
618  */
619 static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception)
620 {
621   sw=-1;
622   if(PyInt_Check(value))
623     {
624       iTyypp=(int)PyInt_AS_LONG(value);
625       sw=1;
626       return;
627     }
628   if(PyTuple_Check(value))
629     {
630       int size=PyTuple_Size(value);
631       stdvecTyypp.resize(size);
632       for(int i=0;i<size;i++)
633         {
634           PyObject *o=PyTuple_GetItem(value,i);
635           if(PyInt_Check(o))
636             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
637           else
638             {
639               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
640               throw INTERP_KERNEL::Exception(oss.str().c_str());
641             }
642         }
643       sw=2;
644       return;
645     }
646   if(PyList_Check(value))
647     {
648       int size=PyList_Size(value);
649       stdvecTyypp.resize(size);
650       for(int i=0;i<size;i++)
651         {
652           PyObject *o=PyList_GetItem(value,i);
653           if(PyInt_Check(o))
654             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
655           else
656             {
657               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
658               throw INTERP_KERNEL::Exception(oss.str().c_str());
659             }
660         }
661       sw=2;
662       return;
663     }
664   void *argp;
665   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
666   if(SWIG_IsOK(status))
667     {
668       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
669       sw=3;
670       return;
671     }
672   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
673   if(SWIG_IsOK(status))
674     {  
675       daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
676       sw=4;
677       return ;
678     }
679   throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
680 }
681
682 /*!
683  * if python double -> cpp double sw=1
684  * if python int -> cpp double sw=1
685  * if python list[double] -> cpp vector<double> sw=2
686  * if python list[int] -> cpp vector<double> sw=2
687  * if python tuple[double] -> cpp vector<double> sw=2
688  * if python tuple[int] -> cpp vector<double> sw=2
689  * if python DataArrayDouble -> cpp DataArrayDouble sw=3
690  *
691  * switch between (int,vector<int>,DataArrayInt)
692  */
693 static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception)
694 {
695   sw=-1;
696   if(PyFloat_Check(value))
697     {
698       iTyypp=PyFloat_AS_DOUBLE(value);
699       sw=1;
700       return;
701     }
702   if(PyInt_Check(value))
703     {
704       iTyypp=(double)PyInt_AS_LONG(value);
705       sw=1;
706       return;
707     }
708   if(PyTuple_Check(value))
709     {
710       int size=PyTuple_Size(value);
711       stdvecTyypp.resize(size);
712       for(int i=0;i<size;i++)
713         {
714           PyObject *o=PyTuple_GetItem(value,i);
715           if(PyFloat_Check(o))
716             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
717           else if(PyInt_Check(o))
718             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
719           else
720             {
721               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
722               throw INTERP_KERNEL::Exception(oss.str().c_str());
723             }
724         }
725       sw=2;
726       return;
727     }
728   if(PyList_Check(value))
729     {
730       int size=PyList_Size(value);
731       stdvecTyypp.resize(size);
732       for(int i=0;i<size;i++)
733         {
734           PyObject *o=PyList_GetItem(value,i);
735           if(PyFloat_Check(o))
736             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
737           else if(PyInt_Check(o))
738             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
739           else
740             {
741               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
742               throw INTERP_KERNEL::Exception(oss.str().c_str());
743             }
744         }
745       sw=2;
746       return;
747     }
748   void *argp;
749   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
750   if(!SWIG_IsOK(status))
751     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDouble");
752   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
753   sw=3;
754 }
755
756 /*!
757  * if python double -> cpp double sw=1
758  * if python int -> cpp double sw=1
759  * if python list[double] -> cpp vector<double> sw=2
760  * if python list[int] -> cpp vector<double> sw=2
761  * if python tuple[double] -> cpp vector<double> sw=2
762  * if python tuple[int] -> cpp vector<double> sw=2
763  * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
764  *
765  * switch between (int,vector<int>,DataArrayInt)
766  */
767 static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector<double>& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception)
768 {
769   sw=-1;
770   if(PyFloat_Check(value))
771     {
772       iTyypp=PyFloat_AS_DOUBLE(value);
773       sw=1;
774       return;
775     }
776   if(PyInt_Check(value))
777     {
778       iTyypp=(double)PyInt_AS_LONG(value);
779       sw=1;
780       return;
781     }
782   if(PyTuple_Check(value))
783     {
784       int size=PyTuple_Size(value);
785       stdvecTyypp.resize(size);
786       for(int i=0;i<size;i++)
787         {
788           PyObject *o=PyTuple_GetItem(value,i);
789           if(PyFloat_Check(o))
790             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
791           else if(PyInt_Check(o))
792             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
793           else
794             {
795               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
796               throw INTERP_KERNEL::Exception(oss.str().c_str());
797             }
798         }
799       sw=2;
800       return;
801     }
802   if(PyList_Check(value))
803     {
804       int size=PyList_Size(value);
805       stdvecTyypp.resize(size);
806       for(int i=0;i<size;i++)
807         {
808           PyObject *o=PyList_GetItem(value,i);
809           if(PyFloat_Check(o))
810             stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
811           else if(PyInt_Check(o))
812             stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
813           else
814             {
815               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
816               throw INTERP_KERNEL::Exception(oss.str().c_str());
817             }
818         }
819       sw=2;
820       return;
821     }
822   void *argp;
823   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
824   if(!SWIG_IsOK(status))
825     throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
826   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
827   sw=3;
828 }
829
830 /*!
831  * if python int -> cpp int sw=1
832  * if python list[int] -> cpp vector<int> sw=2
833  * if python tuple[int] -> cpp vector<int> sw=2
834  * if python slicp -> cpp pair sw=3
835  * if python DataArrayInt -> cpp DataArrayInt sw=4
836  *
837  * switch between (int,vector<int>,DataArrayInt)
838  */
839 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)
840 {
841   const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
842   sw=-1;
843   if(PyInt_Check(value))
844     {
845       iTyypp=(int)PyInt_AS_LONG(value);
846       sw=1;
847       return;
848     }
849   if(PyTuple_Check(value))
850     {
851       int size=PyTuple_Size(value);
852       stdvecTyypp.resize(size);
853       for(int i=0;i<size;i++)
854         {
855           PyObject *o=PyTuple_GetItem(value,i);
856           if(PyInt_Check(o))
857             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
858           else
859             {
860               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
861               throw INTERP_KERNEL::Exception(oss.str().c_str());
862             }
863         }
864       sw=2;
865       return;
866     }
867   if(PyList_Check(value))
868     {
869       int size=PyList_Size(value);
870       stdvecTyypp.resize(size);
871       for(int i=0;i<size;i++)
872         {
873           PyObject *o=PyList_GetItem(value,i);
874           if(PyInt_Check(o))
875             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
876           else
877             {
878               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
879               throw INTERP_KERNEL::Exception(oss.str().c_str());
880             }
881         }
882       sw=2;
883       return;
884     }
885   if(PySlice_Check(value))
886     {
887       Py_ssize_t strt,stp,step;
888       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
889       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
890         {
891           std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
892           throw INTERP_KERNEL::Exception(oss.str().c_str());
893         }
894       p.first=strt;
895       p.second.first=stp;
896       p.second.second=step;
897       sw=3;
898       return ;
899     }
900   void *argp;
901   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
902   if(SWIG_IsOK(status))
903     {
904       daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
905       if(!daIntTyypp)
906         {
907           std::ostringstream oss; oss << msg << " Instance in null !";
908           throw INTERP_KERNEL::Exception(oss.str().c_str());
909         }
910       sw=4;
911       return ;
912     }
913   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
914   if(SWIG_IsOK(status))
915     {
916       ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
917       if(!tmp)
918         {
919           std::ostringstream oss; oss << msg << " Instance in null !";
920           throw INTERP_KERNEL::Exception(oss.str().c_str());
921         }
922       stdvecTyypp.resize(tmp->getNumberOfCompo());
923       std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
924       sw=2;
925       return ;
926     }
927   throw INTERP_KERNEL::Exception(msg);
928 }
929
930 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)
931 {
932   sw=-1;
933   if(PyInt_Check(value))
934     {
935       iTyypp=(int)PyInt_AS_LONG(value);
936       sw=1;
937       return;
938     }
939   if(PyTuple_Check(value))
940     {
941       int size=PyTuple_Size(value);
942       stdvecTyypp.resize(size);
943       for(int i=0;i<size;i++)
944         {
945           PyObject *o=PyTuple_GetItem(value,i);
946           if(PyInt_Check(o))
947             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
948           else
949             {
950               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
951               throw INTERP_KERNEL::Exception(oss.str().c_str());
952             }
953         }
954       sw=2;
955       return;
956     }
957   if(PyList_Check(value))
958     {
959       int size=PyList_Size(value);
960       stdvecTyypp.resize(size);
961       for(int i=0;i<size;i++)
962         {
963           PyObject *o=PyList_GetItem(value,i);
964           if(PyInt_Check(o))
965             stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
966           else
967             {
968               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
969               throw INTERP_KERNEL::Exception(oss.str().c_str());
970             }
971         }
972       sw=2;
973       return;
974     }
975   if(PySlice_Check(value))
976     {
977       Py_ssize_t strt,stp,step;
978       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
979       if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
980         {
981           std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
982           throw INTERP_KERNEL::Exception(oss.str().c_str());
983         }
984       p.first=strt;
985       p.second.first=stp;
986       p.second.second=step;
987       sw=3;
988       return ;
989     }
990   void *argp;
991   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
992   if(!SWIG_IsOK(status))
993     throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple");
994   daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
995   sw=4;
996 }
997
998 /*!
999  * if value int -> cpp it sw=1
1000  * if value list[int] -> vt sw=2
1001  * if value tuple[int] -> vt sw=2
1002  * if value slice -> pt sw=3
1003  * if value DataArrayInt -> dt sw=4
1004  * if value tuple [int,int] -> cpp it,ip sw=5
1005  * if value tuple [list[int],int] -> cpp vt,ip sw=6
1006  * if value tuple [tuple[int],int] -> cpp vt,ip sw=6
1007  * if value tuple [slice,int] -> cpp pt,ip sw=7
1008  * if value tuple [DaI,int] -> cpp dt,ip sw=8
1009  * if value tuple [int,list[int]] -> cpp it,vc sw=9
1010  * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10
1011  * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10
1012  * if value tuple [slice,list[int]] -> cpp pt,vc sw=11
1013  * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12
1014  * if value tuple [int,tuple[int]] -> cpp it,vc sw=9
1015  * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10
1016  * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10
1017  * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11
1018  * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12
1019  * if value tuple [int,slice] -> cpp it,pc sw=13
1020  * if value tuple [list[int],slice] -> cpp vt,pc sw=14
1021  * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14
1022  * if value tuple [slice,slice] -> cpp pt,pc sw=15
1023  * if value tuple [DaI,slice] -> cpp dt,pc sw=16
1024  *
1025  * switch between (int,vector<int>,DataArrayInt)
1026  */
1027 static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector<int>& vt, std::vector<int>& vc,
1028                                      std::pair<int, std::pair<int,int> >& pt, std::pair<int, std::pair<int,int> >& pc,
1029                                      ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception)
1030 {
1031   if(!PyTuple_Check(value))
1032     {
1033       convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
1034       return ;
1035     }
1036   else
1037     {
1038       int sz=PyTuple_Size(value);
1039       if(sz!=2)
1040         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
1041       PyObject *ob0=PyTuple_GetItem(value,0);
1042       int sw1,sw2;
1043       convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
1044       PyObject *ob1=PyTuple_GetItem(value,1);
1045       convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
1046       sw=4*sw2+sw1;
1047     }
1048 }
1049
1050 /*!
1051  * if value int -> cpp val sw=1
1052  * if value double -> cpp val sw=1
1053  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1054  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1055  * if value list[int,double] -> cpp std::vector<double> sw=4
1056  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1057  */
1058 static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f)
1059 {
1060   sw=-1;
1061   if(PyFloat_Check(value))
1062     {
1063       val=PyFloat_AS_DOUBLE(value);
1064       sw=1;
1065       return;
1066     }
1067   if(PyInt_Check(value))
1068     {
1069       val=(double)PyInt_AS_LONG(value);
1070       sw=1;
1071       return;
1072     }
1073   if(PyTuple_Check(value))
1074     {
1075       int size=PyTuple_Size(value);
1076       f.resize(size);
1077       for(int i=0;i<size;i++)
1078         {
1079           PyObject *o=PyTuple_GetItem(value,i);
1080           if(PyFloat_Check(o))
1081             f[i]=PyFloat_AS_DOUBLE(o);
1082           else if(PyInt_Check(o))
1083             f[i]=(double)PyInt_AS_LONG(o);
1084           else
1085             {
1086               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1087               throw INTERP_KERNEL::Exception(oss.str().c_str());
1088             }
1089         }
1090       sw=4;
1091       return;
1092     }
1093   if(PyList_Check(value))
1094     {
1095       int size=PyList_Size(value);
1096       f.resize(size);
1097       for(int i=0;i<size;i++)
1098         {
1099           PyObject *o=PyList_GetItem(value,i);
1100           if(PyFloat_Check(o))
1101             f[i]=PyFloat_AS_DOUBLE(o);
1102           else if(PyInt_Check(o))
1103             f[i]=(double)PyInt_AS_LONG(o);
1104           else
1105             {
1106               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1107               throw INTERP_KERNEL::Exception(oss.str().c_str());
1108             }
1109         }
1110       sw=4;
1111       return;
1112     }
1113   void *argp;
1114   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1115   if(SWIG_IsOK(status))
1116     {  
1117       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1118       sw=2;
1119       return ;
1120     }
1121   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1122   if(SWIG_IsOK(status))
1123     {  
1124       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1125       sw=3;
1126       return ;
1127     }
1128   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1129 }
1130
1131 /*!
1132  * if value int -> cpp val sw=1
1133  * if value double -> cpp val sw=1
1134  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1135  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1136  * if value list[int,double] -> cpp std::vector<double> sw=4
1137  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1138  */
1139 static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1140                                                    const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception)
1141 {
1142   sw=-1;
1143   if(PyFloat_Check(value))
1144     {
1145       val=PyFloat_AS_DOUBLE(value);
1146       sw=1;
1147       if(nbTuplesExpected*nbCompExpected!=1)
1148         {
1149           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1150           throw INTERP_KERNEL::Exception(oss.str().c_str());
1151         }
1152       return &val;
1153     }
1154   if(PyInt_Check(value))
1155     {
1156       val=(double)PyInt_AS_LONG(value);
1157       sw=1;
1158       if(nbTuplesExpected*nbCompExpected!=1)
1159         {
1160           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1161           throw INTERP_KERNEL::Exception(oss.str().c_str());
1162         }
1163       return &val;
1164     }
1165   if(PyTuple_Check(value))
1166     {
1167       int size=PyTuple_Size(value);
1168       f.resize(size);
1169       for(int i=0;i<size;i++)
1170         {
1171           PyObject *o=PyTuple_GetItem(value,i);
1172           if(PyFloat_Check(o))
1173             f[i]=PyFloat_AS_DOUBLE(o);
1174           else if(PyInt_Check(o))
1175             f[i]=(double)PyInt_AS_LONG(o);
1176           else
1177             {
1178               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1179               throw INTERP_KERNEL::Exception(oss.str().c_str());
1180             }
1181         }
1182       sw=4;
1183       if(nbTuplesExpected*nbCompExpected!=(int)f.size())
1184         {
1185           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1186           throw INTERP_KERNEL::Exception(oss.str().c_str());
1187         }
1188       return &f[0];
1189     }
1190   if(PyList_Check(value))
1191     {
1192       int size=PyList_Size(value);
1193       f.resize(size);
1194       for(int i=0;i<size;i++)
1195         {
1196           PyObject *o=PyList_GetItem(value,i);
1197           if(PyFloat_Check(o))
1198             f[i]=PyFloat_AS_DOUBLE(o);
1199           else if(PyInt_Check(o))
1200             f[i]=(double)PyInt_AS_LONG(o);
1201           else
1202             {
1203               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1204               throw INTERP_KERNEL::Exception(oss.str().c_str());
1205             }
1206         }
1207       sw=4;
1208       if(nbTuplesExpected*nbCompExpected!=(int)f.size())
1209         {
1210           std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1211           throw INTERP_KERNEL::Exception(oss.str().c_str());
1212         }
1213       return &f[0];
1214     }
1215   void *argp;
1216   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1217   if(SWIG_IsOK(status))
1218     {  
1219       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1220       sw=2;
1221       if(d)
1222         {
1223           if(d->getNumberOfTuples()==nbTuplesExpected)
1224             {
1225               if(d->getNumberOfComponents()==nbCompExpected)
1226                 {
1227                   return d->getConstPointer();
1228                 }
1229               else
1230                 {
1231                   std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1232                   throw INTERP_KERNEL::Exception(oss.str().c_str());
1233                 }
1234             }
1235           else
1236             {
1237               std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !";
1238               throw INTERP_KERNEL::Exception(oss.str().c_str());
1239             }
1240         }
1241       else
1242         {
1243           if(throwIfNullPt)
1244             {
1245               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1246               throw INTERP_KERNEL::Exception(oss.str().c_str());
1247             }
1248           else
1249             return 0;
1250         }
1251     }
1252   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1253   if(SWIG_IsOK(status))
1254     {  
1255       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1256       sw=3;
1257       if(e->getNumberOfCompo()==nbCompExpected)
1258         {
1259           if(nbTuplesExpected==1)
1260             return e->getConstPointer();
1261           else
1262             {
1263               std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !";
1264               throw INTERP_KERNEL::Exception(oss.str().c_str());
1265             }
1266         }
1267       else
1268         {
1269           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1270           throw INTERP_KERNEL::Exception(oss.str().c_str());
1271         }
1272     }
1273   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1274 }
1275
1276 /*!
1277  * if value int -> cpp val sw=1
1278  * if value double -> cpp val sw=1
1279  * if value DataArrayDouble -> cpp DataArrayDouble sw=2
1280  * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3
1281  * if value list[int,double] -> cpp std::vector<double> sw=4
1282  * if value tuple[int,double] -> cpp std::vector<double> sw=4
1283  */
1284 static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector<double>& f,
1285                                                     const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception)
1286 {
1287   sw=-1;
1288   if(PyFloat_Check(value))
1289     {
1290       val=PyFloat_AS_DOUBLE(value);
1291       sw=1;
1292       if(nbCompExpected!=1)
1293         {
1294           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; 
1295           throw INTERP_KERNEL::Exception(oss.str().c_str());
1296         }
1297       nbTuples=1;
1298       return &val;
1299     }
1300   if(PyInt_Check(value))
1301     {
1302       val=(double)PyInt_AS_LONG(value);
1303       sw=1;
1304       if(nbCompExpected!=1)
1305         {
1306           std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; 
1307           throw INTERP_KERNEL::Exception(oss.str().c_str());
1308         }
1309       nbTuples=1;
1310       return &val;
1311     }
1312   if(PyTuple_Check(value))
1313     {
1314       int size=PyTuple_Size(value);
1315       f.resize(size);
1316       for(int i=0;i<size;i++)
1317         {
1318           PyObject *o=PyTuple_GetItem(value,i);
1319           if(PyFloat_Check(o))
1320             f[i]=PyFloat_AS_DOUBLE(o);
1321           else if(PyInt_Check(o))
1322             f[i]=(double)PyInt_AS_LONG(o);
1323           else
1324             {
1325               std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
1326               throw INTERP_KERNEL::Exception(oss.str().c_str());
1327             }
1328         }
1329       sw=4;
1330       if(size%nbCompExpected!=0)
1331         {
1332           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1333           throw INTERP_KERNEL::Exception(oss.str().c_str());
1334         }
1335       nbTuples=size/nbCompExpected;
1336       return &f[0];
1337     }
1338   if(PyList_Check(value))
1339     {
1340       int size=PyList_Size(value);
1341       f.resize(size);
1342       for(int i=0;i<size;i++)
1343         {
1344           PyObject *o=PyList_GetItem(value,i);
1345           if(PyFloat_Check(o))
1346             f[i]=PyFloat_AS_DOUBLE(o);
1347           else if(PyInt_Check(o))
1348             f[i]=(double)PyInt_AS_LONG(o);
1349           else
1350             {
1351               std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
1352               throw INTERP_KERNEL::Exception(oss.str().c_str());
1353             }
1354         }
1355       sw=4;
1356       if(size%nbCompExpected!=0)
1357         {
1358           std::ostringstream oss; oss << msg << "dimension expected to be a multiple of " << nbCompExpected << " , and your data in input has dimension " << f.size() << " !"; 
1359           throw INTERP_KERNEL::Exception(oss.str().c_str());
1360         }
1361       nbTuples=size/nbCompExpected;
1362       return &f[0];
1363     }
1364   void *argp;
1365   int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
1366   if(SWIG_IsOK(status))
1367     {  
1368       d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp);
1369       sw=2;
1370       if(d)
1371         {
1372           if(d->getNumberOfComponents()==nbCompExpected)
1373             {
1374               nbTuples=d->getNumberOfTuples();
1375               return d->getConstPointer();
1376             }
1377           else
1378             {
1379               std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !";
1380               throw INTERP_KERNEL::Exception(oss.str().c_str());
1381             }
1382         }
1383       else
1384         {
1385           if(throwIfNullPt)
1386             {
1387               std::ostringstream oss; oss << msg << " null pointer not accepted!";
1388               throw INTERP_KERNEL::Exception(oss.str().c_str());
1389             }
1390           else
1391             return 0;
1392         }
1393     }
1394   status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
1395   if(SWIG_IsOK(status))
1396     {  
1397       e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
1398       sw=3;
1399       if(e->getNumberOfCompo()==nbCompExpected)
1400         {
1401           nbTuples=1;
1402           return e->getConstPointer();
1403         }
1404       else
1405         {
1406           std::ostringstream oss; oss << msg << "nb of components expected to be " <<  nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !";
1407           throw INTERP_KERNEL::Exception(oss.str().c_str());
1408         }
1409     }
1410   throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
1411 }