X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling%2FMEDCouplingMemArray.cxx;h=0d5d059a04685eb0884cd269f8348c7107558110;hb=0c9d48870957c4a9f6f82fc8e2c569780a5f886b;hp=88390fc3aff06eaee63d1a270f2c807e6b1c593e;hpb=e6f4a73d64d6b6bfcaad1dd6e17e81fce39d60ed;p=modules%2Fmed.git diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index 88390fc3a..0d5d059a0 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -130,7 +130,7 @@ std::vector DataArray::getDirectChildren() const * See \ref MEDCouplingArrayBasicsName "DataArrays infos" for more information. * \param [in] name - new array name */ -void DataArray::setName(const char *name) +void DataArray::setName(const std::string& name) { _name=name; } @@ -164,7 +164,7 @@ void DataArray::copyPartOfStringInfoFrom(const DataArray& other, const std::vect throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i& compoIds, const DataArray& other) @@ -180,7 +180,7 @@ void DataArray::copyPartOfStringInfoFrom2(const std::vector& compoIds, cons throw INTERP_KERNEL::Exception(oss.str().c_str()); } for(std::size_t i=0;i& arrs) * \param [in] info - the string containing the information. * \throw If \a i is not a valid component index. */ -void DataArray::setInfoOnComponent(int i, const char *info) +void DataArray::setInfoOnComponent(int i, const std::string& info) { if(i<(int)_info_on_compo.size() && i>=0) _info_on_compo[i]=info; @@ -516,7 +516,7 @@ void DataArray::setInfoAndChangeNbOfCompo(const std::vector& info) _info_on_compo=info; } -void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const +void DataArray::checkNbOfTuples(int nbOfTuples, const std::string& msg) const { if(getNumberOfTuples()!=nbOfTuples) { @@ -525,7 +525,7 @@ void DataArray::checkNbOfTuples(int nbOfTuples, const char *msg) const } } -void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const +void DataArray::checkNbOfComps(int nbOfCompo, const std::string& msg) const { if(getNumberOfComponents()!=nbOfCompo) { @@ -534,7 +534,7 @@ void DataArray::checkNbOfComps(int nbOfCompo, const char *msg) const } } -void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const +void DataArray::checkNbOfElems(std::size_t nbOfElems, const std::string& msg) const { if(getNbOfElems()!=nbOfElems) { @@ -543,7 +543,7 @@ void DataArray::checkNbOfElems(std::size_t nbOfElems, const char *msg) const } } -void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const +void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const std::string& msg) const { if(getNumberOfTuples()!=other.getNumberOfTuples()) { @@ -557,7 +557,7 @@ void DataArray::checkNbOfTuplesAndComp(const DataArray& other, const char *msg) } } -void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const +void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const std::string& msg) const { checkNbOfTuples(nbOfTuples,msg); checkNbOfComps(nbOfCompo,msg); @@ -566,7 +566,7 @@ void DataArray::checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char /*! * Simply this method checks that \b value is in [0,\b ref). */ -void DataArray::CheckValueInRange(int ref, int value, const char *msg) +void DataArray::CheckValueInRange(int ref, int value, const std::string& msg) { if(value<0 || value>=ref) { @@ -579,7 +579,7 @@ void DataArray::CheckValueInRange(int ref, int value, const char *msg) * 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) +void DataArray::CheckValueInRangeEx(int value, int start, int end, const std::string& msg) { if(start<0 || start>=value) { @@ -596,7 +596,7 @@ void DataArray::CheckValueInRangeEx(int value, int start, int end, const char *m } } -void DataArray::CheckClosingParInRange(int ref, int value, const char *msg) +void DataArray::CheckClosingParInRange(int ref, int value, const std::string& msg) { if(value<0 || value>ref) { @@ -644,7 +644,7 @@ void DataArray::GetSlice(int start, int stop, int step, int sliceId, int nbOfSli stopSlice=stop; } -int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const char *msg) +int DataArray::GetNumberOfItemGivenBES(int begin, int end, int step, const std::string& msg) { if(endsetName(getName().c_str()); + ret->setName(getName()); for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); - ret->setName(getName().c_str()); + ret->setInfoOnComponent(i,getInfoOnComponent(i)); + ret->setName(getName()); return ret.retn(); } @@ -3536,7 +3536,7 @@ DataArrayDouble *DataArrayDouble::fromCylToCart() const w[1]=wIn[0]*sin(wIn[1]); w[2]=wIn[2]; } - ret->setInfoOnComponent(2,getInfoOnComponent(2).c_str()); + ret->setInfoOnComponent(2,getInfoOnComponent(2)); return ret; } @@ -4276,7 +4276,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, FunctionToEvaluate fun * \throw If \a this is not allocated. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4330,7 +4330,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(int nbOfComp, const char *func) cons * \throw If \a this is not allocated. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc(const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4376,7 +4376,7 @@ DataArrayDouble *DataArrayDouble::applyFunc(const char *func) const * \throw If \a func contains vars that are not in \a this->getInfoOnComponent(). * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4432,7 +4432,7 @@ DataArrayDouble *DataArrayDouble::applyFunc2(int nbOfComp, const char *func) con * \throw If \a func contains vars not in \a varsOrder. * \throw If computing \a func fails. */ -DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const char *func) const +DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vector& varsOrder, const std::string& func) const { checkAllocated(); INTERP_KERNEL::ExprParser expr(func); @@ -4472,7 +4472,7 @@ DataArrayDouble *DataArrayDouble::applyFunc3(int nbOfComp, const std::vectorsetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } @@ -4747,8 +4749,8 @@ DataArrayDouble *DataArrayDouble::Dot(const DataArrayDouble *a1, const DataArray sum+=a1Ptr[i*nbOfComp+j]*a2Ptr[i*nbOfComp+j]; retPtr[i]=sum; } - ret->setInfoOnComponent(0,a1->getInfoOnComponent(0).c_str()); - ret->setName(a1->getName().c_str()); + ret->setInfoOnComponent(0,a1->getInfoOnComponent(0)); + ret->setName(a1->getName()); return ret; } @@ -5603,12 +5605,12 @@ bool DataArrayDouble::resizeForUnserialization(const std::vector& tinyInfoI */ void DataArrayDouble::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS) { - setName(tinyInfoS[0].c_str()); + setName(tinyInfoS[0]); if(isAllocated()) { int nbOfCompo=getNumberOfComponents(); for(int i=0;isetName(getName().c_str()); + ret->setName(getName()); for(int i=0;isetInfoOnComponent(i,getInfoOnComponent(i).c_str()); - ret->setName(getName().c_str()); + ret->setInfoOnComponent(i,getInfoOnComponent(i)); + ret->setName(getName()); return ret.retn(); } @@ -8393,13 +8395,14 @@ DataArrayIntIterator *DataArrayInt::iterator() * array using decrRef() as it is no more needed. * \throw If \a this is not allocated. * \throw If \a this->getNumberOfComponents() != 1. + * \sa DataArrayInt::getIdsEqualTuple */ DataArrayInt *DataArrayInt::getIdsEqual(int val) const { checkAllocated(); if(getNumberOfComponents()!=1) throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); - const int *cptr=getConstPointer(); + const int *cptr(getConstPointer()); MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;i ret(DataArrayInt::New()); ret->alloc(0,1); int nbOfTuples=getNumberOfTuples(); for(int i=0;igetNumberOfComponents() != std::distance(tupleBg,tupleEnd). + * \throw If \a this->getNumberOfComponents() is equal to 0. + * \sa DataArrayInt::getIdsEqual + */ +DataArrayInt *DataArrayInt::getIdsEqualTuple(const int *tupleBg, const int *tupleEnd) const +{ + std::size_t nbOfCompoExp(std::distance(tupleBg,tupleEnd)); + checkAllocated(); + if(getNumberOfComponents()!=(int)nbOfCompoExp) + { + std::ostringstream oss; oss << "DataArrayInt::getIdsEqualTuple : mismatch of number of components. Input tuple has " << nbOfCompoExp << " whereas this array has " << getNumberOfComponents() << " components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(nbOfCompoExp==0) + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualTuple : number of components should be > 0 !"); + MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); ret->alloc(0,1); + const int *bg(begin()),*end2(end()),*work(begin()); + while(work!=end2) + { + work=std::search(work,end2,tupleBg,tupleEnd); + if(work!=end2) + { + std::size_t pos(std::distance(bg,work)); + if(pos%nbOfCompoExp==0) + ret->pushBackSilent(pos/nbOfCompoExp); + work++; + } + } + return ret.retn(); +} /*! * Assigns \a newValue to all elements holding \a oldValue within \a this @@ -8800,6 +8842,8 @@ DataArrayInt *DataArrayInt::Aggregate(const DataArrayInt *a1, const DataArrayInt * the number of component in the result array is same as that of each of given arrays. * Info on components is copied from the first of the given arrays. Number of components * in the given arrays must be the same. + * If the number of non null of elements in \a arr is equal to one the returned object is a copy of it + * not the object itself. * \param [in] arr - a sequence of arrays to include in the result array. * \return DataArrayInt * - the new instance of DataArrayInt. * The caller is to delete this result array using decrRef() as it is no more @@ -9363,7 +9407,7 @@ DataArrayInt *DataArrayInt::Meld(const std::vector& arr) int k=0; for(int i=0;i<(int)a.size();i++) for(int j=0;jsetInfoOnComponent(k,a[i]->getInfoOnComponent(j).c_str()); + ret->setInfoOnComponent(k,a[i]->getInfoOnComponent(j)); return ret; } @@ -11148,12 +11192,12 @@ bool DataArrayInt::resizeForUnserialization(const std::vector& tinyInfoI) */ void DataArrayInt::finishUnserialization(const std::vector& tinyInfoI, const std::vector& tinyInfoS) { - setName(tinyInfoS[0].c_str()); + setName(tinyInfoS[0]); if(isAllocated()) { int nbOfCompo=tinyInfoI[1]; for(int i=0;i