18 : mBufferSize(
std::max(bufferSize, RequiredAlignment))
32 size_t bytesWritten = 0;
38 if (!HandleUnderflow())
43 const size_t bytesToRead =
std::min(maxBytes, availableBytes);
47 maxBytes -= bytesToRead;
48 bytesWritten += bytesToRead;
55bool BufferedStreamReader::Eof()
const
60int BufferedStreamReader::GetC()
70bool BufferedStreamReader::HandleUnderflow()
size_t Read(void *buffer, size_t maxBytes)
Read up to maxBytes into the buffer. Returns the number of bytes read.
static constexpr size_t RequiredAlignment
BufferedStreamReader(size_t bufferSize=4096)
std::enable_if_t< sizeof(ValueType)<=RequiredAlignment, bool > ReadValue(ValueType &value) { constexpr size_t valueSize=sizeof(ValueType);const size_t availableBytes=mCurrentBytes - mCurrentIndex;if(availableBytes< valueSize) return valueSize==Read(&value, valueSize);if constexpr(valueSize==1) value=mBufferStart[mCurrentIndex];else value=UncheckedRead< ValueType >();mCurrentIndex+=valueSize;return true;} bool Eof() const ;int GetC();protected:virtual bool HasMoreData() const=0;virtual size_t ReadData(void *buffer, size_t maxBytes)=0;private:bool HandleUnderflow();template< typename T > T UncheckedRead() noexcept { T result;if((mCurrentIndex % sizeof(T))==0) { const void *ptr=mBufferStart+mCurrentIndex;result=*static_cast< const T * >(ptr);} else { const uint8_t *begin=mBufferStart+mCurrentIndex;const uint8_t *end=begin+sizeof(T);void *out=&result;std::copy(begin, end, static_cast< uint8_t * >(out));} return result;} std::vector< uint8_t > mBufferData
Read a single value of ValueType, where sizeof(ValueType) <= 8 and value is aligned to the size bound...