A bitset with enum items as flags. More...
#include <enumBitset.hpp>
Public Types | |
using | Enum = T_Enum |
See EnumBitset. | |
Public Member Functions | |
bool | any () |
Conversion to boolean. | |
EnumBitset ()=default | |
Constructor all false. | |
EnumBitset (Enum pos) | |
Constructor which sets one bit to true. | |
EnumBitset & | flip () |
Flip all bits. | |
EnumBitset & | flip (Enum pos) |
Flip the bit for the enum. | |
Bitset | getData () const |
Get the underlying bitset. | |
bool | operator!= (Enum const &pos) const |
Not equal operation for a bitset and an enum. | |
bool | operator!= (EnumBitset const &o) const |
Not equal operation for two bitsets. | |
EnumBitset & | operator&= (Enum const &pos) |
And operation of the bitsets and and enum. | |
EnumBitset & | operator&= (EnumBitset const &o) |
And operation of two bitsets. | |
bool | operator== (Enum const &pos) const |
Equal operation for a bitset and an enum. | |
bool | operator== (EnumBitset const &o) const |
Equal operation for two bitsets. | |
EnumBitset & | operator|= (Enum const &pos) |
Or operation of the bitset and an enum. | |
EnumBitset & | operator|= (EnumBitset const &o) |
Or operation of two bitsets. | |
EnumBitset & | reset () |
Reset all bits to false. | |
EnumBitset & | reset (Enum pos) |
Reset the bit for the enum to false. | |
EnumBitset & | set (Enum pos) |
Set the bit for the enum to true. | |
bool | test (Enum pos) const |
Test if the bit for the enum is set. | |
Static Public Member Functions | |
static constexpr EnumBitset | ALL () |
Constructor for a bitset with all values flagged as true. | |
static constexpr EnumBitset | NONE () |
Constructor for a bitset with all values flagged as false. | |
A bitset with enum items as flags.
The bitset implementation allows to use an enum class as flags without causing compiler warnings or having to cast the enum elements to integer types.
The enum needs to have a 'MaxElement' item and all elements need to be positive. An example definition is:
where the overloaded operator | is required to create a bitset out of two flags. An example use case is:
T_Enum | An enumeration class. It has to have the element 'MaxElement' and only positive values. |