Skip to content

Commit

Permalink
Maybe expose this publicly?
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jan 31, 2024
1 parent f2e4554 commit f00baa7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/openPMD/auxiliary/JSON.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ namespace json
*/
std::string
merge(std::string const &defaultValue, std::string const &overwrite);

std::string filterByTemplate(
std::string const &defaultValue, std::string const &positiveMask);
} // namespace json
} // namespace openPMD
22 changes: 22 additions & 0 deletions src/auxiliary/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,26 @@ filterByTemplate(nlohmann::json &defaultVal, nlohmann::json const &positiveMask)
} // else noop
return defaultVal;
}

std::string filterByTemplate(
std::string const &defaultValue, std::string const &positiveMask)
{
auto [res, returnFormat] =
parseOptions(defaultValue, /* considerFiles = */ false);
filterByTemplate(
res, parseOptions(positiveMask, /* considerFiles = */ false).config);
switch (returnFormat)
{
case SupportedLanguages::JSON:
return res.dump();
break;
case SupportedLanguages::TOML: {
auto asToml = json::jsonToToml(res);
std::stringstream sstream;
sstream << asToml;
return sstream.str();
}
}
throw std::runtime_error("Unreachable!");
}
} // namespace openPMD::json
5 changes: 5 additions & 0 deletions src/binding/python/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,9 @@ users to overwrite default options, while keeping any other ones.
If `defaultValue` was a JSON dataset, then as a JSON string,
otherwise as a TOML string.
)END");
m.def(
"filter_json_by_template",
&json::filterByTemplate,
py::arg("default_value") = "{}",
py::arg("positive_mask") = "{}");
}

0 comments on commit f00baa7

Please sign in to comment.