10 #include <type_traits> 18 static_assert(std::is_enum<E>::value,
19 "Flags<> template parameter must be an enum");
21 using Type = std::underlying_type_t<E>;
29 : value_(static_cast<
Type>(flag))
35 value_ &=
static_cast<Type>(flag);
41 value_ &= other.value_;
47 value_ |=
static_cast<Type>(flag);
53 value_ |= other.value_;
59 value_ ^=
static_cast<Type>(flag);
65 value_ ^= other.value_;
71 return value_ ==
static_cast<Type>(flag);
76 return value_ ==
static_cast<Type>(other);
81 return value_ !=
static_cast<Type>(flag);
86 return value_ !=
static_cast<Type>(other);
89 constexpr
explicit operator Type()
const 94 constexpr
explicit operator bool()
const 101 return Flags(static_cast<E>(value_ & static_cast<Type>(flag)));
106 return Flags(static_cast<E>(value_ & other.value_));
111 return Flags(static_cast<E>(value_ | static_cast<Type>(flag)));
116 return Flags(static_cast<E>(value_ | other.value_));
121 return Flags(static_cast<E>(value_ ^ static_cast<Type>(flag)));
126 return Flags(static_cast<E>(value_ ^ other.value_));
131 return Flags(static_cast<E>(~value_));
145 struct flags_enable_operators {
146 static const bool enable =
false;
150 std::enable_if_t<flags_enable_operators<E>::enable,
Flags<E>>
153 using type = std::underlying_type_t<E>;
154 return Flags<E>(
static_cast<E
>(
static_cast<type
>(lhs) | static_cast<type>(rhs)));
158 std::enable_if_t<flags_enable_operators<E>::enable,
Flags<E>>
161 using type = std::underlying_type_t<E>;
162 return Flags<E>(
static_cast<E
>(
static_cast<type
>(lhs) & static_cast<type>(rhs)));
166 std::enable_if_t<flags_enable_operators<E>::enable,
Flags<E>>
169 using type = std::underlying_type_t<E>;
170 return Flags<E>(
static_cast<E
>(
static_cast<type
>(lhs) ^ static_cast<type>(rhs)));
174 std::enable_if_t<flags_enable_operators<E>::enable,
Flags<E>>
177 using type = std::underlying_type_t<E>;
178 return Flags<E>(
static_cast<E
>(~static_cast<type>(rhs)));
181 #define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum) \ 183 struct flags_enable_operators<_enum> { \ 184 static const bool enable = true; \ 189 #define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum) constexpr Transform & operator &=(Transform &t0, Transform t1)
Apply bitwise AND-assignment operator between the bits in the two transforms.
Definition: transform.h:42
constexpr Flags operator|(Flags other) const
Compute the bitwise OR of this Flags and the other Flags.
Definition: flags.h:114
constexpr Flags & operator|=(Flags other)
Store the bitwise OR of this Flags and the other Flags in this Flags.
Definition: flags.h:51
constexpr Flags operator^(Flags other) const
Compute the bitwise XOR of this Flags and the other Flags.
Definition: flags.h:124
constexpr Transform operator &(Transform t0, Transform t1)
Apply bitwise AND operator between the bits in the two transforms.
Definition: transform.h:27
Top-level libcamera namespace.
Definition: backtrace.h:17
constexpr bool operator==(Flags other)
Compare flags for equality.
Definition: flags.h:74
constexpr Flags()
Construct a Flags instance with a zero value.
Definition: flags.h:23
constexpr bool operator!=(E flag)
Compare flags for non-equality.
Definition: flags.h:79
constexpr Flags & operator^=(Flags other)
Store the bitwise XOR of this Flags and the other Flags in this Flags.
Definition: flags.h:63
constexpr Flags operator^(E flag) const
Compute the bitwise XOR of this Flags and the flag.
Definition: flags.h:119
std::underlying_type_t< OpenModeFlag > Type
The underlying data type of the enum.
Definition: flags.h:21
constexpr bool operator!() const
Check if flags are set.
Definition: flags.h:134
constexpr Flags & operator|=(E flag)
Store the bitwise OR of this Flags and the flag in this Flags.
Definition: flags.h:45
constexpr bool operator==(E flag)
Compare flags for equality.
Definition: flags.h:69
constexpr Flags & operator^=(E flag)
Store the bitwise XOR of this Flags and the flag in this Flags.
Definition: flags.h:57
constexpr Flags operator|(E flag) const
Compute the bitwise OR of this Flags and the flag.
Definition: flags.h:109
constexpr bool operator!=(Flags other)
Compare flags for non-equality.
Definition: flags.h:84
Type-safe container for enum-based bitfields.
Definition: flags.h:15
constexpr Flags operator~() const
Compute the bitwise NOT of this Flags.
Definition: flags.h:129
constexpr Flags(E flag)
Construct a Flags instance storing the flag.
Definition: flags.h:28