|
| | Flags (TSizeType flags) noexcept |
| | Constructs a Flags object with the given initial flag values.
|
| TSizeType | getFlags () const |
| | Retrieves the current flag values as a bitmask.
|
| template<typename EnumT = TFlagBitsEnum, typename TReturnType = TSizeType> |
| TReturnType | getFlagValue (const EnumT &flagToCheck) const |
| | Retrieves the value of a specific flag.
|
| void | setFlagValue (const TFlagBitsEnum &flagToSet, TSizeType val) |
| | Sets the value of a specific flag.
|
| void | setMultipleFlagsValue (const TFlagBitsEnum &flagToSet, bool val) |
| | Sets or clears multiple flags based on a boolean value.
|
template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
struct kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >
A utility class to manage flags within MQTT packets.
This class allows for setting, getting, and overriding flag values. It uses a bitmask approach to store multiple flags in a single underlying type. Can use enum to define the flag bits.
- Parameters
-
| TSizeType | The underlying type used to store the flags (e.g., uint8_t, uint16_t). |
| TFlagBitsEnum | An enumeration type representing the individual flag bits. |
| MaxFlagSize | The maximum number of flags that can be represented. |
template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
template<typename EnumT = TFlagBitsEnum, typename TReturnType = TSizeType>
| TReturnType kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >::getFlagValue |
( |
const EnumT & | flagToCheck | ) |
const |
|
inline |
Retrieves the value of a specific flag.
Can retrieve values larger than 1 for multi-bit flags aslong as the flag is defined as contiguous bits. For example, if the flag is defined as 0b00000110, this method can return values from 0 to 3 for the two bits that are positive (2 bits = 4 values: 00, 01, 10, 11) if the flag to check is passed in as such.
- Template Parameters
-
| EnumT | The enumeration type representing the flag bits. |
| TReturnType | The return type for the flag value. |
- Parameters
-
| flagToCheck | The specific flag to retrieve within the bitmask. |
- Returns
- The value of the specified flag.
template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
| void kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >::setFlagValue |
( |
const TFlagBitsEnum & | flagToSet, |
|
|
TSizeType | val ) |
|
inline |
Sets the value of a specific flag.
Can pass in values larger than 1 for multi-bit flags aslong as the flag is defined as contiguous bits. For example, if the flag is defined as 0b00000110, this method can accept values from 0 to 3 for the two bits that are positive (2 bits = 4 values: 00, 01, 10, 11) if the flag to set is passed in as such.
- Template Parameters
-
| TSizeType | The underlying type used to store the flags. |
- Parameters
-
| flagToSet | The specific flag to set within the bitmask. |
| val | The value to set for the specified flag. |
template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
| void kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >::setMultipleFlagsValue |
( |
const TFlagBitsEnum & | flagToSet, |
|
|
bool | val ) |
|
inline |
Sets or clears multiple flags based on a boolean value.
For example, if the flagToSet is 0b00000110 and val is true, both bits will be set to 1 (0b00000110). The rest of the bits will remain unchanged. If val is false, both bits will be cleared to 0 (0b00000000).
- Parameters
-
| flagToSet | The specific flags to set or clear within the bitmask. |
| val | If true, sets the specified flags; if false, clears them. |