X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingTypemaps.i;h=edae657420af39cda5f371fb23b187166d6d4cb6;hb=ec0d2fa019c87f670675131f7ae89228664dc8d4;hp=fbbf34ea6f2f23279eef5426f350770ed77233a6;hpb=f67dc0817fad8a24d547e09fdab9c36e280cd378;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index fbbf34ea6..edae65742 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D +// Copyright (C) 2007-2014 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,24 +16,32 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// Author : Anthony Geay (CEA/DEN) -#include "InterpKernelAutoPtr.hxx" - -#ifdef WITH_NUMPY2 -#include -#endif +#include "MEDCouplingDataArrayTypemaps.i" static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; + if(!mesh) + { + Py_XINCREF(Py_None); + return Py_None; + } if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1SGTUMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCoupling1DGTUMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingExtrudedMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh,owner); if(dynamic_cast(mesh)) ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingCurveLinearMesh,owner); + if(dynamic_cast(mesh)) + ret=SWIG_NewPointerObj((void*)mesh,SWIGTYPE_p_ParaMEDMEM__MEDCouplingIMesh,owner); if(!ret) throw INTERP_KERNEL::Exception("Not recognized type of mesh on downcast !"); return ret; @@ -42,6 +50,11 @@ static PyObject *convertMesh(ParaMEDMEM::MEDCouplingMesh *mesh, int owner) throw static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscretization *fd, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; + if(!fd) + { + Py_XINCREF(Py_None); + return Py_None; + } if(dynamic_cast(fd)) ret=SWIG_NewPointerObj(reinterpret_cast(fd),SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldDiscretizationP0,owner); if(dynamic_cast(fd)) @@ -57,21 +70,14 @@ static PyObject *convertFieldDiscretization(ParaMEDMEM::MEDCouplingFieldDiscreti return ret; } -static PyObject *convertDataArrayChar(ParaMEDMEM::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception) -{ - PyObject *ret=0; - if(dynamic_cast(dac)) - ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayByte,owner); - if(dynamic_cast(dac)) - ret=SWIG_NewPointerObj((void*)dac,SWIGTYPE_p_ParaMEDMEM__DataArrayAsciiChar,owner); - if(!ret) - throw INTERP_KERNEL::Exception("Not recognized type of DataArrayChar on downcast !"); - return ret; -} - static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int owner) throw(INTERP_KERNEL::Exception) { PyObject *ret=0; + if(!mfs) + { + Py_XINCREF(Py_None); + return Py_None; + } if(dynamic_cast(mfs)) ret=SWIG_NewPointerObj((void*)mfs,SWIGTYPE_p_ParaMEDMEM__MEDCouplingFieldOverTime,owner); else @@ -79,1765 +85,54 @@ static PyObject* convertMultiFields(ParaMEDMEM::MEDCouplingMultiFields *mfs, int return ret; } -static PyObject *convertIntArrToPyList(const int *ptr, int size) throw(INTERP_KERNEL::Exception) -{ -#ifndef WITH_NUMPY2 - PyObject *ret=PyList_New(size); - for(int i=0;i(tmp)); -#endif -} - -static PyObject *convertIntArrToPyList2(const std::vector& v) throw(INTERP_KERNEL::Exception) -{ -#ifndef WITH_NUMPY2 - int size=v.size(); - PyObject *ret=PyList_New(size); - for(int i=0;i& v) throw(INTERP_KERNEL::Exception) -{ - int size=v.size(); - PyObject *ret=PyList_New(size); - std::set::const_iterator it=v.begin(); - for(int i=0;i >& arr) throw(INTERP_KERNEL::Exception) -{ - const char msg[]="list must contain tuples of 2 integers only or tuple must contain tuples of 2 integers only !"; - if(PyList_Check(pyLi)) - { - int size=PyList_Size(pyLi); - arr.resize(size); - for(int i=0;i& arr) throw(INTERP_KERNEL::Exception) -{ - if(PyList_Check(pyLi)) - { - int size=PyList_Size(pyLi); - arr.resize(size); - for(int i=0;i& arr) throw(INTERP_KERNEL::Exception) -{ - 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 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 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& 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 fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception) -{ - std::vector ret; - int size1=-1,size2=-1; - if(PyList_Check(pyLi)) - { - size1=PyList_Size(pyLi); - for(int i=0;i& vec) throw(INTERP_KERNEL::Exception) -{ - if(PyList_Check(pyLi)) - { - Py_ssize_t sz=PyList_Size(pyLi); - vec.resize(sz); - for(int i=0;i& v) throw(INTERP_KERNEL::Exception) -{ - int size=v.size(); - PyObject *ret=PyList_New(size); - for(int i=0;i tmp=new char[nbOfComp+1]; tmp[nbOfComp]='\0'; - for(int i=0;i& ret) -{ - 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); - int tmp=0; - for(int i=0;i fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception) -{ - std::vector ret; - int size1=-1,size2=-1; - if(PyList_Check(pyLi)) - { - size1=PyList_Size(pyLi); - for(int i=0;i(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh") -template -static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, const char *typeStr, typename std::vector& ret) -{ - void *argp=0; - if(PyList_Check(pyLi)) - { - int size=PyList_Size(pyLi); - ret.resize(size); - for(int i=0;i(argp); - ret[i]=arg; - } - } - else if(PyTuple_Check(pyLi)) - { - int size=PyTuple_Size(pyLi); - ret.resize(size); - for(int i=0;i(argp); - ret[i]=arg; - } - } - else if(SWIG_IsOK(SWIG_ConvertPtr(pyLi,&argp,ty,0|0))) - { - ret.resize(1); - T arg=reinterpret_cast< T >(argp); - ret[0]=arg; - } - else - throw INTERP_KERNEL::Exception("convertFromPyObjVectorOfObj : not a list nor a tuple"); -} - -/*! - * if python int -> cpp int sw=1 - * if python list[int] -> cpp vector sw=2 - * if python tuple[int] -> cpp vector sw=2 - * if python DataArrayInt -> cpp DataArrayInt sw=3 - * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 - * - * switch between (int,vector,DataArrayInt) - */ -static void convertObjToPossibleCpp1(PyObject *value, int& sw, int& iTyypp, std::vector& stdvecTyypp, ParaMEDMEM::DataArrayInt *& daIntTyypp, ParaMEDMEM::DataArrayIntTuple *&daIntTuple) throw(INTERP_KERNEL::Exception) -{ - 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(argp); - sw=3; - return; - } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0); - if(SWIG_IsOK(status)) - { - daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); - sw=4; - return ; - } - throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); -} - -/*! - * if python double -> cpp double sw=1 - * if python int -> cpp double sw=1 - * if python list[double] -> cpp vector sw=2 - * if python list[int] -> cpp vector sw=2 - * if python tuple[double] -> cpp vector sw=2 - * if python tuple[int] -> cpp vector sw=2 - * if python DataArrayDouble -> cpp DataArrayDouble sw=3 - * - * switch between (int,vector,DataArrayInt) - */ -static void convertObjToPossibleCpp4(PyObject *value, int& sw, double& iTyypp, std::vector& stdvecTyypp, ParaMEDMEM::DataArrayDouble *& daIntTyypp) throw(INTERP_KERNEL::Exception) -{ - 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(argp); - sw=3; -} - -/*! - * if python double -> cpp double sw=1 - * if python int -> cpp double sw=1 - * if python list[double] -> cpp vector sw=2 - * if python list[int] -> cpp vector sw=2 - * if python tuple[double] -> cpp vector sw=2 - * if python tuple[int] -> cpp vector sw=2 - * if python DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 - * - * switch between (int,vector,DataArrayInt) - */ -static void convertObjToPossibleCpp44(PyObject *value, int& sw, double& iTyypp, std::vector& stdvecTyypp, ParaMEDMEM::DataArrayDoubleTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception) -{ - 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(argp); - sw=3; -} - -/*! - * if python int -> cpp int sw=1 - * if python list[int] -> cpp vector sw=2 - * if python tuple[int] -> cpp vector sw=2 - * if python slicp -> cpp pair sw=3 (begin,end,step) - * if python DataArrayInt -> cpp DataArrayInt sw=4 . The returned pointer cannot be the null pointer ! If null an exception is thrown. - * - * switch between (int,vector,DataArrayInt) - */ -static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector& stdvecTyypp, std::pair >& 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(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); -} - -/*! - * if python int -> cpp int sw=1 - * if python tuple[int] -> cpp vector sw=2 - * if python list[int] -> cpp vector sw=2 - * if python slice -> cpp pair sw=3 - * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 . WARNING The returned pointer can be the null pointer ! - */ -static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector& stdvecTyypp, std::pair >& p, ParaMEDMEM::DataArrayIntTuple *& daIntTyypp) throw(INTERP_KERNEL::Exception) -{ - 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(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__DataArrayIntTuple,0|0); - if(!SWIG_IsOK(status)) - throw INTERP_KERNEL::Exception("4 types accepted : integer, tuple of integer, list of integer, slice, DataArrayIntTuple"); - daIntTyypp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); - sw=4; -} - -/*! - * if python string with size one -> cpp char sw=1 - * if python string with size different from one -> cpp string sw=2 - * if python tuple[string] or list[string] -> vector sw=3 - * if python not null pointer of DataArrayChar -> cpp DataArrayChar sw=4 - * switch between (int,string,vector,DataArrayChar) - */ -static void convertObjToPossibleCpp6(PyObject *value, int& sw, char& cTyp, std::string& sType, std::vector& vsType, ParaMEDMEM::DataArrayChar *& dacType) throw(INTERP_KERNEL::Exception) +static PyObject *convertCartesianAMRMesh(ParaMEDMEM::MEDCouplingCartesianAMRMeshGen *mesh, int owner) throw(INTERP_KERNEL::Exception) { - const char *msg="4 types accepted : string, list or tuple of strings having same size, not null DataArrayChar instance."; - sw=-1; - if(PyString_Check(value)) - { - const char *pt=PyString_AsString(value); - Py_ssize_t sz=PyString_Size(value); - if(sz==1) - { - cTyp=pt[0]; - sw=1; - return; - } - else - { - sType=pt; - sw=2; - return; - } - } - if(PyTuple_Check(value)) + if(!mesh) { - int size=PyTuple_Size(value); - vsType.resize(size); - for(int i=0;i(mesh)) { - int size=PyList_Size(value); - vsType.resize(size); - for(int i=0;i(mesh),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRMeshSub,owner); } - void *argp; - int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayChar,0|0); - if(SWIG_IsOK(status)) + if(dynamic_cast(mesh)) { - dacType=reinterpret_cast< ParaMEDMEM::DataArrayChar * >(argp); - if(!dacType) - { - std::ostringstream oss; oss << msg << " Instance in null !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - sw=4; - return ; + return SWIG_NewPointerObj(reinterpret_cast(mesh),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRMesh,owner); } - throw INTERP_KERNEL::Exception(msg); + throw INTERP_KERNEL::Exception("convertCartesianAMRMesh wrap : unrecognized type of cartesian AMR mesh !"); } -/*! - * if value int -> cpp it sw=1 - * if value list[int] -> vt sw=2 - * if value tuple[int] -> vt sw=2 - * if value slice -> pt sw=3 - * if value DataArrayInt -> dt sw=4 - * if value tuple [int,int] -> cpp it,ip sw=5 - * if value tuple [list[int],int] -> cpp vt,ip sw=6 - * if value tuple [tuple[int],int] -> cpp vt,ip sw=6 - * if value tuple [slice,int] -> cpp pt,ip sw=7 - * if value tuple [DaI,int] -> cpp dt,ip sw=8 - * if value tuple [int,list[int]] -> cpp it,vc sw=9 - * if value tuple [list[int],list[int]] -> cpp vt,vc sw=10 - * if value tuple [tuple[int],list[int]] -> cpp vt,vc sw=10 - * if value tuple [slice,list[int]] -> cpp pt,vc sw=11 - * if value tuple [DaI,list[int]] -> cpp dt,vc sw=12 - * if value tuple [int,tuple[int]] -> cpp it,vc sw=9 - * if value tuple [list[int],tuple[int]] -> cpp vt,vc sw=10 - * if value tuple [tuple[int],tuple[int]] -> cpp vt,vc sw=10 - * if value tuple [slice,tuple[int]] -> cpp pt,vc sw=11 - * if value tuple [DaI,tuple[int]] -> cpp dt,vc sw=12 - * if value tuple [int,slice] -> cpp it,pc sw=13 - * if value tuple [list[int],slice] -> cpp vt,pc sw=14 - * if value tuple [tuple[int],slice] -> cpp vt,pc sw=14 - * if value tuple [slice,slice] -> cpp pt,pc sw=15 - * if value tuple [DaI,slice] -> cpp dt,pc sw=16 - * - * switch between (int,vector,DataArrayInt) - */ -static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo, int& sw, int& it, int& ic, std::vector& vt, std::vector& vc, - std::pair >& pt, std::pair >& pc, - ParaMEDMEM::DataArrayInt *&dt, ParaMEDMEM::DataArrayInt *&dc) throw(INTERP_KERNEL::Exception) +static PyObject *convertDataForGodFather(ParaMEDMEM::MEDCouplingDataForGodFather *data, int owner) throw(INTERP_KERNEL::Exception) { - if(!PyTuple_Check(value)) + if(!data) { - convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt); - return ; + Py_XINCREF(Py_None); + return Py_None; } - else + if(dynamic_cast(data)) { - int sz=PyTuple_Size(value); - if(sz!=2) - throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !"); - PyObject *ob0=PyTuple_GetItem(value,0); - int sw1,sw2; - convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt); - PyObject *ob1=PyTuple_GetItem(value,1); - convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc); - sw=4*sw2+sw1; + return SWIG_NewPointerObj(reinterpret_cast(data),SWIGTYPE_p_ParaMEDMEM__MEDCouplingAMRAttribute,owner); } + throw INTERP_KERNEL::Exception("convertDataForGodFather wrap : unrecognized data type for AMR !"); } -/*! - * if value int -> cpp val sw=1 - * if value double -> cpp val sw=1 - * if value DataArrayDouble -> cpp DataArrayDouble sw=2 - * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 - * if value list[int,double] -> cpp std::vector sw=4 - * if value tuple[int,double] -> cpp std::vector sw=4 - */ -static void convertObjToPossibleCpp5(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector& f) +static PyObject *convertCartesianAMRPatch(ParaMEDMEM::MEDCouplingCartesianAMRPatchGen *patch, int owner) throw(INTERP_KERNEL::Exception) { - sw=-1; - if(PyFloat_Check(value)) + if(!patch) { - val=PyFloat_AS_DOUBLE(value); - sw=1; - return; + Py_XINCREF(Py_None); + return Py_None; } - if(PyInt_Check(value)) + if(dynamic_cast(patch)) { - val=(double)PyInt_AS_LONG(value); - sw=1; - return; + return SWIG_NewPointerObj(reinterpret_cast(patch),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRPatchGF,owner); } - if(PyTuple_Check(value)) + if(dynamic_cast(patch)) { - int size=PyTuple_Size(value); - f.resize(size); - for(int i=0;i(argp); - sw=2; - return ; - } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0); - if(SWIG_IsOK(status)) - { - e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp); - sw=3; - return ; - } - throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple"); -} - -/*! - * if value int -> cpp val sw=1 - * if value double -> cpp val sw=1 - * if value DataArrayDouble -> cpp DataArrayDouble sw=2 - * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 - * if value list[int,double] -> cpp std::vector sw=4 - * if value tuple[int,double] -> cpp std::vector sw=4 - */ -static const double *convertObjToPossibleCpp5_Safe(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector& f, - const char *msg, int nbTuplesExpected, int nbCompExpected, bool throwIfNullPt) throw(INTERP_KERNEL::Exception) -{ - sw=-1; - if(PyFloat_Check(value)) - { - val=PyFloat_AS_DOUBLE(value); - sw=1; - if(nbTuplesExpected*nbCompExpected!=1) - { - std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - return &val; - } - if(PyInt_Check(value)) - { - val=(double)PyInt_AS_LONG(value); - sw=1; - if(nbTuplesExpected*nbCompExpected!=1) - { - std::ostringstream oss; oss << msg << "dimension expected to be " << nbTuplesExpected*nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - return &val; - } - if(PyTuple_Check(value) || PyList_Check(value)) - { - try - { - int tmp1=nbTuplesExpected,tmp2=nbCompExpected; - std::vector ret=fillArrayWithPyListDbl2(value,tmp1,tmp2); - sw=4; - f=ret; - return &f[0]; - } - catch(INTERP_KERNEL::Exception& exc) { throw exc; } - } - void *argp; - int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0); - if(SWIG_IsOK(status)) - { - d=reinterpret_cast< ParaMEDMEM::DataArrayDouble * >(argp); - sw=2; - if(d) - { - if(d->getNumberOfTuples()==nbTuplesExpected) - { - if(d->getNumberOfComponents()==nbCompExpected) - { - return d->getConstPointer(); - } - else - { - std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - std::ostringstream oss; oss << msg << " input DataArrayDouble should have a number of tuples equal to " << nbTuplesExpected << " and there are " << d->getNumberOfTuples() << " tuples !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - if(throwIfNullPt) - { - std::ostringstream oss; oss << msg << " null pointer not accepted!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - else - return 0; - } - } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0); - if(SWIG_IsOK(status)) - { - e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp); - sw=3; - if(e->getNumberOfCompo()==nbCompExpected) - { - if(nbTuplesExpected==1) - return e->getConstPointer(); - else - { - std::ostringstream oss; oss << msg << "nb of tuples expected to be " << nbTuplesExpected << " , and input DataArrayDoubleTuple has always one tuple by contruction !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple"); -} - -/*! - * if value int -> cpp val sw=1 - * if value double -> cpp val sw=1 - * if value DataArrayDouble -> cpp DataArrayDouble sw=2 - * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 - * if value list[int,double] -> cpp std::vector sw=4 - * if value tuple[int,double] -> cpp std::vector sw=4 - */ -static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, double& val, ParaMEDMEM::DataArrayDouble *&d, ParaMEDMEM::DataArrayDoubleTuple *&e, std::vector& f, - const char *msg, int nbCompExpected, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception) -{ - sw=-1; - if(PyFloat_Check(value)) - { - val=PyFloat_AS_DOUBLE(value); - sw=1; - if(nbCompExpected!=1) - { - std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyFloat) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - nbTuples=1; - return &val; - } - if(PyInt_Check(value)) - { - val=(double)PyInt_AS_LONG(value); - sw=1; - if(nbCompExpected!=1) - { - std::ostringstream oss; oss << msg << "dimension expected to be " << nbCompExpected << " , and your data in input has dimension one (single PyInt) !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - nbTuples=1; - return &val; - } - if(PyTuple_Check(value)) - { - int size=PyTuple_Size(value); - f.resize(size); - for(int i=0;i(argp); - sw=2; - if(d) - { - if(d->getNumberOfComponents()==nbCompExpected) - { - nbTuples=d->getNumberOfTuples(); - return d->getConstPointer(); - } - else - { - std::ostringstream oss; oss << msg << "nb of components expected to be a multiple of " << nbCompExpected << " , and input has " << d->getNumberOfComponents() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - if(throwIfNullPt) - { - std::ostringstream oss; oss << msg << " null pointer not accepted!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - else - { nbTuples=0; return 0; } - } - } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0); - if(SWIG_IsOK(status)) - { - e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp); - sw=3; - if(e) - { - if(e->getNumberOfCompo()==nbCompExpected) - { - nbTuples=1; - return e->getConstPointer(); - } - else - { - std::ostringstream oss; oss << msg << "nb of components expected to be " << nbCompExpected << " , and input DataArrayDoubleTuple has " << e->getNumberOfCompo() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - if(throwIfNullPt) - { - std::ostringstream oss; oss << msg << " null pointer not accepted!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - else - { nbTuples=0; return 0; } - } - } - throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple"); -} - -/*! - * if value int -> cpp val sw=1 - * if value double -> cpp val sw=1 - * if value DataArrayDouble -> cpp DataArrayDouble sw=2 - * if value DataArrayDoubleTuple -> cpp DataArrayDoubleTuple sw=3 - * if value list[int,double] -> cpp std::vector sw=4 - * if value tuple[int,double] -> cpp std::vector sw=4 - */ -static const double *convertObjToPossibleCpp5_SingleCompo(PyObject *value, int& sw, double& val, std::vector& f, - const char *msg, bool throwIfNullPt, int& nbTuples) throw(INTERP_KERNEL::Exception) -{ - ParaMEDMEM::DataArrayDouble *d=0; - ParaMEDMEM::DataArrayDoubleTuple *e=0; - sw=-1; - if(PyFloat_Check(value)) - { - val=PyFloat_AS_DOUBLE(value); - sw=1; - nbTuples=1; - return &val; - } - if(PyInt_Check(value)) - { - val=(double)PyInt_AS_LONG(value); - sw=1; - nbTuples=1; - return &val; - } - if(PyTuple_Check(value)) - { - int size=PyTuple_Size(value); - f.resize(size); - for(int i=0;i(argp); - sw=2; - if(d) - { - if(d->getNumberOfComponents()==1) - { - nbTuples=d->getNumberOfTuples(); - return d->getConstPointer(); - } - else - { - std::ostringstream oss; oss << msg << "nb of components expected to be one, and input has " << d->getNumberOfComponents() << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - } - else - { - if(throwIfNullPt) - { - std::ostringstream oss; oss << msg << " null pointer not accepted!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - else - { nbTuples=0; return 0; } - } - } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDoubleTuple,0|0); - if(SWIG_IsOK(status)) - { - e=reinterpret_cast< ParaMEDMEM::DataArrayDoubleTuple * >(argp); - sw=3; - if(e) - { - nbTuples=e->getNumberOfCompo(); - return e->getConstPointer(); - } - else - { - if(throwIfNullPt) - { - std::ostringstream oss; oss << msg << " null pointer not accepted!"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); - } - else - { nbTuples=0; return 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 sw=2 - * if python tuple[int] -> cpp vector sw=2 - * if python DataArrayInt -> cpp DataArrayInt sw=3 - * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 - * - * switch between (int,vector,DataArrayInt) - */ -static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector& 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(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(); + return SWIG_NewPointerObj(reinterpret_cast(patch),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCartesianAMRPatch,owner); } - throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); + throw INTERP_KERNEL::Exception("convertCartesianAMRPatch wrap : unrecognized type of cartesian AMR patch !"); } static ParaMEDMEM::MEDCouplingFieldDouble *ParaMEDMEM_MEDCouplingFieldDouble___add__Impl(ParaMEDMEM::MEDCouplingFieldDouble *self, PyObject *obj) throw(INTERP_KERNEL::Exception)