Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
BitmaskVarSize Class Reference

Class that holds a bitmask of variable size. More...

#include <cs_BitmaskVarSize.h>

Public Member Functions

 BitmaskVarSize ()
 
 ~BitmaskVarSize ()
 
bool setNumBits (uint8_t numBits)
 Set new number of bits. More...
 
bool setBit (uint8_t bit)
 Set Nth bit. More...
 
bool clearBit (uint8_t bit)
 Clear Nth bit. More...
 
bool isSet (uint8_t bit)
 Check if Nth bit is set. More...
 
void clearAllBits ()
 Clear all bits. More...
 
bool isAllBitsSet ()
 Check if all bits are set. More...
 

Protected Member Functions

uint8_t getNumBytes (uint8_t numBits)
 Get number of bytes required to store given number of bits. More...
 

Protected Attributes

uint8_t _numBits = 0
 
uint8_t * _bitmask = nullptr
 Bitmask. More...
 

Detailed Description

Class that holds a bitmask of variable size.

Optimized for calling isAllBitsSet() more often than clearAllBits().

Constructor & Destructor Documentation

◆ BitmaskVarSize()

◆ ~BitmaskVarSize()

BitmaskVarSize::~BitmaskVarSize ( )

Member Function Documentation

◆ clearAllBits()

void BitmaskVarSize::clearAllBits ( )

Clear all bits.

◆ clearBit()

bool BitmaskVarSize::clearBit ( uint8_t  bit)

Clear Nth bit.

◆ getNumBytes()

uint8_t BitmaskVarSize::getNumBytes ( uint8_t  numBits)
protected

Get number of bytes required to store given number of bits.

◆ isAllBitsSet()

bool BitmaskVarSize::isAllBitsSet ( )

Check if all bits are set.

◆ isSet()

bool BitmaskVarSize::isSet ( uint8_t  bit)

Check if Nth bit is set.

◆ setBit()

bool BitmaskVarSize::setBit ( uint8_t  bit)

Set Nth bit.

◆ setNumBits()

bool BitmaskVarSize::setNumBits ( uint8_t  numBits)

Set new number of bits.

All bits will be cleared.

Returns true on success. Returns false when failed, new number of bits will then be 0.

Member Data Documentation

◆ _bitmask

uint8_t* BitmaskVarSize::_bitmask = nullptr
protected

Bitmask.

Looks like: byte 0: [ 7 6 5 4 3 2 1 0] byte 1: [15 14 13 12 11 10 9 8] byte 2: [23 22 21 20 19 18 17 16] So if you want 17 bits, then you need 3 bytes. So (17 / 8) rounded up. And to get bit 10, you need byte 1, shift by 2. So byte (10 / 8) rounded down, shifted by (10 % 8)

◆ _numBits

uint8_t BitmaskVarSize::_numBits = 0
protected

The documentation for this class was generated from the following file: