Type-safe bitmask wrapper for enum flags.
More...
#include <spk_flags.hpp>
|
|
using | MaskType = StorageT |
| | Unsigned storage type used to hold flag bits.
|
|
|
constexpr | Flags ()=default |
| | Builds an empty flag set.
|
| constexpr | Flags (TFlagType p_v) |
| | Initializes with a single flag.
|
| constexpr | Flags (MaskType p_raw) |
| | Initializes with raw bits.
|
| constexpr | Flags (std::initializer_list< TFlagType > p_values) |
| | Initializes with multiple flags.
|
|
constexpr void | clear () |
| | Clears all flags.
|
| constexpr void | reset (TFlagType p_v) |
| | Removes specific flags.
|
| constexpr Flags & | operator|= (TFlagType p_v) |
| | In-place OR with a flag.
|
| constexpr Flags & | operator&= (TFlagType p_v) |
| | In-place AND with a mask.
|
| constexpr Flags & | operator^= (TFlagType p_v) |
| | In-place XOR with a flag.
|
| constexpr bool | has (TFlagType p_v) const |
| | Tests whether all bits in a mask are set.
|
| constexpr bool | testAny (TFlagType p_v) const |
| | Tests whether any bit in a mask is set.
|
| constexpr bool | any () const |
| | Checks if any flag is set.
|
| constexpr bool | none () const |
| | Checks if no flags are set.
|
| constexpr | operator bool () const |
| | Tests whether any bit is set.
|
| constexpr MaskType | raw () const |
| | Returns the underlying bits.
|
|
|
MaskType | bits {} |
| | Raw underlying bit storage.
|
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
struct spk::Flags< TFlagType, StorageT >
Type-safe bitmask wrapper for enum flags.
- Template Parameters
-
| TFlagType | Enum type satisfying bitmask_enum. |
| StorageT | Unsigned storage type (8/16/32-bit). |
- See also
- bitmask_enum
enum class Option : uint32_t { A = 1u << 0, B = 1u << 1 };
mask |= Option::B;
if (mask.
has(Option::A)) { use(); }
Type-safe bitmask wrapper for enum flags.
Definition spk_flags.hpp:111
constexpr bool has(TFlagType p_v) const
Tests whether all bits in a mask are set.
Definition spk_flags.hpp:210
◆ Flags() [1/3]
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| spk::Flags< TFlagType, StorageT >::Flags |
( |
TFlagType | p_v | ) |
|
|
inlineconstexpr |
Initializes with a single flag.
- Parameters
-
◆ Flags() [2/3]
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
Initializes with raw bits.
- Parameters
-
◆ Flags() [3/3]
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| spk::Flags< TFlagType, StorageT >::Flags |
( |
std::initializer_list< TFlagType > | p_values | ) |
|
|
inlineconstexpr |
Initializes with multiple flags.
- Parameters
-
| p_values | Flags to OR together. |
◆ any()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| bool spk::Flags< TFlagType, StorageT >::any |
( |
| ) |
const |
|
inlineconstexpr |
Checks if any flag is set.
- Returns
- true when bits is non-zero.
◆ has()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| bool spk::Flags< TFlagType, StorageT >::has |
( |
TFlagType | p_v | ) |
const |
|
inlineconstexpr |
Tests whether all bits in a mask are set.
- Parameters
-
- Returns
- true when every requested flag is present.
◆ none()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| bool spk::Flags< TFlagType, StorageT >::none |
( |
| ) |
const |
|
inlineconstexpr |
Checks if no flags are set.
- Returns
- true when bits is zero.
◆ operator bool()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| spk::Flags< TFlagType, StorageT >::operator bool |
( |
| ) |
const |
|
inlineexplicitconstexpr |
Tests whether any bit is set.
- Returns
- true when any flag is present.
◆ operator&=()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
In-place AND with a mask.
- Parameters
-
- Returns
- Reference to this mask.
◆ operator^=()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
In-place XOR with a flag.
- Parameters
-
- Returns
- Reference to this mask.
◆ operator|=()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
In-place OR with a flag.
- Parameters
-
- Returns
- Reference to this mask.
◆ raw()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
Returns the underlying bits.
- Returns
- Raw mask.
◆ reset()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| void spk::Flags< TFlagType, StorageT >::reset |
( |
TFlagType | p_v | ) |
|
|
inlineconstexpr |
Removes specific flags.
- Parameters
-
◆ testAny()
template<bitmask_enum TFlagType, unsigned_storage StorageT = std::uint32_t>
| bool spk::Flags< TFlagType, StorageT >::testAny |
( |
TFlagType | p_v | ) |
const |
|
inlineconstexpr |
Tests whether any bit in a mask is set.
- Parameters
-
- Returns
- true when at least one requested flag is present.
The documentation for this struct was generated from the following file: