13#include <initializer_list>
147 constexpr Flags() noexcept = default;
159 constexpr Flags(std::initializer_list<enum_type> f)
noexcept
161 for (
auto const & val : f)
171 {
return on ? (*
this |= flag) : (*
this &= ~static_cast<value_type>(flag)); }
187 {
return (_value & flags._value) != 0; }
194 {
return (_value & flags._value) == flags._value; }
211 [[nodiscard]]
constexpr operator enum_type() const noexcept {
return static_cast<enum_type>(_value); }
215 [[nodiscard]]
constexpr operator value_type() const noexcept {
return _value; }
251 [[nodiscard]]
constexpr bool operator!() const noexcept {
return !_value; }
275#define DECLARE_FLAGS(FlagsName, Enum) \
276 using FlagsName = ::dfx::Utils::Flags<Enum>
291#define DECLARE_OPERATOR_FOR_FLAGS(FlagsName) \
292 [[nodiscard]] constexpr ::dfx::Utils::Flags<FlagsName::enum_type> operator|(FlagsName::enum_type f1, FlagsName::enum_type f2) noexcept \
293 { return ::dfx::Utils::Flags<FlagsName::enum_type>({ f1, f2 }); }
308#define DECLARE_STD_FORMATTER_FOR_FLAGS(FlagsName) \
310 struct std::formatter<FlagsName> : public formatter<std::string_view> \
312 auto format(FlagsName const & f, format_context & ctx) const \
314 std::vector<FlagsName::enum_type> vec; \
315 for (auto const & value : ::dfx::Enum::allValues<FlagsName::enum_type>()) \
316 if (f.testFlag(value)) \
317 vec.emplace_back(value); \
318 return formatter<std::string_view>::format(std::format("{}", ::dfx::Utils::join(vec, "|")), ctx); \
Macro-based enum <-> string utilities for dfx.
constexpr Flags(std::initializer_list< enum_type > f) noexcept
Construct from an initializer-list of flags. All provided flags are OR-ed into the resulting mask.
Definition Flags.hpp:159
constexpr Flags< enum_type > & setFlag(enum_type flag, bool on=true) noexcept
Set or clear a single flag.
Definition Flags.hpp:170
constexpr Flags< enum_type > operator&(Flags< enum_type > mask) const noexcept
Bitwise AND with another flag set.
Definition Flags.hpp:221
constexpr Flags< enum_type > operator|(Flags< enum_type > mask) const noexcept
Bitwise OR with another flag set.
Definition Flags.hpp:231
constexpr Flags< enum_type > operator~() const noexcept
Bitwise NOT.
Definition Flags.hpp:249
constexpr bool operator==(Flags< enum_type > const &other) const noexcept
Equality comparison between two flag sets.
Definition Flags.hpp:197
constexpr Flags< enum_type > & operator|=(enum_type mask) noexcept
In-place bitwise OR with an enum mask.
Definition Flags.hpp:233
constexpr Flags< enum_type > & operator&=(enum_type mask) noexcept
In-place bitwise AND with an enum mask.
Definition Flags.hpp:223
constexpr bool testAnyFlag(Flags< enum_type > const &flags) const noexcept
Test whether any bit from flags is set.
Definition Flags.hpp:186
Enum enum_type
The wrapped enum type.
Definition Flags.hpp:140
constexpr Flags< enum_type > operator^(enum_type mask) const noexcept
Bitwise XOR with an enum mask.
Definition Flags.hpp:239
constexpr bool operator!=(Flags< enum_type > const &other) const noexcept
Inequality comparison between two flag sets.
Definition Flags.hpp:199
constexpr Flags< enum_type > & operator&=(Flags< enum_type > mask) noexcept
In-place bitwise AND with another flag set.
Definition Flags.hpp:225
constexpr Flags< enum_type > & operator^=(Flags< enum_type > mask) noexcept
In-place bitwise XOR with another flag set.
Definition Flags.hpp:245
constexpr Flags< enum_type > operator^(Flags< enum_type > mask) const noexcept
Bitwise XOR with another flag set.
Definition Flags.hpp:241
constexpr bool testFlag(enum_type flag) const noexcept
Test whether a given flag is set.
Definition Flags.hpp:179
constexpr bool operator!() const noexcept
Logical negation.
Definition Flags.hpp:251
constexpr bool testAllFlags(Flags< enum_type > const &flags) const noexcept
Test whether all bits from flags are set.
Definition Flags.hpp:193
constexpr Flags< enum_type > operator|(enum_type mask) const noexcept
Bitwise OR with an enum mask.
Definition Flags.hpp:229
constexpr Flags< enum_type > & operator^=(enum_type mask) noexcept
In-place bitwise XOR with an enum mask.
Definition Flags.hpp:243
constexpr bool operator!=(enum_type flag) const noexcept
Negated form of operator==(enum_type).
Definition Flags.hpp:203
constexpr Flags< enum_type > operator&(enum_type mask) const noexcept
Bitwise AND with an enum mask.
Definition Flags.hpp:219
constexpr bool operator==(enum_type flag) const noexcept
Compare the flag set against a single enum mask.
Definition Flags.hpp:201
constexpr Flags() noexcept=default
Construct an empty flag set (value = 0).
constexpr Flags< enum_type > & operator|=(Flags< enum_type > mask) noexcept
In-place bitwise OR with another flag set.
Definition Flags.hpp:235
std::underlying_type_t< Enum > value_type
The underlying integer storage type.
Definition Flags.hpp:143
Concept matching any enumeration type. This is used to constrain Flags to be instantiated only with e...
Definition Flags.hpp:102
Enum string conversion and enumeration utilities.
Definition EnumString.hpp:120
Definition SystemConfigCommandHandler.hpp:15