kmMqtt 0.0.1
MQTT Client Library
Loading...
Searching...
No Matches
kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize > Struct Template Reference

A utility class to manage flags within MQTT packets. More...

#include <Flags.h>

Public Member Functions

 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.

Detailed Description

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
TSizeTypeThe underlying type used to store the flags (e.g., uint8_t, uint16_t).
TFlagBitsEnumAn enumeration type representing the individual flag bits.
MaxFlagSizeThe maximum number of flags that can be represented.

Constructor & Destructor Documentation

◆ Flags()

template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >::Flags ( TSizeType flags)
inlinenoexcept

Constructs a Flags object with the given initial flag values.

Parameters
flagsThe initial flag values as a bitmask.

Member Function Documentation

◆ getFlags()

template<typename TSizeType, typename TFlagBitsEnum, std::size_t MaxFlagSize>
TSizeType kmMqtt::mqtt::Flags< TSizeType, TFlagBitsEnum, MaxFlagSize >::getFlags ( ) const
inline

Retrieves the current flag values as a bitmask.

Returns
The current flag values.

◆ getFlagValue()

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
EnumTThe enumeration type representing the flag bits.
TReturnTypeThe return type for the flag value.
Parameters
flagToCheckThe specific flag to retrieve within the bitmask.
Returns
The value of the specified flag.

◆ setFlagValue()

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
TSizeTypeThe underlying type used to store the flags.
Parameters
flagToSetThe specific flag to set within the bitmask.
valThe value to set for the specified flag.

◆ setMultipleFlagsValue()

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
flagToSetThe specific flags to set or clear within the bitmask.
valIf true, sets the specified flags; if false, clears them.

The documentation for this struct was generated from the following file:
  • D:/Dev/Repos/kmMqtt/include/public/kmMqtt/Mqtt/Packets/Flags.h