The Flags class is a wrapper around a enum that allows bitwise operations (flags). OT_ADD_FLAG_FUNCTIONS or custom bitwise operations must be provided for the enum. The type should be an enumeration where every value represents a single bit in a 32/64 bit value. More...
#include "Flags.h"
Public Member Functions | |
Flags () | |
Data. | |
Flags (T _initialData) | |
Assignment constructor. | |
Flags (const Flags< T > &_other) | |
Copy constructor. | |
Flags (Flags &&_other) noexcept | |
Move constructor. | |
T | data (void) const |
Returns a copy of the data. | |
void | set (T _data) |
Replace the current data. | |
void | setFlag (T _flag) |
Set the provided flag. | |
void | setFlag (T _flag, bool _flagIsSet) |
Set or remove the provided flag. | |
void | removeFlag (T _flag) |
Remove the provided flag. | |
bool | flagIsSet (T _flag) const |
Returns true if the provided flag is set. | |
operator T (void) const | |
Operator T is used to assign the Flags to a enum variable with the same type that is managed by Flags. | |
operator bool (void) const | |
Returns true if at least one flag is set (assuming 0 = no flags). | |
Flags< T > & | operator= (T _flag) |
Flags< T > & | operator= (const Flags< T > &_other) |
Flags< T > & | operator= (Flags< T > &&_other) |
Flags< T > | operator| (T _flag) const |
Flags< T > | operator| (const Flags< T > &_other) const |
Flags< T > | operator& (T _flag) const |
Flags< T > | operator& (const Flags< T > &_other) const |
Flags< T > & | operator|= (T _flag) |
Flags< T > & | operator|= (const Flags< T > &_other) |
Flags< T > & | operator&= (T _flag) |
Flags< T > & | operator&= (const Flags< T > &_other) |
Flags< T > | operator~ (void) const |
bool | operator== (T _flag) const |
bool | operator== (const Flags< T > &_other) const |
bool | operator!= (T _flag) const |
bool | operator!= (const Flags< T > &_other) const |
The Flags class is a wrapper around a enum that allows bitwise operations (flags). OT_ADD_FLAG_FUNCTIONS or custom bitwise operations must be provided for the enum. The type should be an enumeration where every value represents a single bit in a 32/64 bit value.
// This enum contains values represeting single bits, // or masks used for bitwise operations. enum EnumName { // This should always be provided as somewhat of default value, // since ot::Flags<EnumName> will assume 0x00 to be the default. // // +------+------+---------+ // // | Hex | Bin | Info | // // +------+------+---------+ EmptyFlags = 0 << 0, // | 0x00 | 0000 | Default | EnumValue1 = 1 << 0, // | 0x01 | 0001 | Value 1 | EnumValue2 = 1 << 1, // | 0x02 | 0010 | Value 2 | EnumMask1 = EnumValue1 | EnumValue2 // | 0x03 | 0011 | Mask 1 | EnumValue3 = 1 << 2, // | 0x04 | 0100 | Value 3 | ... // +------+------+---------+ };
|
inline |
Data.
Default constructor. Initializes the data with 0.
|
inline |
Assignment constructor.
_initialData | Initial data. |
Copy constructor.
_other | Other flags. |
Move constructor.
_other | Other flags. |
|
inline |
Returns a copy of the data.
|
inline |
Returns true if the provided flag is set.
_flag | the flag that should be checked |
|
inline |
Returns true if at least one flag is set (assuming 0 = no flags).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Remove the provided flag.
_flag | The flag to remove |
|
inline |
Replace the current data.
_data | The data that should be replaced with |
|
inline |
Set the provided flag.
_flag | The flag to set |
|
inline |
Set or remove the provided flag.
_flag | The flag to set |
_flagIsSet | If true the flag will be set, otherwise removed |