Skip to content

Commit

Permalink
Handle inheritance correctly when filtering available optoins (LLNL#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
daboehme authored Jan 16, 2020
1 parent b661153 commit 83e23e8
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/caliper/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,27 @@ class ConfigManager::OptionSpec
data[it->second.to_string()] = opt;
}

std::vector<std::string> recursive_get_services_list(const std::string& cfg) {
std::vector<std::string> ret;

auto it = data.find(cfg);

if (it == data.end())
return ret;

ret = it->second.services;

for (const std::string& s : it->second.inherited_specs) {
auto tmp = recursive_get_services_list(s);
ret.insert(ret.end(), tmp.begin(), tmp.end());
}

std::sort(ret.begin(), ret.end());
ret.erase(std::unique(ret.begin(), ret.end()), ret.end());

return ret;
}

public:

OptionSpec()
Expand Down Expand Up @@ -216,19 +237,17 @@ class ConfigManager::OptionSpec
}

// throw out options requiring unavailable services
void filter_unavailable_options(const std::vector<std::string>& services) {
void filter_unavailable_options(const std::vector<std::string>& in) {
std::vector<std::string> available(in);
std::sort(available.begin(), available.end());
available.erase(std::unique(available.begin(), available.end()), available.end());

auto it = data.begin();

while (it != data.end()) {
bool has_all_services = true;

for (const std::string& s : it->second.services)
if (std::find(services.begin(), services.end(), s) == services.end()) {
has_all_services = false;
break;
}
auto required = recursive_get_services_list(it->first);

if (has_all_services)
if (std::includes(available.begin(), available.end(), required.begin(), required.end()))
++it;
else
it = data.erase(it);
Expand Down

0 comments on commit 83e23e8

Please sign in to comment.