![]() |
PIDUINO
|
A type-safe flags class for bitwise operations on enum values. More...
#include <flags.h>
Public Member Functions | |
| Flags (Underlying original=0) | |
| Default constructor that initializes flags with a given value. | |
| Flags (const Flags &original) | |
| Copy constructor that creates a new Flags object from an existing one. | |
| Flags & | operator|= (const Flags &f) |
| Bitwise OR assignment operator. Combines this flags object with another using bitwise OR operation. | |
| Flags & | operator^= (const Flags &f) |
| Bitwise XOR assignment operator. Combines this flags object with another using bitwise XOR operation. | |
| Flags & | operator&= (const Flags &f) |
| Bitwise AND assignment operator. Combines this flags object with another using bitwise AND operation. | |
| Flags | operator~ () const |
| Bitwise NOT operator that inverts all bits in the flags. | |
| operator RestrictedBool () const | |
| Safe boolean conversion operator. Allows the Flags object to be used in boolean contexts without allowing implicit conversion to other types. | |
| bool | operator== (const Flags &other) |
| Equality comparison operator. | |
| bool | operator!= (const Flags &other) |
| Inequality comparison operator. | |
| void | setFlags (Underlying flags) |
| Sets multiple flags using bitwise OR operation. | |
| void | setFlag (EnumType singleFlag) |
| Sets a single flag using bitwise OR operation. | |
| void | clearFlags (Underlying flags) |
| Clears multiple flags using bitwise AND with complement. | |
| void | clearFlag (EnumType singleFlag) |
| Clears a single flag using bitwise AND with complement. | |
| Underlying | value () const |
| Gets the raw underlying value of the flags. | |
Protected Attributes | |
| Underlying | m_flags |
| The underlying storage for the flag bits. | |
Private Types | |
| typedef Underlying Flags::* | RestrictedBool |
| Restricted bool type for safe boolean conversion. | |
A type-safe flags class for bitwise operations on enum values.
This template class provides a type-safe way to handle bitwise operations on enumeration values. It allows combining multiple enum flags using bitwise operators while maintaining type safety and preventing accidental operations between incompatible types.
| EnumType | The enumeration type that defines the individual flags |
| Underlying | The underlying integral type used to store the flags (default: int) |
|
private |
|
inline |
|
inline |
|
inline |
Clears a single flag using bitwise AND with complement.
| singleFlag | The individual flag to clear (as enum value) |
Definition at line 182 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::clearFlags().
|
inline |
Clears multiple flags using bitwise AND with complement.
| flags | The flags to clear (as underlying type value) |
Definition at line 174 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
Referenced by Piduino::Flags< EnumType, Underlying >::clearFlag().
|
inline |
Safe boolean conversion operator. Allows the Flags object to be used in boolean contexts without allowing implicit conversion to other types.
Definition at line 132 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Inequality comparison operator.
| other | The Flags object to compare with |
Definition at line 150 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Bitwise AND assignment operator. Combines this flags object with another using bitwise AND operation.
| f | The flags object to combine with |
Definition at line 81 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Equality comparison operator.
| other | The Flags object to compare with |
Definition at line 141 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Bitwise XOR assignment operator. Combines this flags object with another using bitwise XOR operation.
| f | The flags object to combine with |
Definition at line 70 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Bitwise OR assignment operator. Combines this flags object with another using bitwise OR operation.
| f | The flags object to combine with |
Definition at line 59 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Bitwise NOT operator that inverts all bits in the flags.
Definition at line 120 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
inline |
Sets a single flag using bitwise OR operation.
| singleFlag | The individual flag to set (as enum value) |
Definition at line 166 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::setFlags().
|
inline |
Sets multiple flags using bitwise OR operation.
| flags | The flags to set (as underlying type value) |
Definition at line 158 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
Referenced by Piduino::Flags< EnumType, Underlying >::setFlag().
|
inline |
Gets the raw underlying value of the flags.
Definition at line 190 of file flags.h.
References Piduino::Flags< EnumType, Underlying >::m_flags.
|
protected |
The underlying storage for the flag bits.
Definition at line 196 of file flags.h.
Referenced by Piduino::Flags< EnumType, Underlying >::clearFlags(), Piduino::Flags< EnumType, Underlying >::operator RestrictedBool(), Piduino::Flags< EnumType, Underlying >::operator!=(), Piduino::Flags< EnumType, Underlying >::operator&=(), Piduino::Flags< EnumType, Underlying >::operator==(), Piduino::Flags< EnumType, Underlying >::operator^=(), Piduino::Flags< EnumType, Underlying >::operator|=(), Piduino::Flags< EnumType, Underlying >::operator~(), Piduino::Flags< EnumType, Underlying >::setFlags(), and Piduino::Flags< EnumType, Underlying >::value().