12#ifndef BITSTREAMREADER_H
13#define BITSTREAMREADER_H
48template <
typename BufferType>
69 return mBitPosition > 0;
76 return mCurrent == mEnd && mBitPosition > 0;
93 template <
typename T,
size_t N = sizeof(T) * 8>
96 static_assert(N <=
sizeof(T) * 8);
97 return peek<T, false>(
v, N);
105 template <
typename T>
108 return peek<T, true>(
v, bitlength);
115 while (
good() && bitlength > 0 && mCurrent != mEnd) {
116 if (bitlength >= mBitPosition) {
117 bitlength -= mBitPosition;
120 mBitPosition -= bitlength;
123 if (mBitPosition == 0) {
135 template <
typename T,
size_t N = sizeof(T) * 8>
145 template <
typename T>
146 T
get(
size_t bitlength =
sizeof(T) * 8)
149 peek<T>(
result, bitlength);
160 template <
typename FieldType,
size_t N = sizeof(FieldType) * 8,
typename ParentType = self_type>
165 static_assert(N <=
sizeof(FieldType) * 8);
167 : mParent(nullptr), mData(0), mLength(0)
171 : mParent(parent), mData(
std::move(
data)), mLength(N)
177 other.mParent =
nullptr;
184 mParent->seek(mLength);
190 mParent =
other.mParent;
191 mData = std::move(
other.mData);
192 mLength =
other.mLength;
193 other.mParent =
nullptr;
216 template <typename T, std::enable_if_t<std::is_integral<T>::value,
int> = 0>
227 target = get<std::bitset<N>, N>();
232 template <
typename T>
243 template <
typename T,
bool RuntimeCheck>
246 if constexpr (RuntimeCheck) {
248 if (bitlength >
sizeof(T) * 8) {
249 throw std::length_error(std::string(
"requested bit length ") +
std::to_string(bitlength) +
" does not fit size of result data type " +
std::to_string(
sizeof(T) * 8));
253 size_t bitsToWrite = bitlength;
254 auto current = mCurrent;
255 auto bitsAvailable = mBitPosition;
256 while (bitsToWrite > 0 && current != mEnd) {
259 if (bitsToWrite >= bitsAvailable) {
260 T
value = (*current &
mask) << (bitsToWrite - bitsAvailable);
262 bitsToWrite -= bitsAvailable;
267 bitsAvailable -= bitsToWrite;
270 if (bitsAvailable == 0) {
276 return bitlength - bitsToWrite;
Helper class to get value of specified type which holds the number used bits.
void markUsed(size_t length)
auto & operator=(Bits< FieldType, N, ParentType > &&other)
Bits(ParentType *parent, FieldType &&data)
void seek(size_t bitlength)
~BitstreamReader()=default
size_t peek(T &v, size_t bitlength)
T get(size_t bitlength=sizeof(T) *8)
Get the next n and move the read position.
self_type & operator>>(T &target)
Read an integral value from the stream.
self_type & operator>>(Bits< T > &target)
Read a Bits object from the stream.
const value_type * iterator
static constexpr size_t value_size
BitstreamReader(iterator start, iterator end)
void reset()
Reset the reader, start over at beginning.
T get()
Get the next n bits and move the read position.
self_type & operator>>(std::bitset< N > &target)
Read a bitstream value from the stream.
GLsizei const GLfloat * value
GLuint GLsizei GLsizei * length
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Defining DataPointCompositeObject explicitly as copiable.
std::string to_string(gsl::span< T, Size > span)
VectorOfTObjectPtrs other