13#include <initializer_list>
147 constexpr Flags() noexcept = default;
176 constexpr explicit(
false)
Flags(std::initializer_list<enum_type> f)
noexcept
178 for (
auto const & val : f)
189 {
return on ? (*
this |= flag) : (*this &=
Flags(~static_cast<
value_type>(flag))); }
197 { _value ^=
static_cast<value_type>(flag);
return *
this; }
202 { _value = 0;
return *
this; }
210 [[nodiscard]]
constexpr bool testFlag(
enum_type flag)
const noexcept
217 [[nodiscard]]
constexpr bool testAnyFlag(
Flags<enum_type> const & flags)
const noexcept
218 {
return (_value & flags._value) != 0; }
224 [[nodiscard]]
constexpr bool testAllFlags(
Flags<enum_type> const & flags)
const noexcept
225 {
return (_value & flags._value) == flags._value; }
228 [[nodiscard]]
constexpr bool operator==(
Flags<enum_type> const & other)
const noexcept {
return _value == other._value; }
230 [[nodiscard]]
constexpr bool operator!=(
Flags<enum_type> const & other)
const noexcept {
return !(*
this == other); }
232 [[nodiscard]]
constexpr bool operator==(
enum_type flag)
const noexcept {
return testAllFlags(flag); }
234 [[nodiscard]]
constexpr bool operator!=(
enum_type flag)
const noexcept {
return !(*
this == flag); }
242 [[nodiscard]]
constexpr explicit operator enum_type() const noexcept {
return static_cast<enum_type>(_value); }
246 [[nodiscard]]
constexpr explicit operator value_type() const noexcept {
return _value; }
250 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return _value != 0; }
290 [[nodiscard]]
constexpr bool operator!() const noexcept {
return !_value; }
309#define DFX_DECLARE_FLAGS(FlagsName, Enum) \
310 using FlagsName = ::dfx::Utils::Flags<Enum>
325#define DFX_DECLARE_OPERATOR_FOR_FLAGS(FlagsName) \
326 [[nodiscard]] constexpr ::dfx::Utils::Flags<FlagsName::enum_type> operator|(FlagsName::enum_type f1, FlagsName::enum_type f2) noexcept \
327 { return ::dfx::Utils::Flags<FlagsName::enum_type>({ f1, f2 }); }
342#define DFX_DECLARE_STD_FORMATTER_FOR_FLAGS(FlagsName) \
344 struct std::formatter<FlagsName> : public formatter<std::string_view> \
346 auto format(FlagsName const & f, format_context & ctx) const \
348 std::vector<FlagsName::enum_type> vec; \
349 for (auto const & value : ::dfx::Enum::allValues<FlagsName::enum_type>()) \
350 if (f.testFlag(value)) \
351 vec.emplace_back(value); \
352 return formatter<std::string_view>::format(std::format("{}", ::dfx::Utils::join(vec, "|")), ctx); \
Macro-based enum <-> string utilities for dfx.
constexpr Flags(value_type val) noexcept
Construct from an underlying value.
Definition Flags.hpp:168
Enum enum_type
The wrapped enum type.
Definition Flags.hpp:140
constexpr explicit(false) Flags(enum_type e) noexcept
Construct from a single enum flag.
Definition Flags.hpp:151
constexpr Flags() noexcept=default
Construct an empty flag set (value = 0).
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