1#include <StormByte/type_traits.hxx>
14template <Type::Un
signedEnum E>
15constexpr E operator|(E a, E b)
noexcept {
16 return static_cast<E
>(Type::ToUnderlying(a) | Type::ToUnderlying(b));
28template <Type::Un
signedEnum E>
29constexpr E operator&(E a, E b)
noexcept {
30 return static_cast<E
>(Type::ToUnderlying(a) & Type::ToUnderlying(b));
42template <Type::Un
signedEnum E>
43constexpr E operator^(E a, E b)
noexcept {
44 return static_cast<E
>(Type::ToUnderlying(a) ^ Type::ToUnderlying(b));
55template <Type::Un
signedEnum E>
56constexpr E operator~(E a)
noexcept {
57 return static_cast<E
>(
~Type::ToUnderlying(a));
94 template<
typename Derived, Type::Un
signedEnum E>
100 constexpr Bitmask() noexcept: m_value(static_cast<E>(0)) {}
106 constexpr Bitmask(E value)
noexcept: m_value(value) {}
144 constexpr
bool operator==(const
Bitmask& other) const noexcept {
145 return m_value == other.m_value;
154 return m_value != other.m_value;
163 return Derived(m_value | other.m_value);
172 return Derived(m_value & other.m_value);
181 return Derived(m_value ^ other.m_value);
189 return Derived(~m_value);
198 m_value = m_value | other.m_value;
208 m_value = m_value & other.m_value;
218 m_value = m_value ^ other.m_value;
226 constexpr void Add(E value)
noexcept {
227 m_value = m_value | value;
234 constexpr void Remove(E value)
noexcept {
235 m_value = m_value & ~value;
242 constexpr E
Value() const noexcept {
251 constexpr bool Has(E value)
const noexcept {
252 return (m_value & value) == value;
261 return Has(other.m_value);
269 constexpr bool HasAny(E value)
const noexcept {
270 return (m_value & value) !=
static_cast<E
>(0);
279 return HasAny(other.m_value);
287 constexpr bool HasNone(E value)
const noexcept {
288 return (m_value & value) ==
static_cast<E
>(0);
Bitmask class template for managing enum class flags.
Definition bitmask.hxx:95
constexpr Bitmask(E value) noexcept
Constructor initializes the bitmask with a specific enum value.
Definition bitmask.hxx:106
constexpr Bitmask & operator&=(const Bitmask &other) noexcept
Bitwise AND assignment operator.
Definition bitmask.hxx:207
constexpr void Remove(E value) noexcept
Remove a flag from the bitmask.
Definition bitmask.hxx:234
constexpr bool HasNone(E value) const noexcept
Check if none of the specified flags are set in the bitmask.
Definition bitmask.hxx:287
constexpr bool HasAny(E value) const noexcept
Check if any of the specified flags are set in the bitmask.
Definition bitmask.hxx:269
constexpr bool operator!=(const Bitmask &other) const noexcept
Inequality operator.
Definition bitmask.hxx:153
constexpr bool Has(E value) const noexcept
Check if the bitmask has a specific flag set.
Definition bitmask.hxx:251
constexpr Derived operator|(const Bitmask &other) const noexcept
Bitwise OR operator.
Definition bitmask.hxx:162
constexpr Bitmask(Bitmask &&other) noexcept=default
Move constructor.
constexpr E Value() const noexcept
Get the current value of the bitmask.
Definition bitmask.hxx:242
constexpr bool HasAny(const Bitmask &other) const noexcept
Check if any of the flags from another bitmask are set in this bitmask.
Definition bitmask.hxx:278
constexpr Bitmask & operator^=(const Bitmask &other) noexcept
Bitwise XOR assignment operator.
Definition bitmask.hxx:217
constexpr Bitmask & operator|=(const Bitmask &other) noexcept
Bitwise OR assignment operator.
Definition bitmask.hxx:197
constexpr bool HasNone(const Bitmask &other) const noexcept
Check if none of the flags from another bitmask are set in this bitmask.
Definition bitmask.hxx:296
constexpr Bitmask() noexcept
Default constructor initializes the bitmask to zero.
Definition bitmask.hxx:100
constexpr Derived operator~() const noexcept
Bitwise NOT operator.
Definition bitmask.hxx:188
constexpr Bitmask(const Bitmask &other) noexcept=default
Copy constructor.
virtual constexpr ~Bitmask() noexcept=default
Destructor.
constexpr Derived operator&(const Bitmask &other) const noexcept
Bitwise AND operator.
Definition bitmask.hxx:171
constexpr bool Has(const Bitmask &other) const noexcept
Check if the bitmask has all flags set from another bitmask.
Definition bitmask.hxx:260
constexpr Derived operator^(const Bitmask &other) const noexcept
Bitwise XOR operator.
Definition bitmask.hxx:180
constexpr void Add(E value) noexcept
Add a flag to the bitmask.
Definition bitmask.hxx:226
Main namespace for the StormByte library.
Modern C++20 concepts for type checking.