summaryrefslogtreecommitdiff
path: root/src/tag/Mask.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-02-07 16:57:16 +0100
committerMax Kellermann <max@musicpd.org>2017-02-08 09:04:45 +0100
commit2f3f075e4fc14e361179905cb15e366d366a4786 (patch)
tree1fab8be3cfe6abda1910fa6339bf4468bca0fa4a /src/tag/Mask.hxx
parent17097d96b7452dbcd099af29239be9480aa9df8f (diff)
tag/Mask: wrap in class
Diffstat (limited to 'src/tag/Mask.hxx')
-rw-r--r--src/tag/Mask.hxx67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/tag/Mask.hxx b/src/tag/Mask.hxx
index 09645906a..fdc71d9bb 100644
--- a/src/tag/Mask.hxx
+++ b/src/tag/Mask.hxx
@@ -20,8 +20,73 @@
#ifndef MPD_TAG_MASK_HXX
#define MPD_TAG_MASK_HXX
+#include "Type.h"
+
#include <stdint.h>
-typedef uint_least32_t tag_mask_t;
+class TagMask {
+ typedef uint_least32_t mask_t;
+ mask_t value;
+
+ explicit constexpr TagMask(uint_least32_t _value)
+ :value(_value) {}
+
+public:
+ TagMask() = default;
+
+ constexpr TagMask(TagType tag)
+ :value(mask_t(1) << mask_t(tag)) {}
+
+ static constexpr TagMask None() {
+ return TagMask(mask_t(0));
+ }
+
+ static constexpr TagMask All() {
+ return ~None();
+ }
+
+ constexpr TagMask operator~() const {
+ return TagMask(~value);
+ }
+
+ constexpr TagMask operator&(TagMask other) const {
+ return TagMask(value & other.value);
+ }
+
+ constexpr TagMask operator|(TagMask other) const {
+ return TagMask(value | other.value);
+ }
+
+ constexpr TagMask operator^(TagMask other) const {
+ return TagMask(value ^ other.value);
+ }
+
+ TagMask &operator&=(TagMask other) {
+ value |= other.value;
+ return *this;
+ }
+
+ TagMask &operator|=(TagMask other) {
+ value |= other.value;
+ return *this;
+ }
+
+ TagMask &operator^=(TagMask other) {
+ value |= other.value;
+ return *this;
+ }
+
+ constexpr bool TestAny() const {
+ return value != 0;
+ }
+
+ constexpr bool Test(TagType tag) const {
+ return (*this & tag).TestAny();
+ }
+
+ void Set(TagType tag) {
+ *this |= tag;
+ }
+};
#endif