C++ Utilities 5.26.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Reads primitive data types from a std::istream. More...
#include <binaryreader.h>
Public Member Functions | |
BinaryReader (std::istream *stream, bool giveOwnership=false) | |
Constructs a new BinaryReader. | |
BinaryReader (const BinaryReader &other) | |
Copies the specified BinaryReader. | |
BinaryReader & | operator= (const BinaryReader &rhs)=delete |
~BinaryReader () | |
Destroys the BinaryReader. | |
const std::istream * | stream () const |
Returns a pointer to the stream the reader will read from when calling one of the read-methods. | |
std::istream * | stream () |
Returns a pointer to the stream the reader will read from when calling one of the read-methods. | |
void | setStream (std::istream *stream, bool giveOwnership=false) |
Assigns the stream the reader will read from when calling one of the read-methods. | |
bool | hasOwnership () const |
Returns whether the reader takes ownership over the assigned stream. | |
void | giveOwnership () |
The reader will take ownership over the assigned stream. | |
void | detatchOwnership () |
The reader will not take ownership over the assigned stream. | |
bool | fail () const |
Returns an indication whether the fail bit of the assigned stream is set. | |
bool | eof () const |
Returns an indication whether the end-of-stream bit of the assigned stream is set. | |
bool | canRead () const |
Returns an indication whether a stream is assigned the reader can read from. | |
std::istream::pos_type | readStreamsize () |
Returns the size of the assigned stream. | |
std::istream::pos_type | readRemainingBytes () |
Returns the number of remaining bytes in the stream from the current offset. | |
void | read (char *buffer, std::streamsize length) |
Reads the specified number of characters from the stream in the character array. | |
void | read (std::uint8_t *buffer, std::streamsize length) |
Reads the specified number of bytes from the stream in the character array. | |
void | read (std::vector< char > &buffer, std::streamsize length) |
Reads the specified number of bytes from the stream in the specified buffer. | |
std::int16_t | readInt16BE () |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes. | |
std::uint16_t | readUInt16BE () |
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes. | |
std::int32_t | readInt24BE () |
Reads a 24-bit big endian signed integer from the current stream and advances the current position of the stream by three bytes. | |
std::uint32_t | readUInt24BE () |
Reads a 24-bit big endian unsigned integer from the current stream and advances the current position of the stream by three bytes. | |
std::int32_t | readInt32BE () |
Reads a 32-bit big endian signed integer from the current stream and advances the current position of the stream by four bytes. | |
std::uint32_t | readUInt32BE () |
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes. | |
std::int64_t | readInt40BE () |
Reads a 40-bit big endian signed integer from the current stream and advances the current position of the stream by five bytes. | |
std::uint64_t | readUInt40BE () |
Reads a 40-bit big endian unsigned integer from the current stream and advances the current position of the stream by five bytes. | |
std::int64_t | readInt56BE () |
Reads a 56-bit big endian signed integer from the current stream and advances the current position of the stream by seven bytes. | |
std::uint64_t | readUInt56BE () |
Reads a 56-bit big endian unsigned integer from the current stream and advances the current position of the stream by seven bytes. | |
std::int64_t | readInt64BE () |
Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes. | |
std::uint64_t | readUInt64BE () |
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes. | |
std::uint64_t | readVariableLengthUIntBE () |
Reads an up to 8 byte long big endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte. | |
float | readFloat32BE () |
Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes. | |
double | readFloat64BE () |
Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes. | |
std::int16_t | readInt16LE () |
Reads a 16-bit little endian signed integer from the current stream and advances the current position of the stream by two bytes. | |
std::uint16_t | readUInt16LE () |
Reads a 16-bit little endian unsigned integer from the current stream and advances the current position of the stream by two bytes. | |
std::int32_t | readInt24LE () |
Reads a 24-bit little endian signed integer from the current stream and advances the current position of the stream by three bytes. | |
std::uint32_t | readUInt24LE () |
Reads a 24-bit little endian unsigned integer from the current stream and advances the current position of the stream by three bytes. | |
std::int32_t | readInt32LE () |
Reads a 32-bit little endian signed integer from the current stream and advances the current position of the stream by four bytes. | |
std::uint32_t | readUInt32LE () |
Reads a 32-bit little endian unsigned integer from the current stream and advances the current position of the stream by four bytes. | |
std::int64_t | readInt40LE () |
Reads a 40-bit little endian signed integer from the current stream and advances the current position of the stream by five bytes. | |
std::uint64_t | readUInt40LE () |
Reads a 40-bit little endian unsigned integer from the current stream and advances the current position of the stream by five bytes. | |
std::int64_t | readInt56LE () |
Reads a 56-bit little endian signed integer from the current stream and advances the current position of the stream by seven bytes. | |
std::uint64_t | readUInt56LE () |
Reads a 56-bit little endian unsigned integer from the current stream and advances the current position of the stream by seven bytes. | |
std::int64_t | readInt64LE () |
Reads a 64-bit little endian signed integer from the current stream and advances the current position of the stream by eight bytes. | |
std::uint64_t | readUInt64LE () |
Reads a 64-bit little endian unsigned integer from the current stream and advances the current position of the stream by eight bytes. | |
std::uint64_t | readVariableLengthUIntLE () |
Reads an up to 8 byte long little endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte. | |
float | readFloat32LE () |
Reads a 32-bit little endian floating point value from the current stream and advances the current position of the stream by four bytes. | |
double | readFloat64LE () |
Reads a 64-bit little endian floating point value from the current stream and advances the current position of the stream by eight bytes. | |
char | readChar () |
Reads a single character from the current stream and advances the current position of the stream by one byte. | |
std::uint8_t | readByte () |
Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte. | |
bool | readBool () |
Reads a boolean value from the current stream and advances the current position of the stream by one byte. | |
std::string | readLengthPrefixedString () |
Reads a length prefixed string from the current stream. | |
std::string | readString (std::size_t length) |
Reads a string from the current stream of the given length from the stream and advances the current position of the stream by length byte. | |
std::string | readTerminatedString (std::uint8_t termination=0) |
Reads a terminated string from the current stream. | |
std::string | readTerminatedString (std::size_t maxBytesToRead, std::uint8_t termination=0) |
Reads a terminated string from the current stream. | |
std::uint32_t | readSynchsafeUInt32BE () |
Reads a 32-bit big endian synchsafe integer from the current stream and advances the current position of the stream by four bytes. | |
float | readFixed8BE () |
Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit floating point value. | |
float | readFixed16BE () |
Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit floating point value. | |
std::uint32_t | readSynchsafeUInt32LE () |
Reads a 32-bit little endian synchsafe integer from the current stream and advances the current position of the stream by four bytes. | |
float | readFixed8LE () |
Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit floating point value. | |
float | readFixed16LE () |
Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-bit floating point value. | |
std::uint32_t | readCrc32 (std::size_t length) |
Reads length bytes from the stream and computes the CRC-32 for that block of data. | |
void | read (char &oneCharacter) |
Reads a single character from the current stream and advances the current position of the stream by one byte. | |
void | read (std::uint8_t &oneByte) |
Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte. | |
void | read (bool &oneBool) |
Reads a boolean value from the current stream and advances the current position of the stream by one byte. | |
void | read (std::string &lengthPrefixedString) |
Reads a length prefixed string from the current stream. | |
void | read (std::int16_t &one16BitInt) |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes. | |
void | read (std::uint16_t &one16BitUInt) |
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes. | |
void | read (std::int32_t &one32BitInt) |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes. | |
void | read (std::uint32_t &one32BitUInt) |
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes. | |
void | read (std::int64_t &one64BitInt) |
Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes. | |
void | read (std::uint64_t &one64BitUInt) |
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes. | |
void | read (float &one32BitFloat) |
Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes. | |
void | read (double &one64BitFloat) |
Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes. | |
Static Public Member Functions | |
static std::uint32_t | computeCrc32 (const char *buffer, std::size_t length) |
Reads length bytes from the buffer and computes the CRC-32 for that block of data. | |
Static Public Attributes | |
static const std::uint32_t | crc32Table [] |
CRC-32 table. | |
Reads primitive data types from a std::istream.
Definition at line 11 of file binaryreader.h.
|
inline |
Constructs a new BinaryReader.
stream | Specifies the stream to read from. |
giveOwnership | Specifies whether the reader should take ownership. |
Definition at line 107 of file binaryreader.h.
|
inline |
Copies the specified BinaryReader.
Definition at line 117 of file binaryreader.h.
|
inline |
Destroys the BinaryReader.
Definition at line 126 of file binaryreader.h.
|
inline |
Returns an indication whether a stream is assigned the reader can read from.
Definition at line 210 of file binaryreader.h.
|
static |
Reads length bytes from the buffer and computes the CRC-32 for that block of data.
Definition at line 168 of file binaryreader.cpp.
|
inline |
The reader will not take ownership over the assigned stream.
Definition at line 186 of file binaryreader.h.
|
inline |
Returns an indication whether the end-of-stream bit of the assigned stream is set.
Definition at line 202 of file binaryreader.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 194 of file binaryreader.h.
|
inline |
The reader will take ownership over the assigned stream.
Definition at line 172 of file binaryreader.h.
|
inline |
Returns whether the reader takes ownership over the assigned stream.
Definition at line 160 of file binaryreader.h.
|
delete |
|
inline |
Reads a boolean value from the current stream and advances the current position of the stream by one byte.
Definition at line 657 of file binaryreader.h.
|
inline |
Reads a single character from the current stream and advances the current position of the stream by one byte.
Definition at line 640 of file binaryreader.h.
|
inline |
Reads the specified number of characters from the stream in the character array.
Definition at line 218 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
Definition at line 732 of file binaryreader.h.
|
inline |
Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
Definition at line 724 of file binaryreader.h.
|
inline |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 676 of file binaryreader.h.
|
inline |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 692 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 708 of file binaryreader.h.
|
inline |
Reads a length prefixed string from the current stream.
Definition at line 668 of file binaryreader.h.
|
inline |
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 684 of file binaryreader.h.
|
inline |
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 700 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 716 of file binaryreader.h.
|
inline |
Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
Definition at line 648 of file binaryreader.h.
|
inline |
Reads the specified number of bytes from the stream in the character array.
Definition at line 226 of file binaryreader.h.
|
inline |
Reads the specified number of bytes from the stream in the specified buffer.
Definition at line 234 of file binaryreader.h.
|
inline |
Reads a boolean value from the current stream and advances the current position of the stream by one byte.
Definition at line 570 of file binaryreader.h.
|
inline |
Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
Definition at line 560 of file binaryreader.h.
|
inline |
Reads a single character from the current stream and advances the current position of the stream by one byte.
Definition at line 551 of file binaryreader.h.
std::uint32_t CppUtilities::BinaryReader::readCrc32 | ( | std::size_t | length | ) |
Reads length bytes from the stream and computes the CRC-32 for that block of data.
Definition at line 151 of file binaryreader.cpp.
|
inline |
Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
Definition at line 606 of file binaryreader.h.
|
inline |
Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
Definition at line 632 of file binaryreader.h.
|
inline |
Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
Definition at line 598 of file binaryreader.h.
|
inline |
Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
Definition at line 624 of file binaryreader.h.
|
inline |
Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
Definition at line 379 of file binaryreader.h.
|
inline |
Reads a 32-bit little endian floating point value from the current stream and advances the current position of the stream by four bytes.
Definition at line 533 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
Definition at line 388 of file binaryreader.h.
|
inline |
Reads a 64-bit little endian floating point value from the current stream and advances the current position of the stream by eight bytes.
Definition at line 542 of file binaryreader.h.
|
inline |
Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 243 of file binaryreader.h.
|
inline |
Reads a 16-bit little endian signed integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 397 of file binaryreader.h.
|
inline |
Reads a 24-bit big endian signed integer from the current stream and advances the current position of the stream by three bytes.
Definition at line 261 of file binaryreader.h.
|
inline |
Reads a 24-bit little endian signed integer from the current stream and advances the current position of the stream by three bytes.
Definition at line 415 of file binaryreader.h.
|
inline |
Reads a 32-bit big endian signed integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 285 of file binaryreader.h.
|
inline |
Reads a 32-bit little endian signed integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 439 of file binaryreader.h.
|
inline |
Reads a 40-bit big endian signed integer from the current stream and advances the current position of the stream by five bytes.
Definition at line 303 of file binaryreader.h.
|
inline |
Reads a 40-bit little endian signed integer from the current stream and advances the current position of the stream by five bytes.
Definition at line 457 of file binaryreader.h.
|
inline |
Reads a 56-bit big endian signed integer from the current stream and advances the current position of the stream by seven bytes.
Definition at line 327 of file binaryreader.h.
|
inline |
Reads a 56-bit little endian signed integer from the current stream and advances the current position of the stream by seven bytes.
Definition at line 481 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 351 of file binaryreader.h.
|
inline |
Reads a 64-bit little endian signed integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 505 of file binaryreader.h.
|
inline |
Reads a length prefixed string from the current stream.
Definition at line 580 of file binaryreader.h.
istream::pos_type CppUtilities::BinaryReader::readRemainingBytes | ( | ) |
Returns the number of remaining bytes in the stream from the current offset.
Definition at line 66 of file binaryreader.cpp.
istream::pos_type CppUtilities::BinaryReader::readStreamsize | ( | ) |
Returns the size of the assigned stream.
Definition at line 51 of file binaryreader.cpp.
string CppUtilities::BinaryReader::readString | ( | std::size_t | length | ) |
Reads a string from the current stream of the given length from the stream and advances the current position of the stream by length byte.
Definition at line 96 of file binaryreader.cpp.
|
inline |
Reads a 32-bit big endian synchsafe integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 590 of file binaryreader.h.
|
inline |
Reads a 32-bit little endian synchsafe integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 616 of file binaryreader.h.
string CppUtilities::BinaryReader::readTerminatedString | ( | std::size_t | maxBytesToRead, |
std::uint8_t | termination = 0 ) |
Reads a terminated string from the current stream.
Advances the current position of the stream by the string length plus one byte but maximal by maxBytesToRead.
maxBytesToRead | The maximal number of bytes to read. |
termination | The value to be recognized as termination. |
Definition at line 129 of file binaryreader.cpp.
std::string CppUtilities::BinaryReader::readTerminatedString | ( | std::uint8_t | termination = 0 | ) |
Reads a terminated string from the current stream.
Advances the current position of the stream by the string length plus one byte.
termination | The byte to be recognized as termination value. |
Definition at line 111 of file binaryreader.cpp.
|
inline |
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 252 of file binaryreader.h.
|
inline |
Reads a 16-bit little endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
Definition at line 406 of file binaryreader.h.
|
inline |
Reads a 24-bit big endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
Definition at line 275 of file binaryreader.h.
|
inline |
Reads a 24-bit little endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
Definition at line 429 of file binaryreader.h.
|
inline |
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 294 of file binaryreader.h.
|
inline |
Reads a 32-bit little endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
Definition at line 448 of file binaryreader.h.
|
inline |
Reads a 40-bit big endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
Definition at line 317 of file binaryreader.h.
|
inline |
Reads a 40-bit little endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
Definition at line 471 of file binaryreader.h.
|
inline |
Reads a 56-bit big endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
Definition at line 341 of file binaryreader.h.
|
inline |
Reads a 56-bit little endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
Definition at line 495 of file binaryreader.h.
|
inline |
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 360 of file binaryreader.h.
|
inline |
Reads a 64-bit little endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
Definition at line 514 of file binaryreader.h.
|
inline |
Reads an up to 8 byte long big endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
Throws | ConversionException if the size of the integer exceeds the maximum. |
Definition at line 370 of file binaryreader.h.
|
inline |
Reads an up to 8 byte long little endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
Throws | ConversionException if the size of the integer exceeds the maximum. |
Definition at line 524 of file binaryreader.h.
void CppUtilities::BinaryReader::setStream | ( | std::istream * | stream, |
bool | giveOwnership = false ) |
Assigns the stream the reader will read from when calling one of the read-methods.
You can assign a null pointer when ensuring that none of the read-methods is called until a stream is assigned.
stream | Specifies the stream to be assigned. |
giveOwnership | Specifies whether the reader should take ownership. |
Definition at line 31 of file binaryreader.cpp.
|
inline |
Returns a pointer to the stream the reader will read from when calling one of the read-methods.
Definition at line 138 of file binaryreader.h.
|
inline |
Returns a pointer to the stream the reader will read from when calling one of the read-methods.
Definition at line 148 of file binaryreader.h.
|
static |
CRC-32 table.
Definition at line 78 of file binaryreader.h.