19 template<
typename Enum,
typename Storage = std::underlying_type_t<Enum>>
struct Flags {
39 constexpr Flags(
const std::initializer_list<Enum>&
values)
noexcept {
60 return (
raw & value.raw) == value.raw;
65 return (
raw &
static_cast<Storage>(value)) != 0;
70 return (
raw & value.raw) != 0;
127 constexpr bool operator==(
const bool rhs)
const noexcept {
return ((
bool)*
this) == rhs; }
216#define CE_FLAGS_OPERATORS(Enum) CE_FLAGS_OPERATORS_EXT(Enum, std::underlying_type_t<Enum>)
219#define CE_FLAGS_OPERATORS_EXT(Enum, Storage) \
220 [[nodiscard]] inline constexpr Flags<Enum, Storage> operator|(Enum a, Enum b) noexcept { \
221 Flags<Enum, Storage> r(a); \
226 [[nodiscard]] inline constexpr Flags<Enum, Storage> operator&(Enum a, Enum b) noexcept { \
227 Flags<Enum, Storage> r(a); \
232 [[nodiscard]] inline constexpr Flags<Enum, Storage> operator~(Enum a) noexcept { return ~Flags<Enum, Storage>(a); }
268 [[
nodiscard]]
inline bool any(
const unsigned int flags)
const {
return ((
raw & flags) != 0); }
271 [[
nodiscard]]
inline bool all(
const unsigned int flags)
const {
return ((
raw & flags) == flags); }
277 inline operator unsigned int()
const {
return raw; }
283template<
class Enum,
class Storage>
struct std::hash<
CeresEngine::
Flags<Enum, Storage>> {
285 std::hash<Storage> hasher{};
286 return hasher(key.
raw);
Represents a reflected enum from C++.
Definition Enum.hpp:26
RawFlags(const RawFlags &)=default
bool any(const unsigned int flags) const
Definition Flags.hpp:268
void remove(const unsigned int flag)
Definition Flags.hpp:259
bool all(const unsigned int flags) const
Definition Flags.hpp:271
void insert(const unsigned int flag)
Definition Flags.hpp:256
bool setOnce(const unsigned int flag)
Definition Flags.hpp:247
RawFlags & operator=(const RawFlags &)=default
unsigned int raw
Definition Flags.hpp:237
RawFlags(const unsigned int flags)
Definition Flags.hpp:244
RawFlags & operator<<(const unsigned int flag)
Definition Flags.hpp:262
bool operator()(const unsigned int flag) const
Definition Flags.hpp:274
Definition Application.hpp:19
auto values(Container &container)
Returns an iterable object that iterates over the values of a map-like container.
Definition Iterator.hpp:400
struct CeresEngine::GLState state
std::uint8_t UInt8
Definition DataTypes.hpp:17
@ Storage
Storage buffer type (also called "Shader Storage Buffer Object" or "Read/Write Buffer").
@ Flags
Indicates that only the object flags are dirty.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Wrapper around an enum that allows simple use of bitwise logic operations.
Definition Flags.hpp:19
constexpr Flags(const Flags &value) noexcept
Definition Flags.hpp:45
constexpr bool operator==(Enum rhs) const noexcept
Definition Flags.hpp:125
constexpr bool operator==(const Flags &rhs) const noexcept
Definition Flags.hpp:126
constexpr Flags() noexcept=default
constexpr Flags & operator=(Enum value) noexcept
Assigns the Flags object with the given enum value.
Definition Flags.hpp:32
constexpr Flags operator&(const Flags &rhs) const noexcept
Definition Flags.hpp:170
constexpr Flags & operator=(const Flags &rhs) noexcept
Definition Flags.hpp:46
Storage raw
Definition Flags.hpp:20
constexpr Flags operator&(Enum rhs) const noexcept
Definition Flags.hpp:164
constexpr bool setIfUnset(Enum value) noexcept
Sets a set of bits only if any of it's bits were previously unset.
Definition Flags.hpp:104
constexpr Flags & operator^=(const Flags &rhs) noexcept
Definition Flags.hpp:181
constexpr Flags & set(Enum value, const bool state) noexcept
Activates or deactives all of the provided bits.
Definition Flags.hpp:80
constexpr Flags operator~() const noexcept
Definition Flags.hpp:198
constexpr Flags operator|(Enum rhs) const noexcept
Definition Flags.hpp:142
constexpr bool operator!=(Enum rhs) const noexcept
Definition Flags.hpp:129
constexpr bool operator!=(const Flags &rhs) const noexcept
Definition Flags.hpp:130
constexpr Flags & operator&=(Enum rhs) noexcept
Definition Flags.hpp:154
constexpr bool isSet(const Flags &value) const noexcept
Checks whether all of the provided bits are set.
Definition Flags.hpp:59
constexpr bool isSetAny(const Flags &value) const noexcept
Checks whether any of the provided bits are set.
Definition Flags.hpp:69
constexpr bool operator==(const bool rhs) const noexcept
Definition Flags.hpp:127
constexpr bool isSet(Enum value) const noexcept
Checks whether all of the provided bits are set.
Definition Flags.hpp:54
constexpr Flags(const std::initializer_list< Enum > &values) noexcept
Creates a new Flags object from a list of values.
Definition Flags.hpp:39
constexpr Flags & unset(Enum value) noexcept
Deactivates all of the provided bits.
Definition Flags.hpp:90
constexpr Flags(Storage bits) noexcept
Definition Flags.hpp:51
constexpr Flags & set(Enum value) noexcept
Activates all of the provided bits.
Definition Flags.hpp:74
constexpr Flags & operator|=(const Flags &rhs) noexcept
Definition Flags.hpp:137
constexpr Flags & unset(const Flags< Enum > value) noexcept
Deactivates all of the provided bits.
Definition Flags.hpp:96
constexpr Flags & operator|=(Enum rhs) noexcept
Definition Flags.hpp:132
constexpr Flags & operator&=(const Flags &rhs) noexcept
Definition Flags.hpp:159
constexpr Flags & operator^=(Enum rhs) noexcept
Definition Flags.hpp:176
constexpr Flags operator|(const Flags &rhs) const noexcept
Definition Flags.hpp:148
constexpr bool unsetIfSet(Enum value) noexcept
Unsets a set of bits only if any of it's bits were previously set.
Definition Flags.hpp:116
friend constexpr Flags operator&(Enum a, Flags &b) noexcept
Definition Flags.hpp:208
constexpr Flags operator^(const Flags &rhs) const noexcept
Definition Flags.hpp:192
constexpr Flags operator^(Enum rhs) const noexcept
Definition Flags.hpp:186
constexpr bool isSetAny(Enum value) const noexcept
Checks whether any of the provided bits are set.
Definition Flags.hpp:64