Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qlibs::bitfield Class Reference

A BitField object. More...

#include <bitfield.hpp>

Inheritance diagram for qlibs::bitfield:

Public Member Functions

 bitfield ()=default
 
virtual ~bitfield ()
 
bool setup (void *const area, const size_t area_size) noexcept
 Setup a initialize a BitField instance.
 
template<size_t area_size>
bool setup (uint8_t(&area)[area_size])
 Setup a initialize a BitField instance.
 
bool clearAll (void) noexcept
 Clear all the bits in the BitField.
 
bool setAll (void) noexcept
 Set all the bits in the BitField.
 
bool setBit (const size_t index) noexcept
 Sets one bit in a BitField.
 
bool clearBit (const size_t index) noexcept
 Clears one bit in a BitField.
 
bool toggleBit (const size_t index) noexcept
 Toggles (i.e. reverses the state of) a bit in a BitField.
 
bool readBit (const size_t index) const noexcept
 Retrieve the state of a bit in a bitfield.
 
bool writeBit (const size_t index, const bool value) noexcept
 Writes one bit in a bitfield.
 
uint32_t readUINTn (const size_t index, const size_t xBits) const noexcept
 Reads an unsigned 32-bit value from the BitField.
 
bool writeUINTn (const size_t index, const size_t xBits, uint32_t value) noexcept
 Writes an unsigned n-bit value from the BitField.
 
float readFloat (const size_t index) const noexcept
 Reads a 32-bit floating point value from the BitField.
 
bool writeFloat (const size_t index, const float value) noexcept
 Writes a 32-bit floating point value to the BitField.
 
void * dump (void *const dst, const size_t n) noexcept
 Copies n bytes from the bit-field instance to a designed memory area.
 

Detailed Description

A BitField object.

Constructor & Destructor Documentation

◆ bitfield()

qlibs::bitfield::bitfield ( )
default

◆ ~bitfield()

virtual qlibs::bitfield::~bitfield ( )
inlinevirtual

Member Function Documentation

◆ clearAll()

bool bitfield::clearAll ( void )
noexcept

Clear all the bits in the BitField.

Returns
true on success, otherwise return false.

◆ clearBit()

bool bitfield::clearBit ( const size_t index)
noexcept

Clears one bit in a BitField.

Parameters
[in]indexThe bit-index.
Returns
true on success, otherwise return false.

◆ dump()

void * bitfield::dump ( void *const dst,
const size_t n )
noexcept

Copies n bytes from the bit-field instance to a designed memory area.

Parameters
[in]dstPointer to the destination array where the content is to be copied.
[in]nNumber of bytes to copy.
Returns
Destination is returned on success, otherwise nullptr.

◆ readBit()

bool bitfield::readBit ( const size_t index) const
noexcept

Retrieve the state of a bit in a bitfield.

Parameters
[in]indexThe bit-index.
Returns
The value of the bit at index.

◆ readFloat()

float bitfield::readFloat ( const size_t index) const
noexcept

Reads a 32-bit floating point value from the BitField.

Parameters
[in]indexThe bit-index taken as offset.
Returns
The floating point value from the BitField at the desired index

◆ readUINTn()

uint32_t bitfield::readUINTn ( const size_t index,
const size_t xBits ) const
noexcept

Reads an unsigned 32-bit value from the BitField.

Parameters
[in]indexThe bit-index taken as offset.
[in]xBitsThe number of bits to read. ( max allowed : 32 bits )
Returns
The value from the bitfield from the desired index

◆ setAll()

bool bitfield::setAll ( void )
noexcept

Set all the bits in the BitField.

Returns
true on success, otherwise return false.

◆ setBit()

bool bitfield::setBit ( const size_t index)
noexcept

Sets one bit in a BitField.

Parameters
[in]indexThe bit-index.
Returns
true on success, otherwise return false.

◆ setup() [1/2]

template<size_t area_size>
bool qlibs::bitfield::setup ( uint8_t(&) area[area_size])
inline

Setup a initialize a BitField instance.

Parameters
[in]areaThe memory block to hold the BitField. Should be an uint8_t array created with the bitArea<n> alias, where n, is the number of bits for the BitField.
Returns
true on success, otherwise return false.

◆ setup() [2/2]

bool bitfield::setup ( void *const area,
const size_t area_size )
noexcept

Setup a initialize a BitField instance.

Parameters
[in]areaThe memory block to hold the BitField. Should be an uint8_t array created with the bitArea<n> alias, where n, is the number of bits for the BitField.
[in]area_sizeThe number of bytes in area.
Returns
true on success, otherwise return false.

◆ toggleBit()

bool bitfield::toggleBit ( const size_t index)
noexcept

Toggles (i.e. reverses the state of) a bit in a BitField.

Parameters
[in]indexThe bit-index.
Returns
true on success, otherwise return false.

◆ writeBit()

bool bitfield::writeBit ( const size_t index,
const bool value )
noexcept

Writes one bit in a bitfield.

Parameters
[in]indexThe bit-index.
[in]valueThe boolean value to write.
Returns
true on success, otherwise return false.

◆ writeFloat()

bool bitfield::writeFloat ( const size_t index,
const float value )
noexcept

Writes a 32-bit floating point value to the BitField.

Parameters
[in]indexThe bit-index taken as offset.
[in]valueThe floating point value to write.
Returns
true on success, otherwise return false.

◆ writeUINTn()

bool bitfield::writeUINTn ( const size_t index,
const size_t xBits,
uint32_t value )
noexcept

Writes an unsigned n-bit value from the BitField.

Parameters
[in]indexThe bit-index taken as offset.
[in]valueThe value to write.
[in]xBitsThe number of bits to read. ( max allowed : 32 bits )
Returns
true on success, otherwise return false.