mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
AK: Change EnumBits has_flag() to check all flags in mask are present
Co-authored-by: Brian Gianforcaro <b.gianfo@gmail.com>
This commit is contained in:
parent
2df4d977e2
commit
03b76e4ba0
1 changed files with 58 additions and 58 deletions
116
AK/EnumBits.h
116
AK/EnumBits.h
|
@ -20,62 +20,62 @@
|
||||||
#define AK_ENUM_BITWISE_FRIEND_OPERATORS(Enum) \
|
#define AK_ENUM_BITWISE_FRIEND_OPERATORS(Enum) \
|
||||||
_AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, friend)
|
_AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, friend)
|
||||||
|
|
||||||
#define _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, Prefix) \
|
#define _AK_ENUM_BITWISE_OPERATORS_INTERNAL(Enum, Prefix) \
|
||||||
\
|
\
|
||||||
[[nodiscard]] Prefix constexpr Enum operator|(Enum lhs, Enum rhs) \
|
[[nodiscard]] Prefix constexpr Enum operator|(Enum lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
return static_cast<Enum>( \
|
return static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
[[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \
|
[[nodiscard]] Prefix constexpr Enum operator&(Enum lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
return static_cast<Enum>( \
|
return static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
[[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \
|
[[nodiscard]] Prefix constexpr Enum operator^(Enum lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
return static_cast<Enum>( \
|
return static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
[[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \
|
[[nodiscard]] Prefix constexpr Enum operator~(Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
return static_cast<Enum>( \
|
return static_cast<Enum>( \
|
||||||
~static_cast<Type>(rhs)); \
|
~static_cast<Type>(rhs)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \
|
Prefix constexpr Enum& operator|=(Enum& lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
lhs = static_cast<Enum>( \
|
lhs = static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) | static_cast<Type>(rhs)); \
|
||||||
return lhs; \
|
return lhs; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \
|
Prefix constexpr Enum& operator&=(Enum& lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
lhs = static_cast<Enum>( \
|
lhs = static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) & static_cast<Type>(rhs)); \
|
||||||
return lhs; \
|
return lhs; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \
|
Prefix constexpr Enum& operator^=(Enum& lhs, Enum rhs) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
lhs = static_cast<Enum>( \
|
lhs = static_cast<Enum>( \
|
||||||
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
static_cast<Type>(lhs) ^ static_cast<Type>(rhs)); \
|
||||||
return lhs; \
|
return lhs; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
Prefix constexpr bool has_flag(Enum value, Enum mask) \
|
Prefix constexpr bool has_flag(Enum value, Enum mask) \
|
||||||
{ \
|
{ \
|
||||||
using Type = UnderlyingType<Enum>; \
|
using Type = UnderlyingType<Enum>; \
|
||||||
return static_cast<Type>(value & mask) != 0; \
|
return static_cast<Type>(value & mask) == static_cast<Type>(mask); \
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue