42 "Unsupported size of C++ int type" );
110 || (startIdx.pos ==
pos && startIdx.bit <
bit),
"BITBUFFER",
111 "Given buffer start index is greater than this index." )
148 "BITBUFFER",
"32bit too narrow for endcoding BitBuffer::Index." )
205 return !(*
this == rhs);
240 return !(*
this < rhs);
251 return !(*
this <= rhs);
342 return reinterpret_cast<char*
>( &
data[idx.pos] );
397 const Index& endIndex );
459 if( capacityNeeded >
storage.capacity() )
490 :
ma( monoAllocator )
519 if( capacityNeeded >
storage.capacity() )
547template<u
integer TCapacity>
585 if( capacityNeeded > TCapacity )
587 ALIB_ERROR(
"BITBUFFER",
"Local bit buffer cannot expand its capacity" )
636 return idx.CountBits();
644 return bb.RemainingSize(
idx);
729 template<ShiftOpRHS TW
idth,
typename TIntegral,
bool TMaskValue= false>
733 template<lang::ShiftOpRHS TW
idth,
typename TValue,
bool TMaskValue= false>
734 requires ( std::unsigned_integral<TValue>
735 && !std::same_as < TValue, bool>
737 void Write(TValue value )
739 static_assert(
bitsof(TValue) >= TWidth,
"Fixed size given greater than value type.");
742 || TWidth ==
bitsof(TValue)
743 || value == (value &
lang::LowerMask<TValue>(TWidth) ),
"BITBUFFER",
744 "Upper bits dirty while TMaskValue flag not set." )
746 if constexpr ( (TWidth <
bitsof(TValue)) && TMaskValue )
747 value&=
lang::LowerMask<TWidth, TValue >();
763 template<lang::ShiftOpRHS TW
idth,
typename TValue,
bool TMaskValue= false>
764 requires ( std::unsigned_integral<TValue>
765 && !std::same_as < TValue, bool>
767 void Write(TValue value )
769 static_assert(
bitsof(TValue) >= TWidth,
"Fixed size given greater than value type.");
772 || TWidth ==
bitsof(TValue)
773 || value == (value &
lang::LowerMask<TValue>(TWidth) ),
"BITBUFFER",
774 "Upper bits dirty while TMaskValue not set." )
776 if constexpr ( (TWidth <
bitsof(TValue)) && TMaskValue )
777 value&=
lang::LowerMask<TWidth, TValue>();
781 value>>= bitsWritten;
788 if(bitsWritten >= TWidth )
804 template<lang::ShiftOpRHS TW
idth,
typename TValue,
bool TMaskValue= false>
805 requires ( std::signed_integral<TValue> && !std::same_as<TValue, bool> )
806 void Write( TValue value)
808 using TUI=
typename std::make_unsigned<TValue>::type;
812 template<
typename TValue>
813 requires ( std::same_as<TValue, bool> )
814 void Write( TValue value)
836 template<
typename TValue,
bool TMaskValue= false>
837 requires ( std::integral<TValue> && (
sizeof(TValue) <=
sizeof(
TStorage) ) )
842 "BITBUFFER",
"BitBufferBase::Write: Width too high: ", width )
847 "BITBUFFER",
"Upper bits dirty while TMaskValue not set.")
849 if constexpr (TMaskValue)
850 if( width <
bitsof(TValue) )
878 template<
typename TValue,
bool TMaskValue= false>
879 requires ( std::integral<TValue> && (
sizeof(TValue) >
sizeof(
TStorage) ) )
884 "BitBufferBase::Write: Width too high: ", width )
888 "BITBUFFER",
"Upper bits dirty while TMaskValue not set.")
890 if constexpr (TMaskValue)
891 if( width <=
bitsof(TValue) )
912 value>>= bitsWritten;
919 if(bitsWritten >= width )
957 template<
typename TUIntegral>
958 requires ( std::unsigned_integral<TUIntegral> && !std::same_as< TUIntegral, bool> )
976 template<
typename TSIntegral>
977 requires ( std::signed_integral<TSIntegral> && !std::same_as< TSIntegral, bool> )
981 using TUnsigned=
typename std::make_unsigned<TSIntegral>::type;
983 : TUnsigned( (TUnsigned(-(value+ 1)) << 1) | 1 ) );
1047 "BitBufferBase overflow detected. Ensure a higher capacity" )
1090 template<lang::ShiftOpRHS TW
idth,
typename TResult=
int>
1091 requires ( std::integral<TResult> && ( TWidth <=
bitsof(
TStorage)) )
1099 if constexpr ( TWidth == 1 )
1112 static_assert(
bitsof(TResult) >= TWidth,
"Fixed size to read greater than given result type.");
1114 result= TResult(
word );
1131 result |= TResult( (
word << bitsRead )
1134 result |= TResult(
word << bitsRead );
1155 template<lang::ShiftOpRHS TW
idth,
typename TResult=
int>
1156 requires ( std::integral<TResult> && ( TWidth >
bitsof(
TStorage)) )
1159 static_assert(
bitsof(TResult) >= TWidth,
"Fixed size to read greater than given result type.");
1162 TResult result =
word;
1168 result|= TResult(
word) << bitsRead;
1171 while( bitsRead < TWidth);
1200 template<
typename TResult=
int>
1201 requires (
sizeof(TResult) <=
sizeof(
TStorage) )
1206 "Read size given greater than value type.")
1212 result= TResult(
word );
1225 result |= TResult( (
word << bitsRead )
1248 template<
typename TResult=
int>
1249 requires (
sizeof(TResult) >
sizeof(
TStorage) )
1254 "Read size given greater than value type.")
1262 result= TResult(
word );
1275 result |= TResult( (
word << bitsRead )
1285 TResult result = TResult(
word );
1291 result|= TResult(
word) << bitsRead;
1294 while( bitsRead < width);
1319 template<
typename TUIntegral>
1320 requires( std::unsigned_integral<TUIntegral> && (
bitsof(TUIntegral) == 8) )
1329 template<
typename TUIntegral>
1330 requires( std::unsigned_integral<TUIntegral> && (
bitsof(TUIntegral) == 16) )
1340 template<
typename TUIntegral>
1341 requires( std::unsigned_integral<TUIntegral> && (
bitsof(TUIntegral) == 32) )
1351 template<
typename TUIntegral>
1352 requires( std::unsigned_integral<TUIntegral> && (
bitsof(TUIntegral) == 64) )
1362 template<
typename TSIntegral>
1363 requires( std::signed_integral<TSIntegral> )
1366 using TUnsigned=
typename std::make_unsigned<TSIntegral>::type;
1368 return result & 1 ? -TSIntegral( result >> 1 ) - 1
1369 : TSIntegral( result >> 1 );
1401template<u
integer TCapacity>
bool operator!=(const Index &rhs) const
bool operator<=(const Index &rhs) const
void SetFromByteOffset(uinteger byteOffset)
lang::ShiftOpRHS bit
Current bit index in the current word.
void Clear()
Sets this index to zero, hence pointing to the first bit in the buffer.
integer GetByteOffset(Index startIdx=Index(0, 0)) const
bool operator<(const Index &rhs) const
uinteger CountBits() const
static Index Decode64(uint64_t code)
bool operator>(const Index &rhs) const
uinteger pos
Index of the current word to read/write.
bool operator==(const Index &rhs) const
bool operator>=(const Index &rhs) const
Index()=default
Default constructor initializing members pos and bit to zero.
static Index Decode32(uint32_t code)
Index(uinteger pPos, lang::ShiftOpRHS pBit)
lang::ShiftOpRHS Bit() const
virtual ALIB_DLL uinteger Capacity() const =0
uinteger RemainingSize(const Index &idx) const
ALIB_DLL Index Unterminate(Index terminationIndex)
void SetWord(const Index &index, TStorage value)
virtual ~BitBufferBase()
Virtual destructor (does nothing, needed for abstract virtual class).
BitBufferBase() noexcept
Default Constructor (the only one).
ALIB_DLL Index Terminate(Index writerIndex)
ALIB_DLL void ToLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
virtual ALIB_DLL bool EnsureCapacity(uinteger bitsRequired, BitBufferBase::Index index)=0
ALIB_DLL void FromLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
TStorage GetWord(const Index &index) const
char * CharStream(Index idx=Index(0, 0))
BitBufferLocal() noexcept
Constructor.
virtual bool EnsureCapacity(uinteger bitsRequired, BitBufferBase::Index idx) override
TStorage storage[(TCapacity+bitsof(TStorage) - 1)/bitsof(TStorage)]
The array that holds the data.
virtual uinteger Capacity() const override
StdVectorMono< TStorage > storage
The vector that holds the data.
MonoAllocator & GetAllocator()
virtual uinteger Capacity() const override
BitBufferMA(MonoAllocator &monoAllocator, uinteger initialCapacity)
virtual bool EnsureCapacity(uinteger bitsRequired, BitBufferBase::Index idx) override
std::vector< TStorage > storage
The vector that holds the data.
virtual bool EnsureCapacity(uinteger bitsRequired, BitBufferBase::Index idx) override
virtual uinteger Capacity() const override
BitBuffer(uinteger initialCapacity)
BitBufferBase & bb
The bit buffer to write into. Provided on construction.
uinteger RemainingSize() const
BitBufferBase::Index idx
The current reading/writing index within bb.
BitBufferBase & GetBuffer() const
BitBufferBase::Index GetIndex() const
BitRWBase(BitBufferBase &buffer)
Reads bits from a BitBufferBase.
BitReader(BitBufferBase &buffer)
TResult Read(lang::ShiftOpRHS width)
ALIB_DLL uint64_t readUIntegral64()
BitBufferBase::TStorage TStorage
Local type alias (shortcut)
ALIB_DLL uint32_t readUIntegral32()
ALIB_DLL uint16_t readUIntegral16()
BitReader(BitBufferBase &buffer, const BitBufferBase::Index &index)
BitBufferBase::TStorage word
The current word, which is partly read and shifted to start with current bit.
void Reset(const BitBufferBase::Index &index)
TResult Read(lang::ShiftOpRHS width)
ALIB_DLL uint8_t readUIntegral8()
void Reset()
Resets this reader to the start of the bit buffer.
Writes bits into a BitBufferBase.
void Reset(const BitBufferBase::Index &index)
~BitWriter()
Destructs a bit writer. Invokes Flush().
void Write(TIntegral value)
void Write(lang::ShiftOpRHS width, TValue value)
void Write(lang::ShiftOpRHS width, TValue value)
void Reset()
Resets the internal index of this writer to the start of the bit buffer.
void Write(TSIntegral value)
BitBufferBase::TStorage word
The current word, which is partly written and not stored in buffer, yet.
BitWriter(BitBufferBase &buffer)
BitWriter(BitBufferBase &buffer, const BitBufferBase::Index &index)
ALIB_DLL void writeUIntegral(uint8_t value)
void Write(TUIntegral value)
BitBufferBase::TStorage TStorage
Local type alias (shortcut)
#define ALIB_ERROR(domain,...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
constexpr int Log2OfSize()
constexpr TIntegral LowerBits(TIntegral value)
constexpr TIntegral LowerMask()
bitbuffer::BitReader BitReader
Type alias in namespace alib.
std::vector< T, SCAMono< T > > StdVectorMono
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
bitbuffer::BitBufferMA BitBufferMA
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
bitbuffer::BitBufferLocal< TCapacity > BitBufferLocal
Type alias in namespace alib.
bitbuffer::BitBuffer BitBuffer
Type alias in namespace alib.
bitbuffer::BitWriter BitWriter
Type alias in namespace alib.
lang::uinteger uinteger
Type alias in namespace alib.
int ShiftOpRHS
Type alias in namespace alib.