X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDLoader%2FMEDFileFieldGlobs.cxx;h=af727fc7b717c457742d1e1625bbb5b8db6f714e;hb=88916ccf9c681624b682d10a62c1ee376324c946;hp=11a46ae5d47f2d512cbd49a757537d3636a3abbf;hpb=22a4bd76f2e2c06917d391a07efa1aa293b35177;p=tools%2Fmedcoupling.git diff --git a/src/MEDLoader/MEDFileFieldGlobs.cxx b/src/MEDLoader/MEDFileFieldGlobs.cxx index 11a46ae5d..af727fc7b 100644 --- a/src/MEDLoader/MEDFileFieldGlobs.cxx +++ b/src/MEDLoader/MEDFileFieldGlobs.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2019 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 @@ -375,9 +375,9 @@ namespace MEDCouplingImpl { public: PflFinder(const std::string& pfl):_pfl(pfl) { } - bool operator() (const MCAuto& pfl) { return _pfl==pfl->getName(); } + bool operator() (const MCAuto& loc) { return loc->getName()==_pfl; } private: - const std::string& _pfl; + const std::string _pfl; }; } /// @endcond @@ -395,21 +395,25 @@ int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const return std::distance(_locs.begin(),it); } -/*! - * The returned value is never null. - */ -const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const +int MEDFileFieldGlobs::getProfileId(const std::string& pfl) const { - std::string pflNameCpp(pflName); - std::vector< MCAuto >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp)); + std::vector< MCAuto >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pfl)); if(it==_pfls.end()) { - std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : "; + std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfileId : no such profile name : \"" << pfl << "\" Possible localizations are : "; for(it=_pfls.begin();it!=_pfls.end();it++) oss << "\"" << (*it)->getName() << "\", "; throw INTERP_KERNEL::Exception(oss.str()); } - return *it; + return std::distance(_pfls.begin(),it); +} + +/*! + * The returned value is never null. + */ +const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const +{ + return getProfileFromId(getProfileId(pflName)); } const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const @@ -432,7 +436,7 @@ MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) } /*! - * The returned value is never null. + * The returned value is never null. Borrowed reference returned. */ DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) { @@ -1039,6 +1043,17 @@ int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const return contentNotNull()->getLocalizationId(loc); } +/*! + * Returns an id of a profile by its name. + * \param [in] loc - the profile name of interest. + * \return int - the id of the profile. + * \throw If there is no a profile named \a loc. + */ +int MEDFileFieldGlobsReal::getProfileId(const std::string& pfl) const +{ + return contentNotNull()->getProfileId(pfl); +} + /*! * Returns the name of the MED file. * \return const std::string& - the MED file name. @@ -1119,7 +1134,7 @@ MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locNa /*! * Returns a profile array, apt for modification, by its name. * \param [in] pflName - the name of the profile of interest. - * \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName. + * \return DataArrayInt * - Borrowed reference - a non-const pointer to the profile array having the name \a pflName. * \throw If there is no a profile named \a pflName. */ DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) @@ -1130,7 +1145,7 @@ DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) /*! * Returns a profile array, apt for modification, by its id. * \param [in] pflId - the id of the profile of interest. - * \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId. + * \return DataArrayInt * - Borrowed reference - a non-const pointer to the profile array having the id \a pflId. * \throw If there is no a profile with id \a pflId. */ DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)