8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
58 && terminationIndex.
bit == 0
59 &&
data[terminationIndex.
pos - 1] != 0,
60 "BITBUFFER",
"Given index is no termination index" )
63 terminationIndex.
pos--;
68 terminationIndex.
bit--;
72 SetWord(terminationIndex, word );
73 return terminationIndex;
81 static int isLittleEndianEncoding= 0;
83 bool IsLittleEndianEncoding()
85 if( isLittleEndianEncoding == 0 )
91 "Platform not supported")
93 isLittleEndianEncoding= 2;
97 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
98 if( *bytes == 0x11 && *(bytes+1) == 0x22)
99 isLittleEndianEncoding= 1;
104 testWord= 0x44332211;
105 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
106 if( * bytes == 0x11 && *(bytes+1) == 0x22
107 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44 )
108 isLittleEndianEncoding= 1;
114 testWord= 0x8877665544332211u;
115 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &testWord );
116 if( * bytes == 0x11 && *(bytes+1) == 0x22
117 && *(bytes+2) == 0x33 && *(bytes+3) == 0x44
118 && *(bytes+4) == 0x55 && *(bytes+5) == 0x66
119 && *(bytes+6) == 0x77 && *(bytes+7) == 0x88 )
120 isLittleEndianEncoding= 1;
126 return (isLittleEndianEncoding == 1);
134 "Given start index is not algined. The easiest way to get an aligned "
135 "index is to terminate the buffer." )
137 if( IsLittleEndianEncoding())
140 const size_t end= endIndex.
pos + (endIndex.
bit != 0 );
141 for (
size_t pos= startIndex.
pos; pos < end; ++pos)
144 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
145 bytes[0]= word & 0xFF;
146 word>>= 8; bytes[1]= word & 0xFF;
150 word>>= 8; bytes[2]= word & 0xFF;
151 word>>= 8; bytes[3]= word & 0xFF;
156 word>>= 8; bytes[4]= word & 0xFF;
157 word>>= 8; bytes[5]= word & 0xFF;
158 word>>= 8; bytes[6]= word & 0xFF;
159 word>>= 8; bytes[7]= word & 0xFF;
166 if( IsLittleEndianEncoding())
169 size_t end= endIndex.
pos + (endIndex.
bit != 0 );
170 for (
size_t pos= startIndex.
pos; pos < end; ++pos)
173 uint8_t* bytes=
reinterpret_cast<uint8_t*
>( &
data[pos] );
226 if( val < (1<< 8) ) {
Write<10>( val << 2 ); }
227 else if( val < (1<<16) ) {
Write<18>(( val << 2) | 1u ); }
228 else if( val < (1<<24) ) {
Write<26>(( val << 2) | 2u ); }
236 if( val < uint64_t(1) << 8 ) {
Write<11>( int16_t (val) << 3 ); }
237 else if( val < uint64_t(1) << 16 ) {
Write<19>( ( uint32_t (val) << 3 ) | 1u); }
238 else if( val < uint64_t(1) << 24 ) {
Write<27>( ( uint32_t (val) << 3 ) | 2u); }
239 else if( val < uint64_t(1) << 32 ) {
Write<35>( ( val << 3 ) | 3u); }
240 else if( val < uint64_t(1) << 40 ) {
Write<43>( ( val << 3 ) | 4u); }
241 else if( val < uint64_t(1) << 48 ) {
Write<51>( ( val << 3 ) | 5u); }
242 else if( val < uint64_t(1) << 56 ) {
Write<59>( ( val << 3 ) | 6u); }
253 return uint8_t(result >> 1);
255 return uint8_t( result >> 1
263 return uint16_t(result >> 1);
265 return uint16_t( result >> 1
274 case 0:
return uint32_t(result >> 2);
286 case 0:
return uint64_t(result >> 3);
lang::ShiftOpRHS bit
Current bit index in the current word.
uinteger pos
Index of the current word to read/write.
ALIB_DLL Index Unterminate(Index terminationIndex)
void SetWord(const Index &index, TStorage value)
ALIB_DLL Index Terminate(Index writerIndex)
ALIB_DLL void ToLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
ALIB_DLL void FromLittleEndianEncoding(const Index &startIndex, const Index &endIndex)
TStorage GetWord(const Index &index) const
BitBufferBase::Index GetIndex() const
ALIB_DLL uint64_t readUIntegral64()
ALIB_DLL uint32_t readUIntegral32()
ALIB_DLL uint16_t readUIntegral16()
ALIB_DLL uint8_t readUIntegral8()
Writes bits into a BitBufferBase.
void Write(TIntegral value)
ALIB_DLL void writeUIntegral(uint8_t value)
#define ALIB_WARNINGS_IGNORE_INTEGRAL_CONSTANT_OVERFLOW
#define ALIB_WARNINGS_RESTORE
#define ALIB_STATIC_ASSERT(CondVariable, Cond, Message)
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_WARNINGS_IGNORE_INTEGER_OVERFLOW
constexpr int MSB(TIntegral value)