Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Src/Base/AMReX_ParmParse.H
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,10 @@ public:
//! Write the contents of the table in ASCII to the ostream.
static void dumpTable (std::ostream& os, bool prettyPrint = false);

//! Write the table in a pretty way to the ostream. If there are
//! duplicates, only the last one is printed.
static void prettyPrintTable (std::ostream& os);

//! Add keys and values from a file to the end of the PP table.
static void addfile (std::string const& filename);

Expand Down
27 changes: 27 additions & 0 deletions Src/Base/AMReX_ParmParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <iostream>
#include <limits>
#include <numeric>
#include <unordered_map>
#include <regex>
#include <sstream>
#include <stdexcept>
Expand Down Expand Up @@ -1209,6 +1210,32 @@ ParmParse::dumpTable (std::ostream& os, bool prettyPrint)
}
}

void
ParmParse::prettyPrintTable (std::ostream& os)
{
std::vector<std::string> sorted_names;
sorted_names.reserve(g_table.size());
for (auto const& [name, entry] : g_table) {
sorted_names.push_back(name);
}
std::sort(sorted_names.begin(), sorted_names.end());

for (auto const& name : sorted_names) {
auto const& entry = g_table[name];
std::vector<std::string> value_string;
std::unordered_map<std::string,int> count;
for (auto const& vals : entry.m_vals) {
value_string.emplace_back(pp_to_pretty_string(name, vals));
++count[value_string.back()];
}
for (auto const& s : value_string) {
if (--count[s] == 0) {
os << s << '\n';
}
}
}
}

int
ParmParse::countval (const char* name,
int n) const
Expand Down