ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner);
if(dynamic_cast<ParaMEDMEM::MEDCouplingCMesh *>(mesh))
ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner);
+ if(dynamic_cast<ParaMEDMEM::MEDCouplingCurveLinearMesh *>(mesh))
+ ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner);
if(!ret)
throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !");
return ret;
throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
}
-
-static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
+static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
{
- if(PyList_Check(pyLi))
+ if(nbOfTuples==-1)
{
- int size=PyList_Size(pyLi);
- if(chckSize)
- if(size!=sizeOfArray)
+ if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
+ else { if(nbOfComp==size2) { nbOfTuples=size1; } else
{
- std::ostringstream oss; oss << "fillArrayWithPyListInt : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
+ std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
+ oss << " whereas nb of components expected is " << nbOfComp << " !";
throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- for(int i=0;i<size;i++)
+ } }
+ }
+ else
+ {
+ if(nbOfComp!=-1)
{
- PyObject *o=PyList_GetItem(pyLi,i);
- if(PyInt_Check(o))
+ if((nbOfTuples!=size1 || nbOfComp!=size2))
{
- int val=(int)PyInt_AS_LONG(o);
- if(i<sizeOfArray)
- arrToFill[i]=val;
+ if(size2!=1 || size1!=nbOfComp*nbOfTuples)
+ {
+ std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
+ oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
}
+ }
+ else
+ {
+ if(nbOfTuples==size1)
+ nbOfComp=size2;
else
- throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : List must contain integers only !");
+ {
+ std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components";
+ oss << " whereas nb of tuples expected is " << nbOfTuples << " !";
+ throw INTERP_KERNEL::Exception(oss.str().c_str());
+ }
+ }
+ }
+}
+
+static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector<int>& ret)
+{
+ static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !";
+ if(PyInt_Check(pyLi))
+ {
+ long val=PyInt_AS_LONG(pyLi);
+ if(nbOfElt==-1)
+ nbOfElt=1;
+ else
+ if(nbOfElt!=1)
+ throw INTERP_KERNEL::Exception(MSG);
+ ret.push_back(val);
+ }
+ else if(PyList_Check(pyLi))
+ {
+ int size=PyList_Size(pyLi);
+ int tmp=0;
+ for(int i=0;i<size;i++)
+ {
+ PyObject *o=PyList_GetItem(pyLi,i);
+ int tmp1=-1;
+ fillArrayWithPyListInt3(o,tmp1,ret);
+ tmp+=tmp1;
+ }
+ if(nbOfElt==-1)
+ nbOfElt=tmp;
+ else
+ {
+ if(nbOfElt!=tmp)
+ throw INTERP_KERNEL::Exception(MSG);
}
- for(int i=size;i<sizeOfArray;i++)
- arrToFill[i]=dftVal;
- return;
-
}
else if(PyTuple_Check(pyLi))
{
int size=PyTuple_Size(pyLi);
- if(chckSize)
- if(size!=sizeOfArray)
- {
- std::ostringstream oss; oss << "fillArrayWithPyListInt : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ int tmp=0;
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(pyLi,i);
- if(PyInt_Check(o))
- {
- int val=(int)PyInt_AS_LONG(o);
- if(i<sizeOfArray)
- arrToFill[i]=val;
- }
- else
- throw INTERP_KERNEL::Exception("tuple must contain integers only");
+ int tmp1=-1;
+ fillArrayWithPyListInt3(o,tmp1,ret);
+ tmp+=tmp1;
}
- for(int i=size;i<sizeOfArray;i++)
- arrToFill[i]=dftVal;
- return;
+ if(nbOfElt==-1)
+ nbOfElt=tmp;
+ else
+ {
+ if(nbOfElt!=tmp)
+ throw INTERP_KERNEL::Exception(MSG);
+ }
+ }
+ else
+ throw INTERP_KERNEL::Exception("fillArrayWithPyListInt3 : Unrecognized type ! Should be a composition of tuple,list,int !");
+}
+
+static std::vector<int> fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<int> ret;
+ int size1=-1,size2=-1;
+ if(PyList_Check(pyLi))
+ {
+ size1=PyList_Size(pyLi);
+ for(int i=0;i<size1;i++)
+ {
+ PyObject *o=PyList_GetItem(pyLi,i);
+ fillArrayWithPyListInt3(o,size2,ret);
+ }
+ if(size1==0)
+ size2=1;
+ }
+ else if(PyTuple_Check(pyLi))
+ {
+ size1=PyTuple_Size(pyLi);
+ for(int i=0;i<size1;i++)
+ {
+ PyObject *o=PyTuple_GetItem(pyLi,i);
+ fillArrayWithPyListInt3(o,size2,ret);
+ }
+ if(size1==0)
+ size2=1;
}
else
- throw INTERP_KERNEL::Exception("fillArrayWithPyListInt : not a list");
+ throw INTERP_KERNEL::Exception("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");
+ //
+ checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
+ return ret;
}
static PyObject *convertDblArrToPyList(const double *ptr, int size) throw(INTERP_KERNEL::Exception)
throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list");
}
-static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal, bool chckSize) throw(INTERP_KERNEL::Exception)
+static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector<double>& ret)
{
- if(PyList_Check(pyLi))
+ static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !";
+ if(PyFloat_Check(pyLi))
+ {
+ if(nbOfElt==-1)
+ nbOfElt=1;
+ else
+ if(nbOfElt!=1)
+ throw INTERP_KERNEL::Exception(MSG);
+ double val=PyFloat_AS_DOUBLE(pyLi);
+ ret.push_back(val);
+ }
+ else if(PyInt_Check(pyLi))
+ {
+ long val0=PyInt_AS_LONG(pyLi);
+ double val=val0;
+ if(nbOfElt==-1)
+ nbOfElt=1;
+ else
+ if(nbOfElt!=1)
+ throw INTERP_KERNEL::Exception(MSG);
+ ret.push_back(val);
+ }
+ else if(PyList_Check(pyLi))
{
int size=PyList_Size(pyLi);
- if(chckSize)
- if(size!=sizeOfArray)
- {
- std::ostringstream oss; oss << "fillArrayWithPyListDbl : List expected to be of size " << sizeOfArray << " but the size is " << size << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ int tmp=0;
for(int i=0;i<size;i++)
{
PyObject *o=PyList_GetItem(pyLi,i);
- if(PyFloat_Check(o))
- {
- double val=PyFloat_AS_DOUBLE(o);
- if(i<sizeOfArray)
- arrToFill[i]=val;
- }
- else if(PyInt_Check(o))
- {
- long val0=PyInt_AS_LONG(o);
- double val=val0;
- if(i<sizeOfArray)
- arrToFill[i]=val;
- }
- else
- throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : list must contain floats/integers only");
+ int tmp1=-1;
+ fillArrayWithPyListDbl3(o,tmp1,ret);
+ tmp+=tmp1;
+ }
+ if(nbOfElt==-1)
+ nbOfElt=tmp;
+ else
+ {
+ if(nbOfElt!=tmp)
+ throw INTERP_KERNEL::Exception(MSG);
}
- for(int i=size;i<sizeOfArray;i++)
- arrToFill[i]=dftVal;
- return;
}
else if(PyTuple_Check(pyLi))
{
int size=PyTuple_Size(pyLi);
- if(chckSize)
- if(size!=sizeOfArray)
- {
- std::ostringstream oss; oss << "fillArrayWithPyListDbl : Tuple expected to be of size " << sizeOfArray << " but the size is " << size << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ int tmp=0;
for(int i=0;i<size;i++)
{
PyObject *o=PyTuple_GetItem(pyLi,i);
- if(PyFloat_Check(o))
- {
- double val=PyFloat_AS_DOUBLE(o);
- arrToFill[i]=val;
- }
- else if(PyInt_Check(o))
- {
- long val0=PyInt_AS_LONG(o);
- double val=val0;
- arrToFill[i]=val;
- }
- else
- throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : tuple must contain floats/integers only");
+ int tmp1=-1;
+ fillArrayWithPyListDbl3(o,tmp1,ret);
+ tmp+=tmp1;
+ }
+ if(nbOfElt==-1)
+ nbOfElt=tmp;
+ else
+ {
+ if(nbOfElt!=tmp)
+ throw INTERP_KERNEL::Exception(MSG);
}
- for(int i=size;i<sizeOfArray;i++)
- arrToFill[i]=dftVal;
- return ;
}
else
- throw INTERP_KERNEL::Exception("convertPyToNewIntArr : not a list");
+ throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl3 : Unrecognized type ! Should be a composition of tuple,list,int and float !");
+}
+
+static std::vector<double> fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<double> ret;
+ int size1=-1,size2=-1;
+ if(PyList_Check(pyLi))
+ {
+ size1=PyList_Size(pyLi);
+ for(int i=0;i<size1;i++)
+ {
+ PyObject *o=PyList_GetItem(pyLi,i);
+ fillArrayWithPyListDbl3(o,size2,ret);
+ }
+ if(size1==0)
+ size2=1;
+ }
+ else if(PyTuple_Check(pyLi))
+ {
+ size1=PyTuple_Size(pyLi);
+ for(int i=0;i<size1;i++)
+ {
+ PyObject *o=PyTuple_GetItem(pyLi,i);
+ fillArrayWithPyListDbl3(o,size2,ret);
+ }
+ if(size1==0)
+ size2=1;
+ }
+ else
+ throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl2 : Unrecognized type ! Should be a tuple or a list !");
+ //
+ checkFillArrayWithPyList(size1,size2,nbOfTuples,nbOfComp);
+ return ret;
}
//convertFromPyObjVectorOfObj<const ParaMEDMEM::MEDCouplingUMesh *>(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh")
for(int i=0;i<size;i++)
{
PyObject *obj=PyTuple_GetItem(pyLi,i);
- void *argp;
int status=SWIG_ConvertPtr(obj,&argp,ty,0|0);
if(!SWIG_IsOK(status))
{
}
if(PySlice_Check(value))
{
- Py_ssize_t strt,stp,step;
+ Py_ssize_t strt=2,stp=2,step=2;
PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
- {
- std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ 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;
}
if(PySlice_Check(value))
{
- Py_ssize_t strt,stp,step;
+ Py_ssize_t strt=2,stp=2,step=2;
PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
- {
- std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elemnts is : " << nbelem;
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
+ 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;
}
return &val;
}
- if(PyTuple_Check(value))
+ if(PyTuple_Check(value) || PyList_Check(value))
{
- int size=PyTuple_Size(value);
- f.resize(size);
- for(int i=0;i<size;i++)
+ try
{
- PyObject *o=PyTuple_GetItem(value,i);
- if(PyFloat_Check(o))
- f[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- f[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());
- }
+ int tmp1=nbTuplesExpected,tmp2=nbCompExpected;
+ std::vector<double> ret=fillArrayWithPyListDbl2(value,tmp1,tmp2);
+ sw=4;
+ f=ret;
+ return &f[0];
}
- sw=4;
- if(nbTuplesExpected*nbCompExpected!=(int)f.size())
- {
- std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- return &f[0];
- }
- if(PyList_Check(value))
- {
- int size=PyList_Size(value);
- f.resize(size);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(value,i);
- if(PyFloat_Check(o))
- f[i]=PyFloat_AS_DOUBLE(o);
- else if(PyInt_Check(o))
- f[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=4;
- if(nbTuplesExpected*nbCompExpected!=(int)f.size())
- {
- std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension " << f.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- return &f[0];
+ catch(INTERP_KERNEL::Exception& e) { throw e; }
}
void *argp;
int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
}
throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple");
}
+
+/*!
+ * 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 DataArrayInt -> cpp DataArrayInt sw=3
+ * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4
+ *
+ * switch between (int,vector<int>,DataArrayInt)
+ */
+static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector<int>& stdvecTyypp) throw(INTERP_KERNEL::Exception)
+{
+ sw=-1;
+ if(PyInt_Check(value))
+ {
+ iTyypp=(int)PyInt_AS_LONG(value);
+ sw=1; sz=1;
+ return &iTyypp;
+ }
+ 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; sz=size;
+ return &stdvecTyypp[0];
+ }
+ 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; sz=size;
+ return &stdvecTyypp[0];
+ }
+ void *argp;
+ int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0);
+ if(SWIG_IsOK(status))
+ {
+ ParaMEDMEM::DataArrayInt *daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayInt * >(argp);
+ if(daIntTyypp)
+ {
+ sw=3; sz=daIntTyypp->getNbOfElems();
+ return daIntTyypp->begin();
+ }
+ else
+ {
+ sz=0;
+ return 0;
+ }
+ }
+ status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);
+ if(SWIG_IsOK(status))
+ {
+ ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp);
+ sw=4; sz=daIntTuple->getNumberOfCompo();
+ return daIntTuple->getConstPointer();
+ }
+ throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple");
+}