Utility functions for implementing [filter], [filter_ability], [filter_weapon], etc. More...
Functions | |
bool | bool_matches_if_present (const config &filter, const config &cfg, const std::string &attribute, bool def) |
Checks whether the filter matches the value of cfg[attribute]. More... | |
bool | double_matches_if_present (const config &filter, const config &cfg, const std::string &attribute, utils::optional< double > def=utils::nullopt) |
Checks whether the filter matches the value of cfg[attribute]. More... | |
bool | int_matches_if_present (const config &filter, const config &cfg, const std::string &attribute, utils::optional< int > def=utils::nullopt) |
bool | int_matches_if_present_or_negative (const config &filter, const config &cfg, const std::string &attribute, const std::string &opposite, utils::optional< int > def=utils::nullopt) |
Supports filters using "add" and "sub" attributes, for example a filter add=1 matching a cfg containing either add=1 or sub=-1 ; this assumes that code elsewhere has already checked that cfg contains at most one of those keys. More... | |
bool | string_matches_if_present (const config &filter, const config &cfg, const std::string &attribute, const std::string &def) |
bool | set_includes_if_present (const config &filter, const config &cfg, const std::string &attribute) |
filter[attribute] and cfg[attribute] are assumed to be comma-separated lists. More... | |
bool | bool_or_empty (const config &filter, const config &cfg, const std::string &attribute) |
Utility functions for implementing [filter], [filter_ability], [filter_weapon], etc.
For example, a filter of x=1
puts a requirement on the value of x
but accepts any value of y
.
Both int
and double
assume a default value of zero, so a filter that accepts zero will match an unset value as well as a present value.
bool utils::config_filters::bool_matches_if_present | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute, | ||
bool | def | ||
) |
Checks whether the filter matches the value of cfg[attribute].
If cfg doesn't have that attribute, assume that an unset value is equivalent to def.
Always returns true if the filter puts no restriction on the value of cfg[attribute].
Definition at line 24 of file config_filters.cpp.
References config::has_attribute().
bool utils::config_filters::bool_or_empty | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute | ||
) |
Definition at line 130 of file config_filters.cpp.
References config::has_attribute(), and utils::split_set().
bool utils::config_filters::double_matches_if_present | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute, | ||
utils::optional< double > | def = utils::nullopt |
||
) |
Checks whether the filter matches the value of cfg[attribute].
If cfg doesn't have that attribute, assume that an unset value is equivalent to def if exist, else value false is returned.
Always returns true if the filter puts no restriction on the value of cfg[attribute].
Definition at line 111 of file config_filters.cpp.
References config::has_attribute(), and utils::parse_ranges_real().
bool utils::config_filters::int_matches_if_present | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute, | ||
utils::optional< int > | def = utils::nullopt |
||
) |
Definition at line 68 of file config_filters.cpp.
References config::has_attribute(), and utils::parse_ranges_int().
Referenced by BOOST_AUTO_TEST_CASE(), and int_matches_if_present_or_negative().
bool utils::config_filters::int_matches_if_present_or_negative | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute, | ||
const std::string & | opposite, | ||
utils::optional< int > | def = utils::nullopt |
||
) |
Supports filters using "add" and "sub" attributes, for example a filter add=1
matching a cfg containing either add=1
or sub=-1
; this assumes that code elsewhere has already checked that cfg contains at most one of those keys.
This only checks for the presence of attribute and opposite in the filter, so the caller should call this function a second time, with attribute and opposite reversed and if none of these attribute is here value false is returned.
The function is named "negative" in case we later want to add a "reciprocal" for the "multiply"/"divide" pair.
Definition at line 87 of file config_filters.cpp.
References config::has_attribute(), int_matches_if_present(), and utils::parse_ranges_int().
Referenced by BOOST_AUTO_TEST_CASE().
bool utils::config_filters::set_includes_if_present | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute | ||
) |
filter[attribute] and cfg[attribute] are assumed to be comma-separated lists.
If the filter is present, each item in filter[attribute] must match an item in cfg[attribute] for the function to return true.
Definition at line 45 of file config_filters.cpp.
References config::has_attribute(), and utils::split_set().
bool utils::config_filters::string_matches_if_present | ( | const config & | filter, |
const config & | cfg, | ||
const std::string & | attribute, | ||
const std::string & | def | ||
) |
Definition at line 33 of file config_filters.cpp.
References config::has_attribute(), and utils::split().