Skip to content

Commit 10800da

Browse files
committed
ParamParse: Find Entries under Prefix
Extend the "unused params" checks to find generally parameters under a given inputs prefix.
1 parent 25b08dc commit 10800da

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Src/Base/AMReX_ParmParse.H

+3
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ public:
935935
//! Returns unused [prefix.]* parameters.
936936
static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());
937937

938+
//! Returns [prefix.]* parameters.
939+
static std::vector<std::string> getEntries (const std::string& prefix = std::string());
940+
938941
struct PP_entry;
939942
typedef std::list<PP_entry> Table;
940943
static void appendTable(ParmParse::Table& tab);

Src/Base/AMReX_ParmParse.cpp

+24-9
Original file line numberDiff line numberDiff line change
@@ -1112,23 +1112,30 @@ ParmParse::hasUnusedInputs (const std::string& prefix)
11121112

11131113
static
11141114
void
1115-
get_unused_inputs(std::vector<std::string>& unused, const ParmParse::Table& table,
1116-
const std::string& prefix)
1115+
get_entries_under_prefix (std::vector<std::string>& found_entries,
1116+
const ParmParse::Table& table,
1117+
const std::string& prefix,
1118+
const bool only_unused = false,
1119+
const bool add_values = false)
11171120
{
11181121
const std::string prefixdot = prefix.empty() ? std::string() : prefix+".";
11191122
for (auto const& entry : table) {
1120-
if (! entry.m_queried) {
1123+
if ((! only_unused) || (only_unused && ! entry.m_queried)) {
11211124
if (entry.m_name.substr(0,prefixdot.size()) == prefixdot) {
1122-
std::string tmp(entry.m_name + " =");
1123-
for (auto const& v : entry.m_vals) {
1124-
tmp += " " + v;
1125+
std::string tmp(entry.m_name);
1126+
if (add_values) {
1127+
tmp.append(" =");
1128+
for (auto const& v : entry.m_vals) {
1129+
tmp += " " + v;
1130+
}
11251131
}
1126-
unused.emplace_back(std::move(tmp));
1132+
found_entries.emplace_back(std::move(tmp));
11271133
}
11281134
}
11291135

11301136
if (entry.m_table) {
1131-
get_unused_inputs(unused, table, prefix);
1137+
get_entries_under_prefix(found_entries, table, prefix,
1138+
only_unused, add_values);
11321139
}
11331140
}
11341141
}
@@ -1137,7 +1144,15 @@ std::vector<std::string>
11371144
ParmParse::getUnusedInputs (const std::string& prefix)
11381145
{
11391146
std::vector<std::string> r;
1140-
get_unused_inputs(r, g_table, prefix);
1147+
get_entries_under_prefix(r, g_table, prefix, true, true);
1148+
return r;
1149+
}
1150+
1151+
std::vector<std::string>
1152+
ParmParse::getEntries (const std::string& prefix)
1153+
{
1154+
std::vector<std::string> r;
1155+
get_entries_under_prefix(r, g_table, prefix, false, false);
11411156
return r;
11421157
}
11431158

0 commit comments

Comments
 (0)