From 6a928b57f9c8ec58a699c721abfbb20bc5026736 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 18 Apr 2016 19:34:40 -0400 Subject: [PATCH] Replace getValue with std::map.at where possible Deprecate the two-argument version of getValue, since the C++11 at method does the same thing. --- include/cantera/base/utilities.h | 3 +++ src/thermo/GeneralSpeciesThermo.cpp | 8 ++++---- src/thermo/Phase.cpp | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/cantera/base/utilities.h b/include/cantera/base/utilities.h index 3490a8705..1f0b00758 100644 --- a/include/cantera/base/utilities.h +++ b/include/cantera/base/utilities.h @@ -526,9 +526,12 @@ void checkFinite(const std::string& name, double* values, size_t N); * This is a const alternative to operator[]. Roughly equivalent to the 'at' * member function introduced in C++11. Throws std::out_of_range if the key * does not exist. + * @deprecated Use `map.at(key)` instead. To be removed after Cantera 2.3. */ template const U& getValue(const std::map& m, const T& key) { + warn_deprecated("getValue(map, key)", + "Use map.at(key) instead. To be removed after Cantera 2.3."); typename std::map::const_iterator iter = m.find(key); if (iter == m.end()) { throw std::out_of_range("std::map: key not found"); diff --git a/src/thermo/GeneralSpeciesThermo.cpp b/src/thermo/GeneralSpeciesThermo.cpp index 132cf24d6..1670613c5 100644 --- a/src/thermo/GeneralSpeciesThermo.cpp +++ b/src/thermo/GeneralSpeciesThermo.cpp @@ -219,8 +219,8 @@ doublereal GeneralSpeciesThermo::refPressure(size_t k) const SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k) { try { - const std::pair& loc = getValue(m_speciesLoc, k); - return getValue(m_sp, loc.first)[loc.second].second.get(); + const std::pair& loc = m_speciesLoc.at(k); + return m_sp.at(loc.first)[loc.second].second.get(); } catch (std::out_of_range&) { return 0; } @@ -229,8 +229,8 @@ SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k) const SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k) const { try { - const std::pair& loc = getValue(m_speciesLoc, k); - return getValue(m_sp, loc.first)[loc.second].second.get(); + const std::pair& loc = m_speciesLoc.at(k); + return m_sp.at(loc.first)[loc.second].second.get(); } catch (std::out_of_range&) { return 0; } diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index 59a4c8887..81b748071 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -368,7 +368,7 @@ void Phase::setMoleFractionsByName(const compositionMap& xMap) vector_fp mf(m_kk, 0.0); for (const auto& sp : xMap) { try { - mf[getValue(m_speciesIndices, sp.first)] = sp.second; + mf[m_speciesIndices.at(sp.first)] = sp.second; } catch (std::out_of_range&) { throw CanteraError("Phase::setMoleFractionsByName", "Unknown species '{}'", sp.first); @@ -412,7 +412,7 @@ void Phase::setMassFractionsByName(const compositionMap& yMap) vector_fp mf(m_kk, 0.0); for (const auto& sp : yMap) { try { - mf[getValue(m_speciesIndices, sp.first)] = sp.second; + mf[m_speciesIndices.at(sp.first)] = sp.second; } catch (std::out_of_range&) { throw CanteraError("Phase::setMassFractionsByName", "Unknown species '{}'", sp.first); @@ -858,7 +858,7 @@ void Phase::modifySpecies(size_t k, shared_ptr spec) shared_ptr Phase::species(const std::string& name) const { - return getValue(m_species, name); + return m_species.at(name); } shared_ptr Phase::species(size_t k) const