Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
BitArray< N > Class Template Reference

#include <AH/Containers/BitArray.hpp>

Detailed Description

template<uint16_t N>
class AH::BitArray< N >

A class for arrays of bits.

Template Parameters
NThe number of bits.

Definition at line 21 of file BitArray.hpp.

+ Collaboration diagram for BitArray< N >:

Public Member Functions

bool get (uint16_t bitIndex) const
 Get the value of the given bit.
 
void set (uint16_t bitIndex)
 Set the value of the given bit to 1.
 
void clear (uint16_t bitIndex)
 Clear the value of the given bit to 0.
 
void set (uint16_t bitIndex, bool state)
 Set the value of the given bit to the given state.
 
uint16_t safeIndex (uint16_t byteIndex) const
 Check the given byte index, and return it if it is within the bounds of the array, otherwise, throw an error, and return the last valid index.
 
const uint8_tgetByte (uint16_t byteIndex) const
 Get the byte at the given index.
 
uint8_tgetByte (uint16_t byteIndex)
 Get the byte at the given index.
 
void setByte (uint16_t byteIndex, uint8_t value)
 Set the byte at the given index.
 
uint16_t getBufferLength () const
 Get the buffer length in bytes.
 

Private Member Functions

uint16_t getBufferIndex (uint16_t bitIndex) const
 
uint8_t getBufferBit (uint16_t bitIndex) const
 
uint8_t getBufferMask (uint16_t bitIndex) const
 

Private Attributes

uint8_t buffer [bufferLength] = {}
 

Static Private Attributes

static constexpr uint16_t bufferLength = (uint16_t)((N + 7) / 8)
 

Member Function Documentation

◆ get()

template<uint16_t N>
bool get ( uint16_t bitIndex) const
inline

Get the value of the given bit.

Parameters
bitIndexThe (zero-based) index of the bit to read.

Definition at line 29 of file BitArray.hpp.

◆ set() [1/2]

template<uint16_t N>
void set ( uint16_t bitIndex)
inline

Set the value of the given bit to 1.

Parameters
bitIndexThe (zero-based) index of the bit to set.

Definition at line 39 of file BitArray.hpp.

◆ clear()

template<uint16_t N>
void clear ( uint16_t bitIndex)
inline

Clear the value of the given bit to 0.

Parameters
bitIndexThe (zero-based) index of the bit to clear.

Definition at line 49 of file BitArray.hpp.

◆ set() [2/2]

template<uint16_t N>
void set ( uint16_t bitIndex,
bool state )
inline

Set the value of the given bit to the given state.

Parameters
bitIndexThe (zero-based) index of the bit to set.
stateThe value to set the bit to.

Definition at line 61 of file BitArray.hpp.

◆ safeIndex()

template<uint16_t N>
uint16_t safeIndex ( uint16_t byteIndex) const
inline

Check the given byte index, and return it if it is within the bounds of the array, otherwise, throw an error, and return the last valid index.

Parameters
byteIndexThe index to check.

Definition at line 73 of file BitArray.hpp.

◆ getByte() [1/2]

template<uint16_t N>
const uint8_t & getByte ( uint16_t byteIndex) const
inline

Get the byte at the given index.

This function can be used to quickly access all of the bits, to send them out to a shift register, for example.

Note
No bounds checking is performed.
Parameters
byteIndexThe index of the byte within the array.

Definition at line 95 of file BitArray.hpp.

◆ getByte() [2/2]

template<uint16_t N>
uint8_t & getByte ( uint16_t byteIndex)
inline

Get the byte at the given index.

This function can be used to quickly access all of the bits, to send them out to a shift register, for example.

Note
No bounds checking is performed.
Parameters
byteIndexThe index of the byte within the array.

Definition at line 100 of file BitArray.hpp.

◆ setByte()

template<uint16_t N>
void setByte ( uint16_t byteIndex,
uint8_t value )
inline

Set the byte at the given index.

This function can be used to quickly write all of the bits, when reading them in from an I/O expander, for example.

Note
No bounds checking is performed.
Parameters
byteIndexThe index of the byte within the array.
valueThe byte to write.

Definition at line 118 of file BitArray.hpp.

◆ getBufferLength()

template<uint16_t N>
uint16_t getBufferLength ( ) const
inline

Get the buffer length in bytes.

Definition at line 125 of file BitArray.hpp.

◆ getBufferIndex()

template<uint16_t N>
uint16_t getBufferIndex ( uint16_t bitIndex) const
inlineprivate

Definition at line 128 of file BitArray.hpp.

◆ getBufferBit()

template<uint16_t N>
uint8_t getBufferBit ( uint16_t bitIndex) const
inlineprivate

Definition at line 131 of file BitArray.hpp.

◆ getBufferMask()

template<uint16_t N>
uint8_t getBufferMask ( uint16_t bitIndex) const
inlineprivate

Definition at line 132 of file BitArray.hpp.

Member Data Documentation

◆ bufferLength

template<uint16_t N>
constexpr uint16_t bufferLength = (uint16_t)((N + 7) / 8)
staticconstexprprivate

Definition at line 136 of file BitArray.hpp.

◆ buffer

template<uint16_t N>
uint8_t buffer[bufferLength] = {}
private

Definition at line 137 of file BitArray.hpp.


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