From: ageay Date: Tue, 19 Mar 2013 16:01:17 +0000 (+0000) Subject: Implementation of __getitem__ and __setitem__ in DataArrayAsciiChar X-Git-Tag: V6_main_FINAL~266 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bc8c921d58ea203e0df5e3d5f160f6c7e4aee23d;p=tools%2Fmedcoupling.git Implementation of __getitem__ and __setitem__ in DataArrayAsciiChar --- diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 183b034d4..d832e9df6 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -11588,6 +11588,28 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd4.toStrList()) dd5=DataArrayChar.Aggregate([dd4,dd3,dd4]) self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY','ABGYY','CdGYY','EFGYY','GHGYY','IJGYY'],dd5.toStrList()) + # getitem, __iter__,__setitem__ + a=list(dd3) + self.assertEqual("ABGYY",str(a[0])) + dd4=dd3[::2] + self.assertEqual(['ABGYY','EFGYY','IJGYY'],dd4.toStrList()) + dd4=dd3[(3,2,1)] + self.assertEqual(['GHGYY','EFGYY','CdGYY'],dd4.toStrList()) + dd4=dd3[:] + dd4[::2]=["12","345","67890"] + self.assertEqual(['12 ','CdGYY','345 ','GHGYY','67890'],dd4.toStrList()) + dd4=dd3[:] + dd4[[1,2]]=" " + self.assertEqual(['ABGYY',' ',' ','GHGYY','IJGYY'],dd4.toStrList()) + dd4=dd3[:] + dd4[4]='12345' + self.assertEqual(['ABGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList()) + dd4[0]=dd4[1] + self.assertEqual(['CdGYY','CdGYY','EFGYY','GHGYY','12345'],dd4.toStrList()) + dd4=DataArrayAsciiChar(["abc","de","fghi"]) + self.assertEqual(['abc ','de ','fghi'],dd4.toStrList()) + dd4=DataArrayAsciiChar(["abc","de","fghi"],"t") + self.assertEqual(['abct','dett','fghi'],dd4.toStrList()) pass def setUp(self): diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 1b549df73..ca75f6f6d 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -606,10 +606,8 @@ namespace ParaMEDMEM std::copy(elts.begin(),elts.end(),d0->getPointer()); std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -651,10 +649,8 @@ namespace ParaMEDMEM std::copy(elts.begin(),elts.end(),d0->getPointer()); std::copy(eltsIndex.begin(),eltsIndex.end(),d1->getPointer()); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -1265,8 +1261,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -1277,8 +1272,7 @@ namespace ParaMEDMEM int tmpp1=-1; std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -1290,8 +1284,7 @@ namespace ParaMEDMEM int tmpp1=-1,tmpp2=-1; std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else if(PyInt_Check(elt0)) @@ -1310,8 +1303,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayByte::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -1323,8 +1315,7 @@ namespace ParaMEDMEM {//DataArrayByte.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayByte::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -1529,7 +1520,7 @@ namespace ParaMEDMEM static DataArrayAsciiChar *New(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) { - const char *msg="ParaMEDMEM::DataArrayAsciiChar::New : Available API are : \n-DataArrayAsciiChar.New()\n--DataArrayAsciiChar.New([1,3,4])\n-DataArrayAsciiChar.New([1,3,4],3)\n-DataArrayAsciiChar.New([1,3,4,5],2,2)\n-DataArrayAsciiChar.New(5)\n-DataArrayAsciiChar.New(5,2) !"; + const char *msg="ParaMEDMEM::DataArrayAsciiChar::New : Available API are : \n-DataArrayAsciiChar.New()\n-DataArrayAsciiChar.New([1,3,4])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"])\n-DataArrayAsciiChar.New([\"abc\",\"de\",\"fghi\"],\"t\")\n-DataArrayAsciiChar.New([1,3,4],3)\n-DataArrayAsciiChar.New([1,3,4,5],2,2)\n-DataArrayAsciiChar.New(5)\n-DataArrayAsciiChar.New(5,2) !"; if(PyList_Check(elt0) || PyTuple_Check(elt0)) { if(nbOfTuples) @@ -1549,8 +1540,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -1561,21 +1551,38 @@ namespace ParaMEDMEM int tmpp1=-1; std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } + else if(PyString_Check(nbOfTuples)) + { + if(PyString_Size(nbOfTuples)!=1) + throw INTERP_KERNEL::Exception(msg); + //DataArrayAsciiChar.New(["abc","de","fghi"],"t") + std::vector tmp; + if(fillStringVector(elt0,tmp)) + return DataArrayAsciiChar::New(tmp,PyString_AsString(nbOfTuples)[0]); + else + throw INTERP_KERNEL::Exception(msg); + } else throw INTERP_KERNEL::Exception(msg); } else - {// DataArrayAsciiChar.New([1,3,4]) - MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); - int tmpp1=-1,tmpp2=-1; - std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); - ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + { + std::vector tmmp; + if(fillStringVector(elt0,tmmp)) + //DataArrayAsciiChar.New(["abc","de","fghi"]) + return DataArrayAsciiChar::New(tmmp,' '); + else + { + // DataArrayAsciiChar.New([1,3,4]) + MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); + return ret.retn(); + } } } else if(PyInt_Check(elt0)) @@ -1594,8 +1601,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayAsciiChar::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -1607,8 +1613,7 @@ namespace ParaMEDMEM {//DataArrayAsciiChar.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayAsciiChar::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -1617,7 +1622,7 @@ namespace ParaMEDMEM DataArrayAsciiChar(PyObject *elt0, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) { - return ParaMEDMEM_DataArrayAsciiChar_New__SWIG_1(elt0,nbOfTuples,nbOfComp); + return ParaMEDMEM_DataArrayAsciiChar_New__SWIG_3(elt0,nbOfTuples,nbOfComp); } DataArrayAsciiCharIterator *__iter__() throw(INTERP_KERNEL::Exception) @@ -1717,7 +1722,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayAsciiChar::search : only strings in input supported !"); } - PyObject *getTuple(int tupleId) throw(INTERP_KERNEL::Exception) + PyObject *getTuple(int tupleId) const throw(INTERP_KERNEL::Exception) { int sz=self->getNumberOfComponents(); INTERP_KERNEL::AutoPtr tmp=new char[sz+1]; tmp[sz]='\0'; @@ -1796,6 +1801,185 @@ namespace ParaMEDMEM return ParaMEDMEM_DataArrayAsciiChar_presenceOfTuple(self,obj); } } + + PyObject *__getitem__(PyObject *obj) const throw(INTERP_KERNEL::Exception) + { + int sw,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + switch(sw) + { + case 1: + return ParaMEDMEM_DataArrayAsciiChar_getTuple(self,iTypppArr); + case 2: + return convertDataArrayChar(self->selectByTupleIdSafe(&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size()), SWIG_POINTER_OWN | 0 ); + case 3: + return convertDataArrayChar(self->selectByTupleId2(sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second), SWIG_POINTER_OWN | 0 ); + case 4: + return convertDataArrayChar(self->selectByTupleIdSafe(daIntTyypp->begin(),daIntTyypp->end()), SWIG_POINTER_OWN | 0 ); + default: + throw INTERP_KERNEL::Exception("DataArrayAsciiChar::__getitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input !"); + } + } + + DataArrayAsciiChar *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) + { + static const char msg[]="DataArrayAsciiChar::__setitem__ : supporting int, list of int, tuple of int, DataArrayInt and slice in input, and 4 types accepted in value : string, list or tuple of strings having same size, not null DataArrayChar instance."; + int sw1,iTypppArr; + std::vector stdvecTyyppArr; + std::pair > sTyyppArr; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbOfCompo=self->getNumberOfTuples(); + convertObjToPossibleCpp2(obj,nbOfCompo,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp); + int sw2; + char vc; std::string sc; std::vector vsc; DataArrayChar *dacc=0; + convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc); + switch(sw1) + { + case 1: + {//obj int + switch(sw2) + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&iTypppArr,&iTypppArr+1,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + case 2: + {//obj list-tuple[int] + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,&stdvecTyyppArr[0],&stdvecTyyppArr[0]+stdvecTyyppArr.size(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 3: + {//slice + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple1(vc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues1(tmp,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues1(dacc,sTyyppArr.first,sTyyppArr.second.first,sTyyppArr.second.second,0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + case 4: + {//DataArrayInt + switch(sw2) + { + {//value char + case 1: + { + self->setPartOfValuesSimple3(vc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1); + return self; + } + //value string + case 2: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(sc); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value vector + case 3: + { + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayAsciiChar::New(vsc,' '); + self->setPartOfValues3(tmp,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + //value DataArrayChar + case 4: + { + self->setPartOfValues3(dacc,daIntTyypp->begin(),daIntTyypp->end(),0,nbOfCompo,1,false); + return self; + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } + } + default: + throw INTERP_KERNEL::Exception(msg); + } + } } %extend ParaMEDMEM::MEDCouplingFieldDiscretization @@ -3103,14 +3287,12 @@ namespace ParaMEDMEM MEDCouplingUMesh *mOut=self->emulateMEDMEMBDC(nM1LevMesh,d0,d1,d2,d3,d4,dd5); PyObject *ret=PyTuple_New(7); PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(mOut),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr((DataArrayInt *)d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,3,SWIG_NewPointerObj(SWIG_as_voidptr(d2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(d3),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,5,SWIG_NewPointerObj(SWIG_as_voidptr(d4),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); PyTuple_SetItem(ret,6,SWIG_NewPointerObj(SWIG_as_voidptr(dd5),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); return ret; } @@ -3120,10 +3302,8 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr d1=DataArrayInt::New(); self->getReverseNodalConnectivity(d0,d1); PyObject *ret=PyTuple_New(2); - PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); - d0->incrRef(); - d1->incrRef(); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(d0.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(d1.retn()),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); return ret; } @@ -3757,8 +3937,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -3769,8 +3948,7 @@ namespace ParaMEDMEM int tmpp1=-1; std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples1,tmpp1); ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -3782,8 +3960,7 @@ namespace ParaMEDMEM int tmpp1=-1,tmpp2=-1; std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else if(PyInt_Check(elt0)) @@ -3802,8 +3979,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -3815,8 +3991,7 @@ namespace ParaMEDMEM {//DataArrayDouble.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -4751,8 +4926,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -4788,8 +4962,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -4863,8 +5036,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1.,-val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -4900,8 +5072,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(-1.,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -4975,8 +5146,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -5012,8 +5182,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -5089,8 +5258,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayDouble::__div__ : trying to divide by zero !"); MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1/val,0.); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -5126,8 +5294,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyInv(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 3: { @@ -5518,8 +5685,7 @@ namespace ParaMEDMEM MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,nbOfCompo); ret->alloc(nbOfTuples1,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -5530,8 +5696,7 @@ namespace ParaMEDMEM int tmpp1=-1; std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples1,tmpp1); ret->alloc(nbOfTuples1,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -5543,8 +5708,7 @@ namespace ParaMEDMEM int tmpp1=-1,tmpp2=-1; std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); - ret->incrRef(); - return ret; + return ret.retn(); } } else if(PyInt_Check(elt0)) @@ -5563,8 +5727,7 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples1,nbOfCompo); - ret->incrRef(); - return ret; + return ret.retn(); } else throw INTERP_KERNEL::Exception(msg); @@ -5576,8 +5739,7 @@ namespace ParaMEDMEM {//DataArrayInt.New(5) MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples1,1); - ret->incrRef(); - return ret; + return ret.retn(); } } else @@ -6690,8 +6852,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6727,8 +6888,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6802,8 +6962,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(1,-val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6839,8 +6998,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(-1,val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6914,8 +7072,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -6951,8 +7108,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyLin(val,0); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -7026,8 +7182,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyDivideBy(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -7063,8 +7218,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyInv(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -7138,8 +7292,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyModulus(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { @@ -7175,8 +7328,7 @@ namespace ParaMEDMEM { MEDCouplingAutoRefCountObjectPtr ret=self->deepCpy(); ret->applyRModulus(val); - ret->incrRef(); - return ret; + return ret.retn(); } case 2: { diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index bcbe12ec6..6d2801d01 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -490,6 +490,40 @@ static std::vector fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, return ret; } +static bool fillStringVector(PyObject *pyLi, std::vector& vec) throw(INTERP_KERNEL::Exception) +{ + if(PyList_Check(pyLi)) + { + Py_ssize_t sz=PyList_Size(pyLi); + vec.resize(sz); + for(int i=0;i 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 - * if python DataArrayInt -> cpp DataArrayInt sw=4 + * 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) */ @@ -1039,7 +1073,7 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& sw=4; return ; } - status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0);; + status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0); if(SWIG_IsOK(status)) { ParaMEDMEM::DataArrayIntTuple *tmp=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); @@ -1056,6 +1090,13 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int& 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; @@ -1125,6 +1166,86 @@ static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int& 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) +{ + 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)) + { + int size=PyTuple_Size(value); + vsType.resize(size); + for(int i=0;i(argp); + if(!dacType) + { + std::ostringstream oss; oss << msg << " Instance in null !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + sw=4; + return ; + } + throw INTERP_KERNEL::Exception(msg); +} + /*! * if value int -> cpp it sw=1 * if value list[int] -> vt sw=2