Skip to content

Commit

Permalink
add bool no_default_value andint/double def to int_matches_if_present…
Browse files Browse the repository at this point in the history
…_or_negative and double_matches_if_present
  • Loading branch information
newfrenchy83 committed Oct 9, 2023
1 parent e261eb8 commit f97c3f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/utils/config_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,32 @@ bool utils::config_filters::int_matches_if_present(const config& filter, const c
}

bool utils::config_filters::int_matches_if_present_or_negative(
const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite)
const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite, bool no_default_value, int def)
{
if(int_matches_if_present(filter, cfg, attribute)) {
if(int_matches_if_present(filter, cfg, attribute, no_default_value , def)) {
return true;
}

// don't check for !cfg[opposite].empty(), as this assumes a default value of zero (similarly to
// int_matches_if_present)
if(cfg[attribute].empty()) {
if(cfg[opposite].empty()) {
if(cfg[opposite].empty() && no_default_value) {
return false;
}
return in_ranges<int>(-cfg[opposite].to_int(0), utils::parse_ranges_int(filter[attribute].str()));
return in_ranges<int>(-cfg[opposite].to_int(def), utils::parse_ranges_int(filter[attribute].str()));
}

return false;
}

bool utils::config_filters::double_matches_if_present(const config& filter, const config& cfg, const std::string& attribute)
bool utils::config_filters::double_matches_if_present(const config& filter, const config& cfg, const std::string& attribute, bool no_default_value, double def)
{
if(filter[attribute].empty()) {
return true;
}
if(cfg[attribute].empty()) {
if(cfg[attribute].empty() && no_default_value) {
return false;
}

return in_ranges<double>(cfg[attribute].to_double(1), utils::parse_ranges_real(filter[attribute].str()));
return in_ranges<double>(cfg[attribute].to_double(def), utils::parse_ranges_real(filter[attribute].str()));
}
4 changes: 2 additions & 2 deletions src/utils/config_filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ bool unsigned_matches_if_present(const config& filter, const config& cfg, const
* The function is named "negative" in case we later want to add a "reciprocal" for the "multiply"/"divide" pair.
*/
bool int_matches_if_present_or_negative(
const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite);
const config& filter, const config& cfg, const std::string& attribute, const std::string& opposite, bool no_default_value = true, int def = 0);

bool string_matches_if_present(
const config& filter, const config& cfg, const std::string& attribute, const std::string& def);
const config& filter, const config& cfg, const std::string& attribute, const std::string& def, bool no_default_value = true, bool def = 1);

} // namespace utils::config_filters

0 comments on commit f97c3f2

Please sign in to comment.