X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/524de5f4ae0694f650b58ce80c901db748c9fe93..4bd1f48f0bf1ad1703be680ec2a38d626c6a2668:/src/xbt/config.cpp diff --git a/src/xbt/config.cpp b/src/xbt/config.cpp index f451949b43..d2f380be0c 100644 --- a/src/xbt/config.cpp +++ b/src/xbt/config.cpp @@ -51,10 +51,10 @@ const char* false_values[] = { static bool parseBool(const char* value) { - for (const char* true_value : true_values) + for (const char* const& true_value : true_values) if (std::strcmp(true_value, value) == 0) return true; - for (const char* false_value : false_values) + for (const char* const& false_value : false_values) if (std::strcmp(false_value, value) == 0) return false; throw std::range_error("not a boolean"); @@ -299,21 +299,23 @@ protected: Config::~Config() { XBT_DEBUG("Frees cfg set %p", this); - for (auto elm : options) + for (auto const& elm : options) delete elm.second; } inline ConfigurationElement* Config::getDictElement(const char* name) { - try { - return options.at(name); - } catch (std::out_of_range& unfound) { - try { - ConfigurationElement* res = aliases.at(name); + auto opt = options.find(name); + if (opt != options.end()) { + return opt->second; + } else { + auto als = aliases.find(name); + if (als != aliases.end()) { + ConfigurationElement* res = als->second; if (warn_for_aliases) XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->getKey().c_str()); return res; - } catch (std::out_of_range& missing_key) { + } else { throw simgrid::config::missing_key_error(std::string("Bad config key: ") + name); } } @@ -342,7 +344,7 @@ void Config::dump(const char *name, const char *indent) if (name) printf("%s>> Dumping of the config set '%s':\n", indent, name); - for (auto elm : options) + for (auto const& elm : options) printf("%s %s: ()%s) %s", indent, elm.first.c_str(), elm.second->getTypeName(), elm.second->getStringValue().c_str()); @@ -356,7 +358,7 @@ void Config::showAliases() { bool old_warn_for_aliases = false; std::swap(warn_for_aliases, old_warn_for_aliases); - for (auto elm : aliases) + for (auto const& elm : aliases) printf(" %s: %s\n", elm.first.c_str(), (*this)[elm.first.c_str()].getDescription().c_str()); std::swap(warn_for_aliases, old_warn_for_aliases); } @@ -364,7 +366,7 @@ void Config::showAliases() /** @brief Displays the declared options and their description */ void Config::help() { - for (auto elm : options) { + for (auto const& elm : options) { simgrid::config::ConfigurationElement* variable = this->options.at(elm.first); printf(" %s: %s\n", elm.first.c_str(), variable->getDescription().c_str()); printf(" Type: %s; ", variable->getTypeName());