replace iterators with range based loops

This commit is contained in:
Arne Morten Kvarving 2024-04-14 22:22:20 +02:00
parent fee52d410a
commit ac909fefc4

View File

@ -352,23 +352,15 @@ inline void getFlattenedKeyList_(std::list<std::string>& dest,
const std::string& prefix) const std::string& prefix)
{ {
// add the keys of the current sub-structure // add the keys of the current sub-structure
auto keyIt = tree.getValueKeys().begin(); for (const auto& valueKey : tree.getValueKeys()) {
const auto& keyEndIt = tree.getValueKeys().end(); std::string newKey(prefix + valueKey);
for (; keyIt != keyEndIt; ++keyIt) {
std::string newKey(prefix);
newKey += *keyIt;
dest.push_back(newKey); dest.push_back(newKey);
} }
// recursively add all substructure keys // recursively add all substructure keys
auto subStructIt = tree.getSubKeys().begin(); for (const auto& subKey : tree.getSubKeys()) {
const auto& subStructEndIt = tree.getSubKeys().end(); std::string newPrefix(prefix + subKey + '.');
for (; subStructIt != subStructEndIt; ++subStructIt) { getFlattenedKeyList_(dest, tree.sub(subKey), newPrefix);
std::string newPrefix(prefix);
newPrefix += *subStructIt;
newPrefix += ".";
getFlattenedKeyList_(dest, tree.sub(*subStructIt), newPrefix);
} }
} }
@ -380,15 +372,13 @@ void printParamList_(std::ostream& os, const std::list<std::string>& keyList, bo
const Dune::ParameterTree& tree = ParamsMeta::tree(); const Dune::ParameterTree& tree = ParamsMeta::tree();
auto keyIt = keyList.begin(); for (const auto& key : keyList) {
const auto& keyEndIt = keyList.end(); const auto& paramInfo = ParamsMeta::registry().at(key);
for (; keyIt != keyEndIt; ++keyIt) {
const auto& paramInfo = ParamsMeta::registry().at(*keyIt);
const std::string& defaultValue = paramInfo.compileTimeValue; const std::string& defaultValue = paramInfo.compileTimeValue;
std::string value = defaultValue; std::string value = defaultValue;
if (tree.hasKey(*keyIt)) if (tree.hasKey(key))
value = tree.get(*keyIt, ""); value = tree.get(key, "");
os << *keyIt << "=\"" << value << "\""; os << key << "=\"" << value << "\"";
if (printDefaults) if (printDefaults)
os << " # default: \"" << defaultValue << "\""; os << " # default: \"" << defaultValue << "\"";
os << "\n"; os << "\n";
@ -764,30 +754,26 @@ void printValues(std::ostream& os = std::cout)
std::list<std::string> unknownKeyList; std::list<std::string> unknownKeyList;
getFlattenedKeyList_(runTimeAllKeyList, tree); getFlattenedKeyList_(runTimeAllKeyList, tree);
auto keyIt = runTimeAllKeyList.begin(); for (const auto& key : runTimeAllKeyList) {
const auto& keyEndIt = runTimeAllKeyList.end(); if (ParamsMeta::registry().find(key) == ParamsMeta::registry().end()) {
for (; keyIt != keyEndIt; ++keyIt) {
if (ParamsMeta::registry().find(*keyIt) == ParamsMeta::registry().end()) {
// key was not registered by the program! // key was not registered by the program!
unknownKeyList.push_back(*keyIt); unknownKeyList.push_back(key);
} }
else { else {
// the key was specified at run-time // the key was specified at run-time
runTimeKeyList.push_back(*keyIt); runTimeKeyList.push_back(key);
} }
} }
// loop over all registered parameters // loop over all registered parameters
std::list<std::string> compileTimeKeyList; std::list<std::string> compileTimeKeyList;
auto paramInfoIt = ParamsMeta::registry().begin(); for (const auto& reg : ParamsMeta::registry()) {
const auto& paramInfoEndIt = ParamsMeta::registry().end();
for (; paramInfoIt != paramInfoEndIt; ++paramInfoIt) {
// check whether the key was specified at run-time // check whether the key was specified at run-time
const auto& keyName = paramInfoIt->first; if (tree.hasKey(reg.first)) {
if (tree.hasKey(keyName))
continue; continue;
else } else {
compileTimeKeyList.push_back(keyName); compileTimeKeyList.push_back(reg.first);
}
} }
// report the values of all registered (and unregistered) // report the values of all registered (and unregistered)
@ -804,10 +790,8 @@ void printValues(std::ostream& os = std::cout)
if (unknownKeyList.size() > 0) { if (unknownKeyList.size() > 0) {
os << "# [unused run-time specified parameters]\n"; os << "# [unused run-time specified parameters]\n";
auto unusedKeyIt = unknownKeyList.begin(); for (const auto& unused : unknownKeyList) {
const auto& unusedKeyEndIt = unknownKeyList.end(); os << unused << "=\"" << tree.get(unused, "") << "\"\n" << std::flush;
for (; unusedKeyIt != unusedKeyEndIt; ++unusedKeyIt) {
os << *unusedKeyIt << "=\"" << tree.get(*unusedKeyIt, "") << "\"\n" << std::flush;
} }
} }
} }
@ -830,21 +814,17 @@ bool printUnused(std::ostream& os = std::cout)
std::list<std::string> unknownKeyList; std::list<std::string> unknownKeyList;
getFlattenedKeyList_(runTimeAllKeyList, tree); getFlattenedKeyList_(runTimeAllKeyList, tree);
auto keyIt = runTimeAllKeyList.begin(); for (const auto& key : runTimeAllKeyList) {
const auto& keyEndIt = runTimeAllKeyList.end(); if (ParamsMeta::registry().find(key) == ParamsMeta::registry().end()) {
for (; keyIt != keyEndIt; ++keyIt) {
if (ParamsMeta::registry().find(*keyIt) == ParamsMeta::registry().end()) {
// key was not registered by the program! // key was not registered by the program!
unknownKeyList.push_back(*keyIt); unknownKeyList.push_back(key);
} }
} }
if (unknownKeyList.size() > 0) { if (unknownKeyList.size() > 0) {
os << "# [unused run-time specified parameters]\n"; os << "# [unused run-time specified parameters]\n";
auto unusedKeyIt = unknownKeyList.begin(); for (const auto& unused : unknownKeyList) {
const auto& unusedKeyEndIt = unknownKeyList.end(); os << unused << "=\"" << tree.get(unused, "") << "\"\n" << std::flush;
for (; unusedKeyIt != unusedKeyEndIt; ++unusedKeyIt) {
os << *unusedKeyIt << "=\"" << tree.get(*unusedKeyIt, "") << "\"\n" << std::flush;
} }
return true; return true;
} }
@ -1044,10 +1024,9 @@ void endParamRegistration()
// loop over all parameters and retrieve their values to make sure // loop over all parameters and retrieve their values to make sure
// that there is no syntax error // that there is no syntax error
auto pIt = ParamsMeta::registrationFinalizers().begin(); for (const auto& param : ParamsMeta::registrationFinalizers()) {
const auto& pEndIt = ParamsMeta::registrationFinalizers().end(); param->retrieve();
for (; pIt != pEndIt; ++pIt) }
(*pIt)->retrieve();
ParamsMeta::registrationFinalizers().clear(); ParamsMeta::registrationFinalizers().clear();
} }
//! \endcond //! \endcond