#include <Corrade/Containers/BigEnumSet.h>
template<class T, std:: size_t size = (1 <<(sizeof(T)*8 - 6))>
BigEnumSet class new in Git master
Set of more than 64 enum values.
Template parameters | |
---|---|
T | Enum type |
size | How many 64-bit integers to use to store the value |
A variant of EnumSet that is able to handle sets of more than 64 values (which is the largest standard integer type) by treating the enum
values as bit positions instead of bit values. Internally an array is used for storage and the class doesn't provide any equivalent to EnumSet::
While it's theoretically possible to store up to different values, the storage is artificially limited to 8192 values, which fits into 1 kB. With a 16-bit T
and larger, you're expected to set the size
template parameter to a reasonable upper bound, not larger than 128
. On construction, the enum value is checked against this limit to ensure no bits are ignored by accident. For an unbounded runtime-sized array of bits use BitArray instead.
Below is a side-by-side comparison of an equivalent enum set implementation in EnumSet and BigEnumSet — the only difference is enum values being specified as i
instead of 1 << i
and the typedef
, the CORRADE_
/* 64 values at most */ enum class Feature: std::uint64_t { DeferredRendering = 1 << 0, AreaLights = 1 << 1, GlobalIllumination = 1 << 2, Shadows = 1 << 3, Reflections = 1 << 4, … }; typedef Containers::EnumSet<Feature> Features; CORRADE_ENUMSET_OPERATORS(Features)
/* 256 values at most, for an 8-bit type */ enum class Feature: std::uint8_t { DeferredRendering = 0, AreaLights = 1, GlobalIllumination = 2, Shadows = 3, Reflections = 4, … }; typedef Containers::BigEnumSet<Feature> Features; CORRADE_ENUMSET_OPERATORS(Features)
Public types
-
enum (anonymous): std::
size_t { Size = size } - using Type = T
- Enum type.
Constructors, destructors, conversion operators
- BigEnumSet() constexpr noexcept
- Create an empty set.
- BigEnumSet(T value) constexpr noexcept
- Create a set from one value.
-
BigEnumSet(Corrade::
NoInitT) explicit - Create an uninitialized set.
- operator bool() const explicit constexpr
- Boolean conversion.
Public functions
- auto operator==(const BigEnumSet<T, size>& other) const -> bool constexpr
- Equality comparison.
- auto operator!=(const BigEnumSet<T, size>& other) const -> bool constexpr
- Non-equality comparison.
-
auto data() const -> const std::
uint64_t* constexpr - Stored data.
- auto operator>=(const BigEnumSet<T, size>& other) const -> bool constexpr
- Whether
other
is a subset of this ( ) - auto operator<=(const BigEnumSet<T, size>& other) const -> bool constexpr
- Whether
other
is a superset of this ( ) - auto operator|(const BigEnumSet<T, size>& other) const -> BigEnumSet<T, size> constexpr
- Union of two sets.
- auto operator|=(const BigEnumSet<T, size>& other) -> BigEnumSet<T, size>&
- Union two sets and assign.
- auto operator&(const BigEnumSet<T, size>& other) const -> BigEnumSet<T, size> constexpr
- Intersection of two sets.
- auto operator&=(const BigEnumSet<T, size>& other) -> BigEnumSet<T, size>&
- Intersect two sets and assign.
- auto operator^(const BigEnumSet<T, size>& other) const -> BigEnumSet<T, size> constexpr
- XOR of two sets.
- auto operator^=(const BigEnumSet<T, size>& other) -> BigEnumSet<T, size>&
- XOR two sets and assign.
- auto operator~() const -> BigEnumSet<T, size> constexpr
- Set complement.
Enum documentation
template<class T, std:: size_t size>
enum Corrade:: Containers:: BigEnumSet<T, size>:: (anonymous): std:: size_t
Enumerators | |
---|---|
Size |
Count of 64-bit integers storing this set |
Function documentation
template<class T, std:: size_t size>
Corrade:: Containers:: BigEnumSet<T, size>:: BigEnumSet(Corrade:: NoInitT) explicit
Create an uninitialized set.
The contents are left in an undefined state.
template<class T, std:: size_t size>
Corrade:: Containers:: BigEnumSet<T, size>:: operator bool() const explicit constexpr
Boolean conversion.
Returns true
if at least one bit is set, false
otherwise.
template<class T, std:: size_t size>
const std:: uint64_t* Corrade:: Containers:: BigEnumSet<T, size>:: data() const constexpr
Stored data.
Returns an array of size Size.
template<class T, std:: size_t size>
bool Corrade:: Containers:: BigEnumSet<T, size>:: operator>=(const BigEnumSet<T, size>& other) const constexpr
Whether other
is a subset of this ( )
Equivalent to (a & other) == other
.
template<class T, std:: size_t size>
bool Corrade:: Containers:: BigEnumSet<T, size>:: operator<=(const BigEnumSet<T, size>& other) const constexpr
Whether other
is a superset of this ( )
Equivalent to (a & other) == a
.
#include <Corrade/Containers/BigEnumSet.hpp>
template<class T, std:: size_t size>
template<class T, std:: size_t size>
Utility:: Debug& bigEnumSetDebugOutput(Utility:: Debug& debug,
BigEnumSet<T, size> value,
const char* empty) new in Git master
Print a big enum set to debug output.
Parameters | |
---|---|
debug | Debug output |
value | Value to be printed |
empty | What to print in case of an empty enum set |
Compared to enumSetDebugOutput(), this function doesn't need an explicit list of known values but will instead go through all set bits and print them one by one. This also means unknown bits, if any, will be interleaved with the known ones. Example definition:
enum class Feature: std::uint8_t { Fast = 0, Cheap = 1, Tested = 2, Popular = 3 }; // already defined to print values as e.g. Feature::Fast and Features(0xab) // for unknown values Utility::Debug& operator<<(Utility::Debug&, Feature); typedef Containers::BigEnumSet<Feature> Features; CORRADE_ENUMSET_OPERATORS(Features) Utility::Debug& operator<<(Utility::Debug& debug, Features value) { return Containers::bigEnumSetDebugOutput(debug, value, "Features{}"); }
The output is then as follows:
// prints Feature::Fast|Feature::Cheap Utility::Debug{} << (Feature::Fast|Feature::Cheap); // prints Feature::Popular|Feature(0xca)|Feature(0xfe) Utility::Debug{} << (Feature::Popular|Feature(0xca)|Feature(0xfe)); // prints Features{} Utility::Debug{} << Features{};