- if(recurseLev<0)
- throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : invalid list of integers level of recursion !");
- arr.clear();
- if(PyList_Check(pyLi))
- {
- int size=PyList_Size(pyLi);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyList_GetItem(pyLi,i);
- if(PyInt_Check(o))
- {
- int val=(int)PyInt_AS_LONG(o);
- arr.push_back(val);
- }
- else
- {
- std::vector<int> arr2;
- convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
- if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
- {
- std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- arr.insert(arr.end(),arr2.begin(),arr2.end());
- }
- }
- }
- else if(PyTuple_Check(pyLi))
- {
- int size=PyTuple_Size(pyLi);
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyTuple_GetItem(pyLi,i);
- if(PyInt_Check(o))
- {
- int val=(int)PyInt_AS_LONG(o);
- arr.push_back(val);
- }
- else
- {
- std::vector<int> arr2;
- convertPyToNewIntArr4(o,recurseLev-1,nbOfSubPart,arr2);
- if(nbOfSubPart>=1 && nbOfSubPart!=(int)arr2.size())
- {
- std::ostringstream oss; oss << "convertPyToNewIntArr4 : input list at lev " << recurseLev << " invalid nb of subpart elts expected " << nbOfSubPart << " having " << arr2.size() << " !";
- throw INTERP_KERNEL::Exception(oss.str().c_str());
- }
- arr.insert(arr.end(),arr2.begin(),arr2.end());
- }
- }
- }
- else
- throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !");
-}
-
-static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception)
-{
- if(nbOfTuples==-1)
- {
- if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; }
- else { if(nbOfComp==size2) { nbOfTuples=size1; } else
- {
- 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());
- } }
- }
- else
- {
- if(nbOfComp!=-1)
- {
- if((nbOfTuples!=size1 || nbOfComp!=size2))
- {
- 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
- {
- 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);
- }
- }
- else if(PyTuple_Check(pyLi))
- {
- int size=PyTuple_Size(pyLi);
- int tmp=0;
- for(int i=0;i<size;i++)
- {
- PyObject *o=PyTuple_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);
- }
- }
- 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("fillArrayWithPyListInt2 : Unrecognized type ! Should be a tuple or a list !");