- sw=-1;
- if(PyFloat_Check(value))
- {
- iTyypp=PyFloat_AS_DOUBLE(value);
- sw=1;
- return;
- }
- if(PyInt_Check(value))
- {
- iTyypp=(double)PyInt_AS_LONG(value);
- sw=1;
- return;
- }
- if(PyTuple_Check(value))
- {
- int size=PyTuple_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyTuple_GetItem(value,i);
- if(PyFloat_Check(o))
- stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not double ! only tuples of doubles accepted or integer !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=2;
- return;
- }
- if(PyList_Check(value))
- {
- int size=PyList_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(value,i);
- if(PyFloat_Check(o))
- stdvecTyypp[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- stdvecTyypp[i]=(double)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not double ! only lists of doubles accepted or integer !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=2;
- return;
- }
- void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0);
- if(!SWIG_IsOK(status))
- throw INTERP_KERNEL::Exception("5 types accepted : double float, integer, tuple of double float or int, list of double float or int, DataArrayDoubleTuple");
- daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp);
- sw=3;
-}
-
-/*!
- * if python int -> cpp int sw=1
- * if python list[int] -> cpp vector<int> sw=2
- * if python tuple[int] -> cpp vector<int> sw=2
- * if python slicp -> cpp pair sw=3
- * if python DataArrayInt -> cpp DataArrayInt sw=4
- *
- * switch between (int,vector<int>,DataArrayInt)
- */
-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)
-{
- const char *msg="5 types accepted : integer, tuple of integer, list of integer, slice, DataArrayInt, DataArrayIntTuple";
- sw=-1;
- if(PyInt_Check(value))
- {
- iTyypp=(int)PyInt_AS_LONG(value);
- sw=1;
- return;
- }
- if(PyTuple_Check(value))
- {
- int size=PyTuple_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyTuple_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "Tuple as been detected but element #" << i << " is not integer ! only tuples of integers accepted !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=2;
- return;
- }
- if(PyList_Check(value))
- {
- int size=PyList_Size(value);
- stdvecTyypp.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(value,i);
- if(PyInt_Check(o))
- stdvecTyypp[i]=(int)PyInt_AS_LONG(o);
- else
- {
- std::ostringstream oss; oss << "List as been detected but element #" << i << " is not integer ! only lists of integers accepted !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- }
- sw=2;
- return;
- }
- if(PySlice_Check(value))
- {
- Py_ssize_t strt=2,stp=2,step=2;
- PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
- if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
- if(nbelem!=0 || strt!=0 || stp!=0)
- {
- std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- p.first=strt;
- p.second.first=stp;
- p.second.second=step;
- sw=3;
- return ;
- }
- void *argp;
- int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
- if(SWIG_IsOK(status))
- {
- daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
- if(!daIntTyypp)
- {
- std::ostringstream oss; oss << msg << " Instance in null !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- sw=4;
- return ;
- }
- status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);;
- if(SWIG_IsOK(status))
- {
- ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
- if(!tmp)
- {
- std::ostringstream oss; oss << msg << " Instance in null !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- stdvecTyypp.resize(tmp->getNumberOfCompo());
- std::copy(tmp->getConstPointer(),tmp->getConstPointer()+tmp->getNumberOfCompo(),stdvecTyypp.begin());
- sw=2;
- return ;
- }
- throw INTERP_KERNEL::Exception(msg);