21template <
typename T,
typename E>
22 requires(std::is_enum_v<E> && std::is_integral_v<T>)
45 [[nodiscard]]
constexpr operator T()
const {
62 template <
typename... Es>
63 requires(std::is_same_v<Es, E> && ...)
73 template <
typename... Es>
74 requires(std::is_same_v<Es, E> && ...)
85 template <
typename... Es>
86 requires(std::is_same_v<Es, E> && ...)
96 template <
typename... Es>
97 requires(std::is_same_v<Es, E> && ...)
108 template <
typename... Es>
109 requires(std::is_same_v<Es, E> && ...)
110 [[nodiscard]]
constexpr bool onBit(Es... es)
const {
119 template <
typename... Es>
120 requires(std::is_same_v<Es, E> && ...)
121 [[nodiscard]]
constexpr bool onAnyBit(Es... es)
const {
122 return (
onBit_(es) || ...);
130 template <
typename... Es>
131 requires(std::is_same_v<Es, E> && ...)
132 [[nodiscard]]
constexpr bool onAllBit(Es... es)
const {
133 return (
onBit_(es) && ...);
141 template <
typename... Es>
142 requires(std::is_same_v<Es, E> && ...)
143 [[nodiscard]]
constexpr bool offBit(Es... es)
const {
152 template <
typename... Es>
153 requires(std::is_same_v<Es, E> && ...)
154 [[nodiscard]]
constexpr bool offAllBit(Es... es)
const {
163 template <
typename... Es>
164 requires(std::is_same_v<Es, E> && ...)
165 [[nodiscard]]
constexpr bool offAnyBit(Es... es)
const {
174 template <
typename... Es>
175 requires(std::is_same_v<Es, E> && ...)
176 [[nodiscard]]
constexpr T
maskBit(Es... es)
const {
184 template <
typename... Es>
185 requires(std::is_same_v<Es, E> && ...)
186 [[nodiscard]]
constexpr T
makeMask(Es... es)
const {
217 [[nodiscard]]
constexpr bool on(T mask)
const {
218 return (
bits & mask) != 0;
224 [[nodiscard]]
constexpr bool onAll(T mask)
const {
231 [[nodiscard]]
constexpr bool off(T mask)
const {
232 return (
bits & mask) == 0;
253 typedef std::underlying_type_t<E> EI;
254 static constexpr size_t MAX_CAPACITY = std::numeric_limits<T>::digits;
260 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
268 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
277 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
285 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
293 [[nodiscard]]
constexpr bool onBit_(E e)
const {
294 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
302 [[nodiscard]]
constexpr bool offBit_(E e)
const {
303 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
312 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
313 return static_cast<T
>(1) <<
static_cast<T
>(e);
322template <
size_t N,
typename E>
323 requires(std::is_enum_v<E> && N > 64)
335 std::fill(bits.begin(), bits.end(), 0);
344 template <
typename... Es>
345 requires(std::is_same_v<Es, E> && ...)
355 template <
typename... Es>
356 requires(std::is_same_v<Es, E> && ...)
367 template <
typename... Es>
368 requires(std::is_same_v<Es, E> && ...)
379 template <
typename... Es>
380 requires(std::is_same_v<Es, E> && ...)
381 [[nodiscard]]
constexpr bool onBit(Es... es)
const {
390 template <
typename... Es>
391 requires(std::is_same_v<Es, E> && ...)
392 [[nodiscard]]
constexpr bool onAnyBit(Es... es)
const {
393 return (
onBit_(es) || ...);
401 template <
typename... Es>
402 requires(std::is_same_v<Es, E> && ...)
403 [[nodiscard]]
constexpr bool onAllBit(Es... es)
const {
404 return (
onBit_(es) && ...);
412 template <
typename... Es>
413 requires(std::is_same_v<Es, E> && ...)
414 [[nodiscard]]
constexpr bool offBit(Es... es)
const {
423 template <
typename... Es>
424 requires(std::is_same_v<Es, E> && ...)
425 [[nodiscard]]
constexpr bool offAllBit(Es... es)
const {
434 template <
typename... Es>
435 requires(std::is_same_v<Es, E> && ...)
436 [[nodiscard]]
constexpr bool offAnyBit(Es... es)
const {
441 typedef std::underlying_type_t<E> EI;
471 [[nodiscard]]
constexpr bool onBit_(E e)
const {
473 return (field & mask) != 0;
480 [[nodiscard]]
constexpr bool offBit_(E e)
const {
482 return (field & mask) == 0;
491 [[nodiscard]]
constexpr std::pair<T, T>
makeMask_(E e)
const {
492 EI ei =
static_cast<EI
>(e);
494 return std::pair<T, T>(bits[ei / C],
static_cast<T
>(1) << (ei % C));
501 [[nodiscard]]
constexpr std::pair<T &, T>
makeMask_(E e) {
502 EI ei =
static_cast<EI
>(e);
504 return std::pair<T &, T>(bits[ei / C],
static_cast<T
>(1) << (ei % C));
507 static constexpr size_t C = 8 *
sizeof(T);
508 std::array<T, (N + C - 1) / C> bits;
constexpr TBitFlagExt< N, eStatus > & changeBit(bool on, Es... es)
constexpr bool offBit_(eStatus e) const
constexpr void changeBit_(bool on, eStatus e)
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
constexpr bool onAnyBit(Es... es) const
constexpr bool offAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are off.
constexpr TBitFlagExt< N, eStatus > & setBit(Es... es)
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
constexpr bool onAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are on.
constexpr TBitFlagExt< N, eStatus > & makeAllZero()
constexpr bool onBit_(eStatus e) const
constexpr std::pair< T &, T > makeMask_(E e)
Gets bit index and mask for a specific bit.
constexpr void setBit_(eStatus e)
constexpr bool offAllBit(Es... es) const
constexpr TBitFlagExt()
Default constructor, initializes all flags to off.
constexpr std::pair< T, T > makeMask_(eStatus e) const
constexpr void resetBit_(eStatus e)
constexpr TBitFlagExt< N, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
constexpr TBitFlag< T, E > & change(bool on, T mask)
Changes the bits using a direct mask.
constexpr bool onAll(T mask) const
Checks if all bits are on in the specified mask.
constexpr void makeAllZero()
constexpr void changeBit_(bool on, eAttribute e)
constexpr TBitFlag< T, E > & toggleBit(Es... es)
Toggles the corresponding bits for the provided enum values.
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
constexpr void setDirect(u16 mask)
constexpr bool off(T mask) const
Checks if all bits are off in the specified mask.
constexpr TBitFlag< T, E > & reset(T mask)
Resets the bits using a direct mask.
constexpr bool onAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are on.
constexpr TBitFlag< u16, eAttribute > & changeBit(bool on, Es... es)
constexpr TBitFlag()
Default constructor, initializes all flags to off.
constexpr bool offAllBit(Es... es) const
constexpr TBitFlag(T mask)
Constructor that initializes the bit flags with a given mask.
constexpr u16 makeMask(Es... es) const
constexpr TBitFlag< u16, eAttribute > & setBit(Es... es)
constexpr bool onBit_(eAttribute e) const
constexpr bool offAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are off.
constexpr void resetBit_(eAttribute e)
constexpr TBitFlag< T, E > & set(T mask)
Sets the bits using a direct mask.
constexpr TBitFlag< T, E > & operator=(const TBitFlag< T, E > &rhs)
Assignment operator.
constexpr bool on(u16 mask) const
constexpr bool offBit_(eAttribute e) const
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
constexpr bool onAnyBit(Es... es) const
constexpr TBitFlag(E e)
Constructor that initializes the bit flags with a given enum.
constexpr T maskBit(Es... es) const
Creates an applied mask of the corresponding bits for the provided enum values.
constexpr T getDirect() const
Gets the current bit mask.
constexpr u16 makeMask_(eAttribute e) const
constexpr void toggleBit_(eAttribute e)
constexpr void setBit_(eAttribute e)