X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingMemArray.i;h=7d583d4c8599038e25bab3262e4e12f06be9a464;hb=6da34015490b019ffb480bf92519ef268dc2de5b;hp=c638e76d43c094175b55471f7c6e088d69889b6b;hpb=79c404a024c4b00550400f158f89fcc64859e71d;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index c638e76d4..7d583d4c8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.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 @@ -102,6 +102,7 @@ %newobject ParaMEDMEM::DataArrayInt::buildPermArrPerLevel; %newobject ParaMEDMEM::DataArrayInt::getDifferentValues; %newobject ParaMEDMEM::DataArrayInt::FindPermutationFromFirstToSecond; +%newobject ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation; %newobject ParaMEDMEM::DataArrayInt::__neg__; %newobject ParaMEDMEM::DataArrayInt::__add__; %newobject ParaMEDMEM::DataArrayInt::__radd__; @@ -2249,6 +2250,11 @@ namespace ParaMEDMEM return trueSelf; } + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } + PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { const char msg2[]="DataArrayDoubleTuple::__getitem__ : Mismatch of slice values in 2nd parameter (components) !"; @@ -2268,7 +2274,8 @@ namespace ParaMEDMEM { std::ostringstream oss; oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + PyErr_SetString(PyExc_StopIteration,oss.str().c_str()); + return 0; } if(singleVal>=0) return PyFloat_FromDouble(pt[singleVal]); @@ -2787,6 +2794,17 @@ namespace ParaMEDMEM return ret; } + static DataArrayInt *CheckAndPreparePermutation(PyObject *arr) throw(INTERP_KERNEL::Exception) + { + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); + int szArr,sw,iTypppArr; + std::vector stdvecTyyppArr; + const int *arrPtr(convertObjToPossibleCpp1_Safe(arr,sw,szArr,iTypppArr,stdvecTyyppArr)); + int *pt(ParaMEDMEM::DataArrayInt::CheckAndPreparePermutation(arrPtr,arrPtr+szArr)); + ret->useArray(pt,true,ParaMEDMEM::C_DEALLOC,szArr,1); + return ret.retn(); + } + void setValues(PyObject *li, PyObject *nbOfTuples=0, PyObject *nbOfComp=0) throw(INTERP_KERNEL::Exception) { const char *msg="ParaMEDMEM::DataArrayInt::setValues : Available API are : \n-DataArrayInt.setValues([1,3,4])\n-DataArrayInt.setValues([1,3,4],3)\n-DataArrayInt.setValues([1,3,4,5],2,2)\n-DataArrayInt.New(5)\n !"; @@ -4510,6 +4528,11 @@ namespace ParaMEDMEM Py_XINCREF(trueSelf); return trueSelf; } + + PyObject *__len__() throw(INTERP_KERNEL::Exception) + { + return PyInt_FromLong(self->getNumberOfCompo()); + } PyObject *__getitem__(PyObject *obj) throw(INTERP_KERNEL::Exception) { @@ -4530,7 +4553,8 @@ namespace ParaMEDMEM { std::ostringstream oss; oss << "Requesting for id " << singleVal << " having only " << nbc << " components !"; - throw INTERP_KERNEL::Exception(oss.str().c_str()); + PyErr_SetString(PyExc_StopIteration,oss.str().c_str()); + return 0; } if(singleVal>=0) return PyInt_FromLong(pt[singleVal]);