jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
|
Simple statically sized bitfield template for efficient bit storage access in O(1). More...
#include <bitfield.hpp>
Public Types | |
typedef size_t | size_type |
size_t data type, bit position and count | |
typedef StorageType | unit_type |
Unit data type. | |
Public Member Functions | |
constexpr | bitfield_t () noexcept |
Constructs an empty bitfield instance. | |
bitfield_t (std::string_view bitstr) | |
Constructs a bitfield instance, initialized with bitstr msb bit-pattern. | |
constexpr void | clear () noexcept |
constexpr bool | clr (size_type bitpos) noexcept |
Clear the bit at position bitpos of this storage. | |
bool | copy (size_type srcBitpos, size_type dstBitpos) noexcept |
Copies the bit at position srcBitpos to position dstBitpos , returning the copied bit-value. | |
bool | copyUnit (size_type srcBitpos, size_type dstBitpos, size_type length) noexcept |
Copies length bits at position srcBitpos to position dstBitpos , returning the copied bits. | |
size_type | count () const noexcept |
constexpr bitfield_t & | flip () noexcept |
constexpr bool | flip (size_type bitpos) noexcept |
Flips the bit value at position bitpos in this storage. | |
constexpr bool | get (size_type bitpos) const noexcept |
unit_type | getUnit (size_type bitpos, size_type length) const noexcept |
std::string | infoString () const noexcept |
constexpr bool | operator== (const bitfield_t &rhs) const noexcept |
constexpr bool | operator[] (size_type bitpos) const noexcept |
template<size_t OBitSize> | |
bool | put (size_t bitpos, const bitfield_t< StorageType, OBitSize > &o) |
constexpr bool | put (size_type bitpos, bool v) noexcept |
Writes the bit value v to position bitpos into this storage. | |
bool | put (size_type bitpos, std::string_view bitstr) noexcept |
Writes bitstr msb bit-pattern into this storage, starting with the lowest bit from the storage position bitpos . | |
bool | putUnit (size_type bitpos, size_type length, unit_type data) noexcept |
Writes length bits of given data into this storage, starting with the lowest bit from the storage position bitpos . | |
constexpr bitfield_t & | reset () noexcept |
constexpr bool | reset (size_type bitpos) noexcept |
Clear the bit at position bitpos of this storage. | |
constexpr bitfield_t & | reverse () noexcept |
constexpr bool | set (size_type bitpos) noexcept |
Sets the bit at position bitpos of this storage. | |
bool | set (size_type bitpos, size_type length, bool bit) noexcept |
Set length bits starting at bitpos of this bitfield to the given value bit . | |
bitfield_t & | setAll (bool bit) noexcept |
Set all bits of this bitfield to the given value bit . | |
constexpr size_type | size () const noexcept |
Returns storage size in bits. | |
template<size_t BitLength> | |
std::pair< bitfield_t< StorageType, BitLength >, bool > | subbits (size_type bitpos) const noexcept |
std::string | toString (PrefixOpt prefix=PrefixOpt::none) const noexcept |
std::string | toString (size_type bitpos, size_type length, PrefixOpt prefix=PrefixOpt::none) const noexcept |
Static Public Member Functions | |
static constexpr bool | in_range (size_type bitpos) |
static constexpr bool | in_range (size_type bitpos, size_type length) |
Static Public Attributes | |
static constexpr size_type | bit_size = BitSize |
Storage size in bits. | |
static constexpr size_type | unit_bit_size = unit_byte_size * CHAR_BIT |
One unit size in bits. | |
static constexpr size_type | unit_byte_size = sizeof(unit_type) |
One unit size in bytes. | |
static constexpr size_type | unit_shift = jau::log2_byteshift(unit_byte_size) |
One unit shift amount. | |
static constexpr size_type | unit_size = std::max<size_type>(1, (bit_size + unit_bit_size - 1) >> unit_shift) |
Storage size in units. | |
Simple statically sized bitfield template for efficient bit storage access in O(1).
Bit-position and bit-order are in least-significant-bits (lsb) first.
Implementations utilizes an in-memory std::array<StorageType, (BitSize+31)/32>
with unsigned integral StorageType of sizeof(StorageType) <= sizeof(size_t).
Similar to std::bitset, but providing custom methods.
Definition at line 53 of file bitfield.hpp.
typedef StorageType jau::bitfield_t< StorageType, BitSize >::unit_type |
Unit data type.
Definition at line 55 of file bitfield.hpp.
typedef size_t jau::bitfield_t< StorageType, BitSize >::size_type |
size_t data type, bit position and count
Definition at line 56 of file bitfield.hpp.
|
inlineconstexprnoexcept |
Constructs an empty bitfield instance.
Definition at line 81 of file bitfield.hpp.
|
inline |
Constructs a bitfield instance, initialized with bitstr
msb bit-pattern.
bitstr | most-significat (msb) bit string pattern |
jau::IllegalArgumentError | if bitstr put failed |
Definition at line 89 of file bitfield.hpp.
|
inlineconstexprnoexcept |
Returns storage size in bits.
Definition at line 63 of file bitfield.hpp.
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
Definition at line 76 of file bitfield.hpp.
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Definition at line 107 of file bitfield.hpp.
|
inlineconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Writes the bit value v
to position bitpos
into this storage.
Definition at line 122 of file bitfield.hpp.
|
inlinenodiscardconstexprnoexcept |
Flips the bit value at position bitpos
in this storage.
Definition at line 140 of file bitfield.hpp.
|
inlineconstexprnoexcept |
Definition at line 155 of file bitfield.hpp.
|
inlineconstexprnoexcept |
|
inlinenodiscardconstexprnoexcept |
Sets the bit at position bitpos
of this storage.
Definition at line 191 of file bitfield.hpp.
|
inlinenodiscardconstexprnoexcept |
Clear the bit at position bitpos
of this storage.
Definition at line 196 of file bitfield.hpp.
|
inlinenodiscardconstexprnoexcept |
Clear the bit at position bitpos
of this storage.
Definition at line 201 of file bitfield.hpp.
|
inlinenodiscardnoexcept |
Copies the bit at position srcBitpos
to position dstBitpos
, returning the copied bit-value.
Definition at line 207 of file bitfield.hpp.
|
inlinenoexcept |
|
inlinenodiscardnoexcept |
Writes length
bits of given data
into this storage, starting with the lowest bit from the storage position bitpos
.
Definition at line 242 of file bitfield.hpp.
|
inlinenodiscardnoexcept |
Writes bitstr
msb bit-pattern into this storage, starting with the lowest bit from the storage position bitpos
.
bitpos | bit position to insert |
bitstr | most-significat (msb) bit string pattern |
Definition at line 278 of file bitfield.hpp.
|
inlinenodiscardnoexcept |
Set length
bits starting at bitpos
of this bitfield to the given value bit
.
Definition at line 304 of file bitfield.hpp.
|
inlinenoexcept |
Set all bits of this bitfield to the given value bit
.
Definition at line 342 of file bitfield.hpp.
|
inlinenodiscardnoexcept |
Copies length
bits at position srcBitpos
to position dstBitpos
, returning the copied bits.
Definition at line 351 of file bitfield.hpp.
|
inlinenoexcept |
|
inlineconstexprnoexcept |
Definition at line 363 of file bitfield.hpp.
|
inlinenodiscard |
Definition at line 378 of file bitfield.hpp.
|
inlinenodiscardnoexcept |
Definition at line 410 of file bitfield.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 471 of file bitfield.hpp.
|
inlinenoexcept |
Definition at line 475 of file bitfield.hpp.
|
staticconstexpr |
One unit size in bytes.
Definition at line 57 of file bitfield.hpp.
|
staticconstexpr |
One unit size in bits.
Definition at line 58 of file bitfield.hpp.
|
staticconstexpr |
One unit shift amount.
Definition at line 59 of file bitfield.hpp.
|
staticconstexpr |
Storage size in bits.
Definition at line 60 of file bitfield.hpp.
|
staticconstexpr |
Storage size in units.
Definition at line 66 of file bitfield.hpp.