C++ Utilities
5.0.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. More... | |
BinaryReader (const BinaryReader &other) | |
Copies the specified BinaryReader. More... | |
BinaryReader & | operator= (const BinaryReader &rhs)=delete |
~BinaryReader () | |
Destroys the BinaryReader. More... | |
const std::istream * | stream () const |
Returns a pointer to the stream the reader will read from when calling one of the read-methods. More... | |
std::istream * | stream () |
Returns a pointer to the stream the reader will read from when calling one of the read-methods. More... | |
void | setStream (std::istream *stream, bool giveOwnership=false) |
Assigns the stream the reader will read from when calling one of the read-methods. More... | |
bool | hasOwnership () const |
Returns whether the reader takes ownership over the assigned stream. More... | |
void | giveOwnership () |
The reader will take ownership over the assigned stream. More... | |
void | detatchOwnership () |
The reader will not take ownership over the assigned stream. More... | |
bool | fail () const |
Returns an indication whether the fail bit of the assigned stream is set. More... | |
bool | eof () const |
Returns an indication whether the end-of-stream bit of the assigned stream is set. More... | |
bool | canRead () const |
Returns an indication whether a stream is assigned the reader can read from. More... | |
std::istream::pos_type | readStreamsize () |
Returns the size of the assigned stream. More... | |
void | read (char *buffer, std::streamsize length) |
Reads the specified number of characters from the stream in the character array. More... | |
void | read (std::uint8_t *buffer, std::streamsize length) |
Reads the specified number of bytes from the stream in the character array. More... | |
void | read (std::vector< char > &buffer, std::streamsize length) |
Reads the specified number of bytes from the stream in the specified buffer. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
char | readChar () |
Reads a single character from the current stream and advances the current position of the stream by one byte. More... | |
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. More... | |
bool | readBool () |
Reads a boolean value from the current stream and advances the current position of the stream by one byte. More... | |
std::string | readLengthPrefixedString () |
Reads a length prefixed string from the current stream. More... | |
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. More... | |
std::string | readTerminatedString (std::uint8_t termination=0) |
Reads a terminated string from the current stream. More... | |
std::string | readTerminatedString (std::size_t maxBytesToRead, std::uint8_t termination=0) |
Reads a terminated string from the current stream. More... | |
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. More... | |
float | readFixed8BE () |
Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit floating point value. More... | |
float | readFixed16BE () |
Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit floating point value. More... | |
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. More... | |
float | readFixed8LE () |
Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit floating point value. More... | |
float | readFixed16LE () |
Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-bit floating point value. More... | |
std::uint32_t | readCrc32 (std::size_t length) |
Reads length bytes from the stream and computes the CRC-32 for that block of data. More... | |
void | read (char &oneCharacter) |
Reads a single character from the current stream and advances the current position of the stream by one byte. More... | |
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. More... | |
void | read (bool &oneBool) |
Reads a boolean value from the current stream and advances the current position of the stream by one byte. More... | |
void | read (std::string &lengthPrefixedString) |
Reads a length prefixed string from the current stream. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
Static Public Attributes | |
static const std::uint32_t | crc32Table [] |
CRC-32 table. More... | |
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 106 of file binaryreader.h.
|
inline |
Copies the specified BinaryReader.
Definition at line 116 of file binaryreader.h.
|
inline |
Destroys the BinaryReader.
Definition at line 125 of file binaryreader.h.
|
inline |
Returns an indication whether a stream is assigned the reader can read from.
Definition at line 209 of file binaryreader.h.
|
static |
Reads length bytes from the buffer and computes the CRC-32 for that block of data.
Definition at line 154 of file binaryreader.cpp.
|
inline |
The reader will not take ownership over the assigned stream.
Definition at line 185 of file binaryreader.h.
|
inline |
Returns an indication whether the end-of-stream bit of the assigned stream is set.
Definition at line 201 of file binaryreader.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 193 of file binaryreader.h.
|
inline |
The reader will take ownership over the assigned stream.
Definition at line 171 of file binaryreader.h.
|
inline |
Returns whether the reader takes ownership over the assigned stream.
Definition at line 159 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 656 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 639 of file binaryreader.h.
|
inline |
Reads the specified number of characters from the stream in the character array.
Definition at line 217 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 731 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 723 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 675 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 691 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 707 of file binaryreader.h.
|
inline |
Reads a length prefixed string from the current stream.
Definition at line 667 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 683 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 699 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 715 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 647 of file binaryreader.h.
|
inline |
Reads the specified number of bytes from the stream in the character array.
Definition at line 225 of file binaryreader.h.
|
inline |
Reads the specified number of bytes from the stream in the specified buffer.
Definition at line 233 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 569 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 559 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 550 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 137 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 605 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 631 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 597 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 623 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 378 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 532 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 387 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 541 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 242 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 396 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 260 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 414 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 284 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 438 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 302 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 456 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 326 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 480 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 350 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 504 of file binaryreader.h.
|
inline |
Reads a length prefixed string from the current stream.
Definition at line 579 of file binaryreader.h.
istream::pos_type CppUtilities::BinaryReader::readStreamsize | ( | ) |
Returns the size of the assigned stream.
The size is determined by seeking to the end of the stream and returning this offset.
Definition at line 52 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 82 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 589 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 615 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 115 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 97 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 251 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 405 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 274 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 428 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 293 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 447 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 316 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 470 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 340 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 494 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 359 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 513 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 369 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 523 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 137 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 147 of file binaryreader.h.
|
static |
CRC-32 table.
Definition at line 77 of file binaryreader.h.