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_));
145struct flags_enable_operators {
146 static const bool enable =
false;
150std::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)));
158std::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)));
166std::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)));
174std::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) \
183struct flags_enable_operators<_enum> { \
184 static const bool enable = true; \
189#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Type-safe container for enum-based bitfields.
Definition: flags.h:16
constexpr Flags operator&(Flags other) const
Compute the bitwise AND of this Flags and the other Flags.
Definition: flags.h:104
constexpr Flags operator|(Flags other) const
Compute the bitwise OR of this Flags and the other Flags.
Definition: flags.h:114
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^=(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
constexpr Flags & operator&=(E flag)
Store the bitwise AND of this Flags and the flag in this Flags.
Definition: flags.h:33
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 equality.
Definition: flags.h:74
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
constexpr Flags & operator|=(Flags other)
Store the bitwise OR of this Flags and the other Flags in this Flags.
Definition: flags.h:51
std::underlying_type_t< E > Type
The underlying data type of the enum.
Definition: flags.h:21
constexpr Flags()
Construct a Flags instance with a zero value.
Definition: flags.h:23
constexpr bool operator!() const
Check if flags are set.
Definition: flags.h:134
constexpr Flags operator^(Flags other) const
Compute the bitwise XOR of this Flags and the other Flags.
Definition: flags.h:124
constexpr bool operator!=(Flags other)
Compare flags for non-equality.
Definition: flags.h:84
constexpr bool operator!=(E flag)
Compare flags for non-equality.
Definition: flags.h:79
constexpr Flags & operator|=(E flag)
Store the bitwise OR of this Flags and the flag in this Flags.
Definition: flags.h:45
constexpr Flags operator&(E flag) const
Compute the bitwise AND of this Flags and the flag.
Definition: flags.h:99
constexpr Flags & operator&=(Flags other)
Store the bitwise AND of this Flags and the other Flags in this Flags.
Definition: flags.h:39
Top-level libcamera namespace.
Definition: backtrace.h:17
constexpr Transform operator&(Transform t0, Transform t1)
Apply bitwise AND operator between the bits in the two transforms.
Definition: transform.h:29
constexpr Transform operator~(Transform t)
Return the transform with all the bits inverted individually.
Definition: transform.h:68
constexpr Transform operator|(Transform t0, Transform t1)
Apply bitwise OR operator between the bits in the two transforms.
Definition: transform.h:34
constexpr Transform operator^(Transform t0, Transform t1)
Apply bitwise XOR operator between the bits in the two transforms.
Definition: transform.h:39