19 template <
typename TEnum>
22 using TValue = std::underlying_type_t<TEnum>;
23 TValue data = TValue(0);
36 template <
typename... TArgs>
37 constexpr
Flags(
const TEnum flag,
const TArgs... others)
38 : data(construct(flag, others...)) {}
78 return (data & TValue(flag)) != 0;
82 template <
typename... TArgs>
83 INLINE constexpr
bool hasAny(
const TEnum flag,
const TArgs... others)
const {
88 template <
typename... TArgs>
89 INLINE constexpr
bool hasAll(
const TEnum flag,
const TArgs... others)
const {
104 data &= ~TValue(flag);
111 data |= TValue(flag);
113 data &= ~TValue(flag);
132 return data == other.data;
137 return data != other.data;
142 INLINE constexpr
bool hasAny()
const {
150 template <
typename... TArgs>
151 INLINE constexpr TValue construct(
const TEnum first,
const TArgs... rest) {
153 return TValue(first) | construct(rest...);
156 INLINE constexpr TValue construct() {
161 template <typename TEnum, typename = std::enable_if_t<IsEnumClass<TEnum>::value>>
166 template <
typename T>
171 template <
typename T>
#define SPH_ASSERT(x,...)
constexpr INLINE Flags< TEnum > operator|(const TEnum flag1, const TEnum flag2)
const EmptyFlags EMPTY_FLAGS
Additional math routines (with more includes).
constexpr INLINE bool isPower2(const Size n) noexcept
Returns true if given n is a power of 2. N must at least 1.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Few non-standard type traits.
Wrapper of an integral value providing functions for reading and modifying individual bits.
INLINE void unset(const TEnum flag)
Removed a single flag.
constexpr INLINE Flags operator|(const TEnum flag) const
Returns a Flags object by adding a single flag to currently stored values.
constexpr INLINE bool has(const TEnum flag) const
Checks if the object has a given flag.
INLINE bool operator!=(const Flags &other) const
Checks for inequality with other Flags object.
Flags & operator=(const Flags &other)
Copies other Flags object.
constexpr INLINE bool hasAll(const TEnum flag, const TArgs... others) const
Checks if the object has all of given flags.
constexpr INLINE bool hasAny(const TEnum flag, const TArgs... others) const
Checks if the object has any of given flags.
Flags & operator=(const TEnum flag)
Assigns a single flag, all previous flags are deleted.
INLINE TValue value() const
Returns the underlying value.
constexpr Flags(const TEnum flag, const TArgs... others)
Constructs object given a list of flags.
constexpr Flags()=default
Constructs empty flags.
Flags & operator=(const EmptyFlags)
Deletes all flags.
constexpr Flags(const Flags &other)
Constucts flags by copying other object.
constexpr static Flags fromValue(const TValue value)
Constructs object from underlying value.
INLINE void setIf(const TEnum flag, const bool use)
Sets or removes given flag based given boolean value.
INLINE bool operator==(const Flags &other) const
Checks for equality with other Flags object.
INLINE void set(const TEnum flag)
Adds a single flag into the object. All previously stored flags are kept unchanged.
constexpr Flags(const EmptyFlags)
Constructs empty flags.
static constexpr bool isFlags