mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
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.
This commit is contained in:
@@ -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 <class T, class U>
|
||||
const U& getValue(const std::map<T, U>& m, const T& key) {
|
||||
warn_deprecated("getValue(map, key)",
|
||||
"Use map.at(key) instead. To be removed after Cantera 2.3.");
|
||||
typename std::map<T,U>::const_iterator iter = m.find(key);
|
||||
if (iter == m.end()) {
|
||||
throw std::out_of_range("std::map: key not found");
|
||||
|
||||
@@ -219,8 +219,8 @@ doublereal GeneralSpeciesThermo::refPressure(size_t k) const
|
||||
SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k)
|
||||
{
|
||||
try {
|
||||
const std::pair<int, size_t>& loc = getValue(m_speciesLoc, k);
|
||||
return getValue(m_sp, loc.first)[loc.second].second.get();
|
||||
const std::pair<int, size_t>& 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<int, size_t>& loc = getValue(m_speciesLoc, k);
|
||||
return getValue(m_sp, loc.first)[loc.second].second.get();
|
||||
const std::pair<int, size_t>& loc = m_speciesLoc.at(k);
|
||||
return m_sp.at(loc.first)[loc.second].second.get();
|
||||
} catch (std::out_of_range&) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -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<Species> spec)
|
||||
|
||||
shared_ptr<Species> Phase::species(const std::string& name) const
|
||||
{
|
||||
return getValue(m_species, name);
|
||||
return m_species.at(name);
|
||||
}
|
||||
|
||||
shared_ptr<Species> Phase::species(size_t k) const
|
||||
|
||||
Reference in New Issue
Block a user