This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
BitArray< N > Class Template Reference

A class for arrays of bits. More...

#include <BitArray.hpp>

Collaboration diagram for BitArray< N >:

Public Member Functions

bool get (uint8_t bitIndex)
 Get the value of the given bit. More...
 
void set (uint8_t bitIndex)
 Set the value of the given bit to 1. More...
 
void clear (uint8_t bitIndex)
 Clear the value of the given bit to 0. More...
 
void set (uint8_t bitIndex, bool state)
 Set the value of the given bit to the given state. More...
 
uint8_t safeIndex (uint8_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. More...
 
uint8_t getByte (uint8_t byteIndex) const
 Get the byte at the given index. More...
 
uint8_t getBufferLength () const
 Get the buffer length in bytes. More...
 

Private Member Functions

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

Private Attributes

uint8_t buffer [bufferLength] = {}
 

Static Private Attributes

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

Detailed Description

template<uint8_t N>
class BitArray< N >

A class for arrays of bits.

Template Parameters
NThe number of bits.

Definition at line 18 of file BitArray.hpp.

Member Function Documentation

◆ get()

template<uint8_t N>
bool BitArray< N >::get ( uint8_t  bitIndex)
inline

Get the value of the given bit.

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

Definition at line 26 of file BitArray.hpp.

◆ set() [1/2]

template<uint8_t N>
void BitArray< N >::set ( uint8_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 36 of file BitArray.hpp.

◆ clear()

template<uint8_t N>
void BitArray< N >::clear ( uint8_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 46 of file BitArray.hpp.

◆ set() [2/2]

template<uint8_t N>
void BitArray< N >::set ( uint8_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 58 of file BitArray.hpp.

◆ safeIndex()

template<uint8_t N>
uint8_t BitArray< N >::safeIndex ( uint8_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 70 of file BitArray.hpp.

◆ getByte()

template<uint8_t N>
uint8_t BitArray< N >::getByte ( uint8_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 92 of file BitArray.hpp.

◆ getBufferLength()

template<uint8_t N>
uint8_t BitArray< N >::getBufferLength ( ) const
inline

Get the buffer length in bytes.

Definition at line 100 of file BitArray.hpp.

◆ getBufferIndex()

template<uint8_t N>
uint8_t BitArray< N >::getBufferIndex ( uint8_t  bitIndex) const
inlineprivate

Definition at line 103 of file BitArray.hpp.

◆ getBufferBit()

template<uint8_t N>
uint8_t BitArray< N >::getBufferBit ( uint8_t  bitIndex) const
inlineprivate

Definition at line 106 of file BitArray.hpp.

◆ getBufferMask()

template<uint8_t N>
uint8_t BitArray< N >::getBufferMask ( uint8_t  bitIndex) const
inlineprivate

Definition at line 107 of file BitArray.hpp.

Member Data Documentation

◆ bufferLength

template<uint8_t N>
constexpr static uint8_t BitArray< N >::bufferLength = (uint8_t)((N + 7) / 8)
staticconstexprprivate

Definition at line 111 of file BitArray.hpp.

◆ buffer

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

Definition at line 112 of file BitArray.hpp.


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