Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParamParse: Find Entries under Prefix #2043

Merged
merged 2 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Src/Base/AMReX_ParmParse.H
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,9 @@ public:
//! Returns unused [prefix.]* parameters.
static std::vector<std::string> getUnusedInputs (const std::string& prefix = std::string());

//! Returns [prefix.]* parameters.
static std::vector<std::string> getEntries (const std::string& prefix = std::string());

struct PP_entry;
typedef std::list<PP_entry> Table;
static void appendTable(ParmParse::Table& tab);
Expand Down
33 changes: 24 additions & 9 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,23 +1112,30 @@ ParmParse::hasUnusedInputs (const std::string& prefix)

static
void
get_unused_inputs(std::vector<std::string>& unused, const ParmParse::Table& table,
const std::string& prefix)
get_entries_under_prefix (std::vector<std::string>& found_entries,
const ParmParse::Table& table,
const std::string& prefix,
const bool only_unused = false,
const bool add_values = false)
{
const std::string prefixdot = prefix.empty() ? std::string() : prefix+".";
for (auto const& entry : table) {
if (! entry.m_queried) {
if ((! only_unused) || (only_unused && ! entry.m_queried)) {
if (entry.m_name.substr(0,prefixdot.size()) == prefixdot) {
std::string tmp(entry.m_name + " =");
for (auto const& v : entry.m_vals) {
tmp += " " + v;
std::string tmp(entry.m_name);
if (add_values) {
tmp.append(" =");
for (auto const& v : entry.m_vals) {
tmp += " " + v;
}
}
unused.emplace_back(std::move(tmp));
found_entries.emplace_back(std::move(tmp));
}
}

if (entry.m_table) {
get_unused_inputs(unused, table, prefix);
get_entries_under_prefix(found_entries, table, prefix,
only_unused, add_values);
}
}
}
Expand All @@ -1137,7 +1144,15 @@ std::vector<std::string>
ParmParse::getUnusedInputs (const std::string& prefix)
{
std::vector<std::string> r;
get_unused_inputs(r, g_table, prefix);
get_entries_under_prefix(r, g_table, prefix, true, true);
return r;
}

std::vector<std::string>
ParmParse::getEntries (const std::string& prefix)
{
std::vector<std::string> r;
get_entries_under_prefix(r, g_table, prefix, false, false);
return r;
}

Expand Down