From 66824244c56a0bff3eea82904c2e6500f5593636 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 18 Jun 2012 13:35:19 +0000 Subject: [PATCH] Extend setPartOfValues. --- src/MEDCoupling/MEDCouplingMemArray.cxx | 60 +++++++++++++++---------- src/MEDCoupling/MEDCouplingMemArray.hxx | 1 + 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index cce1ae037..48d19a1b1 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -282,6 +282,9 @@ void DataArray::checkNbOfElems(int nbOfElems, const char *msg) const throw(INTER } } +/*! + * Simply this method checks that \b value is in [0,\b ref). + */ void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception) { if(value<0 || value>=ref) @@ -291,6 +294,27 @@ void DataArray::CheckValueInRange(int ref, int value, const char *msg) throw(INT } } +/*! + * This method checks that [\b start, \b end) is compliant with ref length \b value. + * typicaly start in [0,\b value) and end in [0,\b value). If value==start and start==end, it is supported. + */ +void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception) +{ + if(start<0 || start>=value) + { + if(value!=start || end!=start) + { + std::ostringstream oss; oss << "DataArray::CheckValueInRange : " << msg << " ! Expected start " << start << " of range in [0," << value << "[ !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + if(end<0 || end>value) + { + std::ostringstream oss; oss << "DataArray::CheckClosingParInRange : " << msg << " ! Expected start " << end << " of range in [0," << value << "[ !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } +} + void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception) { if(value<0 || value>ref) @@ -1140,10 +1164,8 @@ void DataArrayDouble::setPartOfValues1(const DataArrayDouble *a, int bgTuples, i int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); int nbComp=getNumberOfComponents(); int nbOfTuples=getNumberOfTuples(); - DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value"); - DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value"); - DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value"); - DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value"); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); a->checkNbOfElems(newNbOfTuples*newNbOfComp,msg); if(strictCompoCompare) a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); @@ -1165,10 +1187,8 @@ void DataArrayDouble::setPartOfValuesSimple1(double a, int bgTuples, int endTupl int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); int nbComp=getNumberOfComponents(); int nbOfTuples=getNumberOfTuples(); - DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value"); - DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value"); - DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value"); - DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value"); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); double *pt=getPointer()+bgTuples*nbComp+bgComp; for(int i=0;igetNbOfElems()==newNbOfTuples*newNbOfComp) @@ -1312,8 +1331,7 @@ void DataArrayDouble::setPartOfValuesSimple3(double a, const int *bgTuples, cons int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); int nbComp=getNumberOfComponents(); int nbOfTuples=getNumberOfTuples(); - DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value"); - DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); double *pt=getPointer()+bgComp; for(const int *w=bgTuples;w!=endTuples;w++) for(int j=0;jcheckNbOfElems(newNbOfTuples*newNbOfComp,msg); if(strictCompoCompare) a->checkNbOfTuplesAndComp(newNbOfTuples,newNbOfComp,msg); @@ -4015,10 +4031,8 @@ void DataArrayInt::setPartOfValuesSimple1(int a, int bgTuples, int endTuples, in int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); int nbComp=getNumberOfComponents(); int nbOfTuples=getNumberOfTuples(); - DataArray::CheckValueInRange(nbOfTuples,bgTuples,"invalid begin tuple value"); - DataArray::CheckClosingParInRange(nbOfTuples,endTuples,"invalid end tuple value"); - DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value"); - DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value"); + DataArray::CheckValueInRangeEx(nbOfTuples,bgTuples,endTuples,"invalid tuple value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); int *pt=getPointer()+bgTuples*nbComp+bgComp; for(int i=0;igetNbOfElems()==newNbOfTuples*newNbOfComp) @@ -4162,8 +4175,7 @@ void DataArrayInt::setPartOfValuesSimple3(int a, const int *bgTuples, const int int newNbOfComp=DataArray::GetNumberOfItemGivenBES(bgComp,endComp,stepComp,msg); int nbComp=getNumberOfComponents(); int nbOfTuples=getNumberOfTuples(); - DataArray::CheckValueInRange(nbComp,bgComp,"invalid begin component value"); - DataArray::CheckClosingParInRange(nbComp,endComp,"invalid end component value"); + DataArray::CheckValueInRangeEx(nbComp,bgComp,endComp,"invalid component value"); int *pt=getPointer()+bgComp; for(const int *w=bgTuples;w!=endTuples;w++) for(int j=0;j