From: ageay Date: Tue, 18 Dec 2012 17:39:25 +0000 (+0000) Subject: DataArrayInt,DataArrayDouble pushBack and popBack X-Git-Tag: V6_main_FINAL~445 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c30e41a4af80543784ae21133a8b6ec4da414a1b;p=tools%2Fmedcoupling.git DataArrayInt,DataArrayDouble pushBack and popBack --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 58a16e355..e91915af2 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -130,12 +130,6 @@ void DataArray::copyPartOfStringInfoFrom2(const std::vector& compoIds, cons bool DataArray::areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const { std::ostringstream oss; - if(_nb_of_tuples!=other._nb_of_tuples) - { - oss << "Number of tuples of DataArray mismatch : this number of tuples=" << _nb_of_tuples << " other number of tuples=" << other._nb_of_tuples; - reason=oss.str(); - return false; - } if(_name!=other._name) { oss << "Names DataArray mismatch : this name=\"" << _name << " other name=\"" << other._name << "\" !"; @@ -553,10 +547,6 @@ void DataArrayDouble::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) else if(nbCompo==0) { _mem.reserve(nbOfElems); - if(_nb_of_tuples==-1) - _nb_of_tuples=0; - else - _nb_of_tuples=std::min(_nb_of_tuples,nbOfElems); _info_on_compo.resize(1); } else @@ -566,10 +556,7 @@ void DataArrayDouble::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) - { - _mem.pushBack(val); - _nb_of_tuples++; - } + _mem.pushBack(val); else throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !"); } @@ -577,11 +564,7 @@ void DataArrayDouble::pushBackSilent(double val) throw(INTERP_KERNEL::Exception) double DataArrayDouble::popBackSilent() throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) - { - double ret=_mem.popBack(); - _nb_of_tuples--; - return ret; - } + return _mem.popBack(); else throw INTERP_KERNEL::Exception("DataArrayDouble::pushBackSilent : not available for DataArrayDouble with number of components different than 1 !"); } @@ -606,9 +589,8 @@ void DataArrayDouble::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::E { if(nbOfTuple<0 || nbOfCompo<0) throw INTERP_KERNEL::Exception("DataArrayDouble::alloc : request for negative length of data !"); - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); - _mem.alloc(nbOfCompo*_nb_of_tuples); + _mem.alloc(nbOfCompo*nbOfTuple); declareAsNew(); } @@ -813,8 +795,7 @@ bool DataArrayDouble::isEqualWithoutConsideringStr(const DataArrayDouble& other, void DataArrayDouble::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception) { checkAllocated(); - _mem.reAlloc((int)(_info_on_compo.size())*nbOfTuples); - _nb_of_tuples=nbOfTuples; + _mem.reAlloc(getNumberOfComponents()*nbOfTuples); declareAsNew(); } @@ -1140,7 +1121,6 @@ void DataArrayDouble::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception int nbOfElems=getNbOfElems(); if(nbOfElems%newNbOfCompo!=0) throw INTERP_KERNEL::Exception("DataArrayDouble::rearrange : nbOfElems%newNbOfCompo!=0 !"); - _nb_of_tuples=nbOfElems/newNbOfCompo; _info_on_compo.clear(); _info_on_compo.resize(newNbOfCompo); declareAsNew(); @@ -1680,7 +1660,6 @@ void DataArrayDouble::SetArrayIn(DataArrayDouble *newArray, DataArrayDouble* &ar void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) { - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); declareAsNew(); @@ -1688,7 +1667,6 @@ void DataArrayDouble::useArray(const double *array, bool ownership, DeallocType void DataArrayDouble::useExternalArrayWithRWAccess(const double *array, int nbOfTuple, int nbOfCompo) { - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); declareAsNew(); @@ -3524,10 +3502,6 @@ void DataArrayInt::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) else if(nbCompo==0) { _mem.reserve(nbOfElems); - if(_nb_of_tuples==-1) - _nb_of_tuples=0; - else - _nb_of_tuples=std::min(_nb_of_tuples,nbOfElems); _info_on_compo.resize(1); } else @@ -3537,10 +3511,7 @@ void DataArrayInt::reserve(int nbOfElems) throw(INTERP_KERNEL::Exception) void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) - { - _mem.pushBack(val); - _nb_of_tuples++; - } + _mem.pushBack(val); else throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !"); } @@ -3548,11 +3519,7 @@ void DataArrayInt::pushBackSilent(int val) throw(INTERP_KERNEL::Exception) int DataArrayInt::popBackSilent() throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()==1) - { - int ret=_mem.popBack(); - _nb_of_tuples--; - return ret; - } + return _mem.popBack(); else throw INTERP_KERNEL::Exception("DataArrayInt::pushBackSilent : not available for DataArrayInt with number of components different than 1 !"); } @@ -3577,9 +3544,8 @@ void DataArrayInt::alloc(int nbOfTuple, int nbOfCompo) throw(INTERP_KERNEL::Exce { if(nbOfTuple<0 || nbOfCompo<0) throw INTERP_KERNEL::Exception("DataArrayInt::alloc : request for negative length of data !"); - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); - _mem.alloc(nbOfCompo*_nb_of_tuples); + _mem.alloc(nbOfCompo*nbOfTuple); declareAsNew(); } @@ -3958,7 +3924,6 @@ DataArrayInt *DataArrayInt::buildPermutationArr(const DataArrayInt& other) const void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo) { - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); _mem.useArray(array,ownership,type,nbOfTuple*nbOfCompo); declareAsNew(); @@ -3966,7 +3931,6 @@ void DataArrayInt::useArray(const int *array, bool ownership, DeallocType type, void DataArrayInt::useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo) { - _nb_of_tuples=nbOfTuple; _info_on_compo.resize(nbOfCompo); _mem.useExternalArrayWithRWAccess(array,nbOfTuple*nbOfCompo); declareAsNew(); @@ -4454,7 +4418,6 @@ void DataArrayInt::rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception) int nbOfElems=getNbOfElems(); if(nbOfElems%newNbOfCompo!=0) throw INTERP_KERNEL::Exception("DataArrayInt::rearrange : nbOfElems%newNbOfCompo!=0 !"); - _nb_of_tuples=nbOfElems/newNbOfCompo; _info_on_compo.clear(); _info_on_compo.resize(newNbOfCompo); declareAsNew(); @@ -4505,8 +4468,7 @@ DataArrayInt *DataArrayInt::changeNbOfComponents(int newNbOfComp, int dftValue) void DataArrayInt::reAlloc(int nbOfTuples) throw(INTERP_KERNEL::Exception) { checkAllocated(); - _mem.reAlloc((int)_info_on_compo.size()*nbOfTuples); - _nb_of_tuples=nbOfTuples; + _mem.reAlloc(getNumberOfComponents()*nbOfTuples); declareAsNew(); } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index dbe0cc4d6..2ab3f47ee 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -117,8 +117,8 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::string getUnitOnComponent(int i) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void setInfoOnComponent(int i, const char *info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfComponents() const { return (int)_info_on_compo.size(); } - MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; } - MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*_nb_of_tuples; } + MEDCOUPLING_EXPORT virtual int getNumberOfTuples() const = 0; + MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*getNumberOfTuples(); } MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -131,13 +131,12 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const = 0; protected: - DataArray():_nb_of_tuples(-1) { } + DataArray() { } protected: static void CheckValueInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception); static void CheckValueInRangeEx(int value, int start, int end, const char *msg) throw(INTERP_KERNEL::Exception); static void CheckClosingParInRange(int ref, int value, const char *msg) throw(INTERP_KERNEL::Exception); protected: - int _nb_of_tuples; std::string _name; std::vector _info_on_compo; }; @@ -155,6 +154,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayDouble *New(); MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT double doubleValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool empty() const throw(INTERP_KERNEL::Exception); @@ -353,6 +353,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT static DataArrayInt *New(); MEDCOUPLING_EXPORT bool isAllocated() const; MEDCOUPLING_EXPORT void checkAllocated() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _info_on_compo.empty()?0:_mem.getNbOfElem()/getNumberOfComponents(); } MEDCOUPLING_EXPORT void setInfoAndChangeNbOfCompo(const std::vector& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int intValue() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getHashCode() const throw(INTERP_KERNEL::Exception); @@ -489,7 +490,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT std::vector partitionByDifferentValues(std::vector& differentIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo); - MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _nb_of_tuples=std::max(_nb_of_tuples,id+sizeOfOthers+1); _mem.writeOnPlace(id,element0,others,sizeOfOthers); } + MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } MEDCOUPLING_EXPORT static DataArrayInt *Add(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void addEqual(const DataArrayInt *other) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static DataArrayInt *Substract(const DataArrayInt *a1, const DataArrayInt *a2) throw(INTERP_KERNEL::Exception);