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