From daf048e76bc4624037ccc4bd2cf28aeb3f366811 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 26 Apr 2012 09:18:09 +0000 Subject: [PATCH] DataArray*::getIJSafe --- src/MEDCoupling/MEDCouplingMemArray.cxx | 42 +++++++++++++++++++++++++ src/MEDCoupling/MEDCouplingMemArray.hxx | 2 ++ 2 files changed, 44 insertions(+) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 0f10c59de..03492743b 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -1421,6 +1421,27 @@ void DataArrayDouble::setContigPartOfSelectedValues2(int tupleIdStart, const Dat } } +/*! + * This method is equivalent to DataArrayDouble::getIJ except that here \b tupleId is checked to be in [0,this->getNumberOfTuples()) and compoId to be in [0,this->getNumberOfComponents()). + * If one of these check fails an INTERP_KERNEL::Exception will be thrown. + * So this method is safe but expensive if used to go through all data of \b this. + */ +double DataArrayDouble::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(tupleId<0 || tupleId>=getNumberOfTuples()) + { + std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(compoId<0 || compoId>=getNumberOfComponents()) + { + std::ostringstream oss; oss << "DataArrayDouble::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return _mem[tupleId*((int)_info_on_compo.size())+compoId]; +} + /*! * This method returns the last element in 'this'. So this method makes the hypothesis that 'this' is allocated. * This method works only for arrays that have exactly number of components equal to 1. If not an exception is thrown. @@ -4126,6 +4147,27 @@ void DataArrayInt::setContigPartOfSelectedValues2(int tupleIdStart, const DataAr } } +/*! + * This method is equivalent to DataArrayInt::getIJ except that here \b tupleId is checked to be in [0,this->getNumberOfTuples()) and compoId to be in [0,this->getNumberOfComponents()). + * If one of these check fails an INTERP_KERNEL::Exception will be thrown. + * So this method is safe but expensive if used to go through all data of \b this. + */ +int DataArrayInt::getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(tupleId<0 || tupleId>=getNumberOfTuples()) + { + std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for tupleId " << tupleId << " should be in [0," << getNumberOfTuples() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(compoId<0 || compoId>=getNumberOfComponents()) + { + std::ostringstream oss; oss << "DataArrayInt::getIJSafe : request for compoId " << compoId << " should be in [0," << getNumberOfComponents() << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + return _mem[tupleId*((int)_info_on_compo.size())+compoId]; +} + /*! * This method returns the last element in 'this'. So this method makes the hypothesis that 'this' is allocated. * This method works only for arrays that have exactly number of components equal to 1. If not an exception is thrown. diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 39c71433b..1245e1558 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -198,6 +198,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void getTuple(int tupleId, double *res) const { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } MEDCOUPLING_EXPORT double getIJ(int tupleId, int compoId) const { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } MEDCOUPLING_EXPORT double back() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT double getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, double newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, double newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } MEDCOUPLING_EXPORT double *getPointer() { return _mem.getPointer(); } @@ -386,6 +387,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void setContigPartOfSelectedValues2(int tupleIdStart, const DataArrayInt *a, int bg, int end2, int step) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void getTuple(int tupleId, int *res) const { std::copy(_mem.getConstPointerLoc(tupleId*((int)_info_on_compo.size())),_mem.getConstPointerLoc((tupleId+1)*((int)_info_on_compo.size())),res); } MEDCOUPLING_EXPORT int getIJ(int tupleId, int compoId) const { return _mem[tupleId*((int)_info_on_compo.size())+compoId]; } + MEDCOUPLING_EXPORT int getIJSafe(int tupleId, int compoId) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int back() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setIJ(int tupleId, int compoId, int newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; declareAsNew(); } MEDCOUPLING_EXPORT void setIJSilent(int tupleId, int compoId, int newVal) { _mem[tupleId*((int)_info_on_compo.size())+compoId]=newVal; } -- 2.39.2