X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArrayChar.cxx;h=3acb7faf17d30e8e73382c7df4b125519854f588;hb=b607ffc713080a567fb90595118069ac18181e99;hp=08316a81e65429e14a2ae731f81266615e6813eb;hpb=f2690dd9bd062d8727817a86abc53237357187ed;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx old mode 100644 new mode 100755 index 08316a81e..3acb7faf1 --- a/src/MEDCoupling/MEDCouplingMemArrayChar.cxx +++ b/src/MEDCoupling/MEDCouplingMemArrayChar.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 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 @@ -35,23 +35,23 @@ template class MEDCoupling::DataArrayTemplate; /*! * Returns an integer value characterizing \a this array, which is useful for a quick - * comparison of many instances of DataArrayInt. - * \return int - the hash value. + * comparison of many instances of DataArrayChar. + * \return mcIdType - the hash value. * \throw If \a this is not allocated. */ -int DataArrayChar::getHashCode() const +mcIdType DataArrayChar::getHashCode() const { checkAllocated(); std::size_t nbOfElems=getNbOfElems(); - int ret=nbOfElems*65536; - int delta=3; + std::size_t ret=nbOfElems*65536; + std::size_t delta=3; if(nbOfElems>48) delta=nbOfElems/8; - int ret0=0; + mcIdType ret0=0; const char *pt=begin(); for(std::size_t i=0;icheckAllocated(); - int nbOfTuples=getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(); if(nbOfTuples!=other->getNumberOfTuples()) throw INTERP_KERNEL::Exception("DataArrayChar::meldWith : mismatch of number of tuples !"); - int nbOfComp1=getNumberOfComponents(); - int nbOfComp2=other->getNumberOfComponents(); + std::size_t nbOfComp1=getNumberOfComponents(); + std::size_t nbOfComp2=other->getNumberOfComponents(); char *newArr=(char *)malloc(nbOfTuples*(nbOfComp1+nbOfComp2)*sizeof(char)); char *w=newArr; const char *inp1=getConstPointer(); const char *inp2=other->getConstPointer(); - for(int i=0;i compIds(nbOfComp2); - for(int i=0;i compIds(nbOfComp2); + for(std::size_t i=0;igetNumberOfComponents() != 1. */ -DataArrayInt *DataArrayChar::findIdsEqual(char val) const +DataArrayIdType *DataArrayChar::findIdsEqual(char val) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayChar::findIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); const char *cptr=getConstPointer(); - MCAuto ret(DataArrayInt::New()); ret->alloc(0,1); - int nbOfTuples=getNumberOfTuples(); - for(int i=0;i ret(DataArrayIdType::New()); ret->alloc(0,1); + mcIdType nbOfTuples=getNumberOfTuples(); + for(mcIdType i=0;ipushBackSilent(i); return ret.retn(); } /*! - * Creates a new DataArrayChar containing IDs (indices) of tuples holding value \b not + * Creates a new DataArrayIdType containing IDs (indices) of tuples holding value \b not * equal to a given one. * \param [in] val - the value to ignore within \a this. * \return DataArrayChar * - a new instance of DataArrayChar. The caller is to delete this @@ -224,15 +224,15 @@ DataArrayInt *DataArrayChar::findIdsEqual(char val) const * \throw If \a this is not allocated. * \throw If \a this->getNumberOfComponents() != 1. */ -DataArrayInt *DataArrayChar::findIdsNotEqual(char val) const +DataArrayIdType *DataArrayChar::findIdsNotEqual(char val) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayChar::findIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !"); const char *cptr=getConstPointer(); - MCAuto ret(DataArrayInt::New()); ret->alloc(0,1); - int nbOfTuples=getNumberOfTuples(); - for(int i=0;i ret(DataArrayIdType::New()); ret->alloc(0,1); + mcIdType nbOfTuples=getNumberOfTuples(); + for(mcIdType i=0;ipushBackSilent(i); return ret.retn(); @@ -244,17 +244,16 @@ DataArrayInt *DataArrayChar::findIdsNotEqual(char val) const * This method differs from DataArrayChar::findIdFirstEqualTuple in that the position is internal raw data is not considered here contrary to DataArrayChar::findIdFirstEqualTuple. * \sa DataArrayChar::findIdFirstEqualTuple */ -int DataArrayChar::findIdSequence(const std::vector& vals) const +mcIdType DataArrayChar::findIdSequence(const std::vector& vals) const { checkAllocated(); - int nbOfCompo=getNumberOfComponents(); - if(nbOfCompo!=1) + if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayChar::findIdSequence : works only for DataArrayChar instance with one component !"); const char *cptr=getConstPointer(); std::size_t nbOfVals=getNbOfElems(); const char *loc=std::search(cptr,cptr+nbOfVals,vals.begin(),vals.end()); if(loc!=cptr+nbOfVals) - return std::distance(cptr,loc); + return ToIdType(std::distance(cptr,loc)); return -1; } @@ -270,13 +269,13 @@ int DataArrayChar::findIdSequence(const std::vector& vals) const * \return tuple id where \b tupl is. -1 if no such tuple exists in \b this. * \sa DataArrayChar::findIdSequence. */ -int DataArrayChar::findIdFirstEqualTuple(const std::vector& tupl) const +mcIdType DataArrayChar::findIdFirstEqualTuple(const std::vector& tupl) const { checkAllocated(); - int nbOfCompo=getNumberOfComponents(); + std::size_t nbOfCompo=getNumberOfComponents(); if(nbOfCompo==0) throw INTERP_KERNEL::Exception("DataArrayChar::findIdFirstEqualTuple : 0 components in 'this' !"); - if(nbOfCompo!=(int)tupl.size()) + if(nbOfCompo!=tupl.size()) { std::ostringstream oss; oss << "DataArrayChar::findIdFirstEqualTuple : 'this' contains " << nbOfCompo << " components and searching for a tuple of length " << tupl.size() << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -291,7 +290,7 @@ int DataArrayChar::findIdFirstEqualTuple(const std::vector& tupl) const if(std::distance(cptr,work)%nbOfCompo!=0) work++; else - return std::distance(cptr,work)/nbOfCompo; + return ToIdType(std::distance(cptr,work)/nbOfCompo); } } return -1; @@ -340,16 +339,16 @@ bool DataArrayChar::presenceOfValue(const std::vector& vals) const * If not any tuple contains \b value -1 is returned. * \sa DataArrayChar::presenceOfValue */ -int DataArrayChar::findIdFirstEqual(char value) const +mcIdType DataArrayChar::findIdFirstEqual(char value) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayChar::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); const char *cptr=getConstPointer(); - int nbOfTuples=getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(); const char *ret=std::find(cptr,cptr+nbOfTuples,value); if(ret!=cptr+nbOfTuples) - return std::distance(cptr,ret); + return ToIdType(std::distance(cptr,ret)); return -1; } @@ -359,17 +358,17 @@ int DataArrayChar::findIdFirstEqual(char value) const * If not any tuple contains one of the values contained in 'vals' false is returned. * \sa DataArrayChar::presenceOfValue */ -int DataArrayChar::findIdFirstEqual(const std::vector& vals) const +mcIdType DataArrayChar::findIdFirstEqual(const std::vector& vals) const { checkAllocated(); if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::presenceOfValue : the array must have only one component, you can call 'rearrange' method before !"); + throw INTERP_KERNEL::Exception("DataArrayChar::findIdFirstEqual : the array must have only one component, you can call 'rearrange' method before !"); std::set vals2(vals.begin(),vals.end()); const char *cptr=getConstPointer(); - int nbOfTuples=getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(); for(const char *w=cptr;w!=cptr+nbOfTuples;w++) if(vals2.find(*w)!=vals2.end()) - return std::distance(cptr,w); + return ToIdType(std::distance(cptr,w)); return -1; } @@ -382,15 +381,15 @@ int DataArrayChar::findIdFirstEqual(const std::vector& vals) const * \param [in] vmax end of range. This value is \b not included in range. * \return a newly allocated data array that the caller should deal with. */ -DataArrayInt *DataArrayChar::findIdsInRange(char vmin, char vmax) const +DataArrayIdType *DataArrayChar::findIdsInRange(char vmin, char vmax) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayChar::findIdsInRange : this must have exactly one component !"); const char *cptr=getConstPointer(); - MCAuto ret=DataArrayInt::New(); ret->alloc(0,1); - int nbOfTuples=getNumberOfTuples(); - for(int i=0;i ret=DataArrayIdType::New(); ret->alloc(0,1); + mcIdType nbOfTuples=getNumberOfTuples(); + for(mcIdType i=0;i=vmin && *cptrpushBackSilent(i); return ret.retn(); @@ -444,8 +443,8 @@ DataArrayChar *DataArrayChar::Aggregate(const std::vector throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : input list must be NON EMPTY !"); std::vector::const_iterator it=a.begin(); std::size_t nbOfComp((*it)->getNumberOfComponents()); - int nbt=(*it++)->getNumberOfTuples(); - for(int i=1;it!=a.end();it++,i++) + mcIdType nbt=(*it++)->getNumberOfTuples(); + for(;it!=a.end();it++) { if((*it)->getNumberOfComponents()!=nbOfComp) throw INTERP_KERNEL::Exception("DataArrayChar::Aggregate : Nb of components mismatch for array aggregation !"); @@ -510,31 +509,31 @@ DataArrayChar *DataArrayChar::Meld(const std::vector& arr for(it=a.begin();it!=a.end();it++) (*it)->checkAllocated(); it=a.begin(); - int nbOfTuples=(*it)->getNumberOfTuples(); - std::vector nbc(a.size()); + mcIdType nbOfTuples=(*it)->getNumberOfTuples(); + std::vector nbc(a.size()); std::vector pts(a.size()); nbc[0]=(*it)->getNumberOfComponents(); pts[0]=(*it++)->getConstPointer(); - for(int i=1;it!=a.end();it++,i++) + for(std::size_t i=1;it!=a.end();it++,i++) { if(nbOfTuples!=(*it)->getNumberOfTuples()) throw INTERP_KERNEL::Exception("DataArrayChar::meld : mismatch of number of tuples !"); nbc[i]=(*it)->getNumberOfComponents(); pts[i]=(*it)->getConstPointer(); } - int totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),0); + std::size_t totalNbOfComp=std::accumulate(nbc.begin(),nbc.end(),(std::size_t)0); DataArrayChar *ret=a[0]->buildEmptySpecializedDAChar(); ret->alloc(nbOfTuples,totalNbOfComp); char *retPtr=ret->getPointer(); - for(int i=0;isetInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } @@ -622,12 +621,12 @@ void DataArrayByte::reprZipStream(std::ostream& stream) const void DataArrayByte::reprWithoutNameStream(std::ostream& stream) const { DataArray::reprWithoutNameStream(stream); - if(_mem.reprHeader(getNumberOfComponents(),stream)) + if(_mem.reprHeader(ToIdType(getNumberOfComponents()),stream)) { const char *data=begin(); - int nbOfTuples=getNumberOfTuples(); - int nbCompo=getNumberOfComponents(); - for(int i=0;i(stream," "));//it is not a bug int here not char because it is not ASCII here contrary to DataArrayAsciiChar @@ -639,12 +638,13 @@ void DataArrayByte::reprWithoutNameStream(std::ostream& stream) const void DataArrayByte::reprZipWithoutNameStream(std::ostream& stream) const { DataArray::reprWithoutNameStream(stream); - _mem.reprZip(getNumberOfComponents(),stream); + _mem.reprZip(ToIdType(getNumberOfComponents()),stream); } void DataArrayByte::reprCppStream(const std::string& varName, std::ostream& stream) const { - int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + mcIdType nbTuples=getNumberOfTuples(); + std::size_t nbComp=getNumberOfComponents(); const char *data=getConstPointer(); stream << "DataArrayByte *" << varName << "=DataArrayByte::New();" << std::endl; if(nbTuples*nbComp>=1) @@ -668,10 +668,10 @@ void DataArrayByte::reprQuickOverview(std::ostream& stream) const stream << "DataArrayByte C++ instance at " << this << ". "; if(isAllocated()) { - int nbOfCompo=(int)_info_on_compo.size(); + std::size_t nbOfCompo=_info_on_compo.size(); if(nbOfCompo>=1) { - int nbOfTuples=getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); } @@ -685,17 +685,17 @@ void DataArrayByte::reprQuickOverview(std::ostream& stream) const void DataArrayByte::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const { const char *data=begin(); - int nbOfTuples=getNumberOfTuples(); - int nbOfCompo=(int)_info_on_compo.size(); + mcIdType nbOfTuples=getNumberOfTuples(); + std::size_t nbOfCompo=_info_on_compo.size(); std::ostringstream oss2; oss2 << "["; std::string oss2Str(oss2.str()); bool isFinished=true; - for(int i=0;i1) { oss2 << "("; - for(int j=0;j DataArrayByte::toVectorOfBool() const checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayByte::toVectorOfBool : this method can be used only if this has one component !"); - int nbt(getNumberOfTuples()); + mcIdType nbt(getNumberOfTuples()); std::vector ret(nbt,false); const char *pt(begin()); - for(int i=0;i_nb_of_elem and \bnbOfTuples==1 or * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem. */ -DataArrayByte *DataArrayByteTuple::buildDAByte(int nbOfTuples, int nbOfCompo) const +DataArrayByte *DataArrayByteTuple::buildDAByte(std::size_t nbOfTuples, std::size_t nbOfCompo) const { if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) { @@ -845,7 +845,7 @@ DataArrayAsciiChar::DataArrayAsciiChar(const std::string& st) { std::size_t lgth=st.length(); if(lgth==0) - throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with string ! Size of input string is null !"); + throw INTERP_KERNEL::Exception("DataArrayAsciiChar constructor with string ! Size of input string is null !"); alloc(1,lgth); std::copy(st.begin(),st.begin()+lgth,getPointer()); } @@ -882,16 +882,16 @@ DataArrayAsciiChar *DataArrayAsciiChar::New(const std::vector& vst, DataArrayAsciiChar::DataArrayAsciiChar(const std::vector& vst, char defaultChar) { if(vst.empty()) - throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with vector of strings ! Empty array !"); + throw INTERP_KERNEL::Exception("DataArrayAsciiChar constructor with vector of strings ! Empty array !"); std::size_t nbCompo=0; for(std::vector::const_iterator it=vst.begin();it!=vst.end();it++) nbCompo=std::max(nbCompo,(*it).length()); if(nbCompo==0) - throw INTERP_KERNEL::Exception("DataArrayAsciiChar contructor with vector of strings ! All strings in not empty vector are empty !"); - int nbTuples=(int)vst.size(); - alloc(nbTuples,(int)nbCompo); + throw INTERP_KERNEL::Exception("DataArrayAsciiChar constructor with vector of strings ! All strings in not empty vector are empty !"); + std::size_t nbTuples=vst.size(); + alloc(nbTuples,nbCompo); char *pt=getPointer(); - for(int i=0;i(stream)); @@ -995,7 +995,8 @@ void DataArrayAsciiChar::reprZipWithoutNameStream(std::ostream& stream) const void DataArrayAsciiChar::reprCppStream(const std::string& varName, std::ostream& stream) const { - int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + mcIdType nbTuples=getNumberOfTuples(); + std::size_t nbComp=getNumberOfComponents(); const char *data=getConstPointer(); stream << "DataArrayAsciiChar *" << varName << "=DataArrayAsciiChar::New();" << std::endl; if(nbTuples*nbComp>=1) @@ -1019,10 +1020,10 @@ void DataArrayAsciiChar::reprQuickOverview(std::ostream& stream) const stream << "DataArrayAsciiChar C++ instance at " << this << ". "; if(isAllocated()) { - int nbOfCompo=(int)_info_on_compo.size(); + std::size_t nbOfCompo=_info_on_compo.size(); if(nbOfCompo>=1) { - int nbOfTuples=getNumberOfTuples(); + mcIdType nbOfTuples=getNumberOfTuples(); stream << "Number of tuples : " << nbOfTuples << ". Number of components : " << nbOfCompo << "." << std::endl; reprQuickOverviewData(stream,MAX_NB_OF_BYTE_IN_REPR); } @@ -1036,27 +1037,27 @@ void DataArrayAsciiChar::reprQuickOverview(std::ostream& stream) const void DataArrayAsciiChar::reprQuickOverviewData(std::ostream& stream, std::size_t maxNbOfByteInRepr) const { const char *data=begin(); - int nbOfTuples=getNumberOfTuples(); - int nbOfCompo=(int)_info_on_compo.size(); + mcIdType nbOfTuples=getNumberOfTuples(); + std::size_t nbOfCompo=_info_on_compo.size(); std::ostringstream oss2; oss2 << "["; std::string oss2Str(oss2.str()); bool isFinished=true; - for(int i=0;i_nb_of_elem and \bnbOfTuples==1 or * \b nbOfCompo=1 and \bnbOfTuples==this->_nb_of_elem. */ -DataArrayAsciiChar *DataArrayAsciiCharTuple::buildDAAsciiChar(int nbOfTuples, int nbOfCompo) const +DataArrayAsciiChar *DataArrayAsciiCharTuple::buildDAAsciiChar(std::size_t nbOfTuples, std::size_t nbOfCompo) const { if((_nb_of_compo==nbOfCompo && nbOfTuples==1) || (_nb_of_compo==nbOfTuples && nbOfCompo==1)) {