9#include <AH/Error/Error.hpp>
33 bool get(uint16_t bitIndex)
const {
34 return buffer[getBufferIndex(bitIndex)] & getBufferMask(bitIndex);
43 void set(uint16_t bitIndex) {
44 buffer[getBufferIndex(bitIndex)] |= getBufferMask(bitIndex);
54 buffer[getBufferIndex(bitIndex)] &= ~getBufferMask(bitIndex);
65 void set(uint16_t bitIndex,
bool state) {
66 state ? set(bitIndex) : clear(bitIndex);
78 if (byteIndex >= getBufferLength()) {
79 ERROR(F(
"Error: index out of bounds (")
80 << byteIndex << F(
", length is ") << getBufferLength()
83 return getBufferLength() - 1;
99 const uint8_t &
getByte(uint16_t byteIndex)
const {
100 return buffer[byteIndex];
105 return buffer[byteIndex];
122 void setByte(uint16_t byteIndex, uint8_t value) {
123 buffer[byteIndex] = value;
133 return safeIndex(bitIndex / 8);
137 return 1 << getBufferBit(bitIndex);
140 constexpr static uint16_t bufferLength = (uint16_t)((N + 7) / 8);
141 uint8_t buffer[bufferLength] = {};
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
A class for arrays of bits.
void set(uint16_t bitIndex)
Set the value of the given bit to 1.
uint8_t getBufferMask(uint16_t bitIndex) const
uint8_t & getByte(uint16_t byteIndex)
Get the byte at the given index.
uint16_t safeIndex(uint16_t byteIndex) const
Check the given byte index, and return it if it is within the bounds of the array,...
void setByte(uint16_t byteIndex, uint8_t value)
Set the byte at the given index.
uint8_t getBufferBit(uint16_t bitIndex) const
uint16_t getBufferLength() const
Get the buffer length in bytes.
const uint8_t & getByte(uint16_t byteIndex) const
Get the byte at the given index.
void clear(uint16_t bitIndex)
Clear the value of the given bit to 0.
uint16_t getBufferIndex(uint16_t bitIndex) const
void set(uint16_t bitIndex, bool state)
Set the value of the given bit to the given state.
bool get(uint16_t bitIndex) const
Get the value of the given bit.