13#include <include/qlibs_types.hpp>
31 using bitArea = uint8_t[ 4U*( ( ( N - 1U )/32U ) + 1U ) ];
38 uint32_t *field{
nullptr };
41 static const size_t LBit;
42 inline uint32_t mask(
const size_t index )
noexcept
44 return static_cast<uint32_t
>( 1U ) << ( index % LBit );
46 inline size_t slot(
const size_t index )
const noexcept
50 inline uint32_t get(
const size_t index )
const noexcept
52 const size_t s = slot( index );
53 return ( field[ s ] >> ( index % LBit ) ) & 1U;
55 inline void set(
const size_t index )
noexcept
57 const size_t s = slot( index );
58 field[ s ] |= mask( index );
60 inline void clear(
const size_t index )
noexcept
62 const size_t s = slot( index );
64 field[ s ] &= ~mask( index );
66 inline void toggle(
const size_t index )
noexcept
68 const size_t s = slot( index );
70 field[ s ] ^= mask( index );
72 inline uint32_t safeMask(
const uint32_t val,
74 const size_t nbits )
const noexcept
76 return val >> (
static_cast<uint32_t
>( x - nbits ) );
78 inline size_t offset(
const size_t index )
const noexcept
80 return index &
static_cast<size_t>( 31U );
82 inline uint32_t maskMerge(
const uint32_t w,
84 const uint32_t mask )
noexcept
86 return value ^ ( ( w ^ value ) & mask );
89 uint32_t read_uint32(
const size_t index )
const noexcept;
90 void write_uint32(
const size_t index,
91 const uint32_t value )
noexcept;
105 bool setup(
void *
const area,
106 const size_t area_size )
noexcept;
115 template<
size_t area_size>
116 bool setup( uint8_t ( &area )[ area_size ] )
118 return setup( area, area_size );
131 bool setAll(
void )
noexcept;
138 bool setBit(
const size_t index )
noexcept;
145 bool clearBit(
const size_t index )
noexcept;
152 bool toggleBit(
const size_t index )
noexcept;
159 bool readBit(
const size_t index )
const noexcept;
168 const bool value )
noexcept;
177 const size_t xBits )
const noexcept;
188 uint32_t value )
noexcept;
195 float readFloat(
const size_t index )
const noexcept;
204 const float value )
noexcept;
214 void*
dump(
void *
const dst,
215 const size_t n )
noexcept;
A BitField object.
Definition bitfield.hpp:36
uint32_t readUINTn(const size_t index, const size_t xBits) const noexcept
Reads an unsigned 32-bit value from the BitField.
Definition bitfield.cpp:113
bool clearAll(void) noexcept
Clear all the bits in the BitField.
Definition bitfield.cpp:25
bool clearBit(const size_t index) noexcept
Clears one bit in a BitField.
Definition bitfield.cpp:60
bool setup(uint8_t(&area)[area_size])
Setup a initialize a BitField instance.
Definition bitfield.hpp:116
bool readBit(const size_t index) const noexcept
Retrieve the state of a bit in a bitfield.
Definition bitfield.cpp:84
bool setup(void *const area, const size_t area_size) noexcept
Setup a initialize a BitField instance.
Definition bitfield.cpp:8
bool writeFloat(const size_t index, const float value) noexcept
Writes a 32-bit floating point value to the BitField.
Definition bitfield.cpp:177
void * dump(void *const dst, const size_t n) noexcept
Copies n bytes from the bit-field instance to a designed memory area.
Definition bitfield.cpp:193
bool writeBit(const size_t index, const bool value) noexcept
Writes one bit in a bitfield.
Definition bitfield.cpp:95
float readFloat(const size_t index) const noexcept
Reads a 32-bit floating point value from the BitField.
Definition bitfield.cpp:163
virtual ~bitfield()
Definition bitfield.hpp:95
bool toggleBit(const size_t index) noexcept
Toggles (i.e. reverses the state of) a bit in a BitField.
Definition bitfield.cpp:72
bool setAll(void) noexcept
Set all the bits in the BitField.
Definition bitfield.cpp:36
bool writeUINTn(const size_t index, const size_t xBits, uint32_t value) noexcept
Writes an unsigned n-bit value from the BitField.
Definition bitfield.cpp:134
bool setBit(const size_t index) noexcept
Sets one bit in a BitField.
Definition bitfield.cpp:48
uint8_t[4U *(((N - 1U)/32U)+1U)] bitArea
Variable that allocates block of bytes to hold N bits for a BitField .
Definition bitfield.hpp:31
The qLibs++ library namespace.
Definition fp16.cpp:4