diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /src/object_filter.hpp | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'src/object_filter.hpp')
-rw-r--r-- | src/object_filter.hpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/object_filter.hpp b/src/object_filter.hpp new file mode 100644 index 00000000..d18e13ee --- /dev/null +++ b/src/object_filter.hpp @@ -0,0 +1,90 @@ +#pragma once + +#include "h-basic.h" +#include "object_flag_set.hpp" +#include "object_type_fwd.hpp" + +#include <functional> +#include <initializer_list> + +typedef std::function<bool (object_type const *)> object_filter_t; + +namespace object_filter { + +/** + * Is TVal equal to the given value? + */ +object_filter_t TVal(byte tval); + +/** + * Is SVal equal to the given value? + */ +object_filter_t SVal(byte sval); + +/** + * Has given set of flags set. + */ +object_filter_t HasFlags(object_flag_set const &); + +/** + * Is the object an artifact? + */ +object_filter_t IsArtifact(); + +/** + * Is the object an artifact as determined by artifact_p? + */ +object_filter_t IsArtifactP(); + +/** + * Is the object an ego item? + */ +object_filter_t IsEgo(); + +/** + * Is the object "known"? + */ +object_filter_t IsKnown(); + +/** + * True always accepts all items. + */ +object_filter_t True(); + +/** + * Invert an object filter. + */ +object_filter_t Not(object_filter_t p); + +/** + * Logical conjunction (AND) + */ +object_filter_t And(); + +/** + * Logical conjunction (AND) + */ +template<typename Arg0, typename... Args> object_filter_t And(Arg0&& arg0, Args&&... args) { + auto argsFilter = And(args...); + return [=](object_type const *o_ptr) -> bool { + return arg0(o_ptr) && argsFilter(o_ptr); + }; +} + +/** + * Logical disjunction (OR) + */ +object_filter_t Or(); + +/** + * Logical disjunction (OR) + */ +template<typename Arg0, typename... Args> object_filter_t Or(Arg0&& arg0, Args&&... args) { + auto argsFilter = Or(args...); + return [=](object_type const *o_ptr) -> bool { + auto x = arg0(o_ptr) || argsFilter(o_ptr); + return x; + }; +} + +} |