C++ Utilities 5.27.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Writes primitive data types to a std::ostream. More...
#include <binarywriter.h>
Public Member Functions | |
BinaryWriter (std::ostream *stream, bool giveOwnership=false) | |
Constructs a new BinaryWriter. | |
BinaryWriter (const BinaryWriter &other) | |
Copies the specified BinaryWriter. | |
BinaryWriter & | operator= (const BinaryWriter &rhs)=delete |
~BinaryWriter () | |
Destroys the BinaryWriter. | |
const std::ostream * | stream () const |
Returns a pointer to the stream the writer will write to when calling one of the write-methods. | |
std::ostream * | stream () |
Returns a pointer to the stream the writer will write to when calling one of the write-methods. | |
void | setStream (std::ostream *stream, bool giveOwnership=false) |
Assigns the stream the writer will write to when calling one of the write-methods. | |
bool | hasOwnership () const |
Returns whether the writer takes ownership over the assigned stream. | |
void | giveOwnership () |
The writer will take ownership over the assigned stream. | |
void | detatchOwnership () |
The writer will not take ownership over the assigned stream. | |
void | flush () |
Calls the flush() method of the assigned stream. | |
bool | fail () const |
Returns an indication whether the fail bit of the assigned stream is set. | |
void | write (const char *buffer, std::streamsize length) |
Writes a character array to the current stream and advances the current position of the stream by the length of the array. | |
void | write (const std::vector< char > &buffer, std::streamsize length) |
Writes the specified number of bytes from the buffer to the current stream and advances the current position of the stream by the specified length which must be less or equal to the buffer size. | |
void | writeChar (char value) |
Writes a single character to the current stream and advances the current position of the stream by one byte. | |
void | writeByte (std::uint8_t value) |
Writes a single byte to the current stream and advances the current position of the stream by one byte. | |
void | writeInt16BE (std::int16_t value) |
Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes. | |
void | writeUInt16BE (std::uint16_t value) |
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes. | |
void | writeInt24BE (std::int32_t value) |
Writes a 24-bit big endian signed integer to the current stream and advances the current position of the stream by three bytes. | |
void | writeUInt24BE (std::uint32_t value) |
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position of the stream by three bytes. | |
void | writeInt32BE (std::int32_t value) |
Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt32BE (std::uint32_t value) |
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt40BE (std::int64_t value) |
Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt40BE (std::uint64_t value) |
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt56BE (std::int64_t value) |
Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt56BE (std::uint64_t value) |
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt64BE (std::int64_t value) |
Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes. | |
void | writeUInt64BE (std::uint64_t value) |
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes. | |
void | writeVariableLengthUIntBE (std::uint64_t value) |
Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes. | |
void | writeFloat32BE (float value) |
Writes a 32-bit big endian floating point value to the current stream and advances the current position of the stream by four bytes. | |
void | writeFloat64BE (double value) |
Writes a 64-bit big endian floating point value to the current stream and advances the current position of the stream by eight bytes. | |
void | writeInt16LE (std::int16_t value) |
Writes a 16-bit little endian signed integer to the current stream and advances the current position of the stream by two bytes. | |
void | writeUInt16LE (std::uint16_t value) |
Writes a 16-bit little endian unsigned integer to the current stream and advances the current position of the stream by two bytes. | |
void | writeInt24LE (std::int32_t value) |
Writes a 24-bit little endian signed integer to the current stream and advances the current position of the stream by three bytes. | |
void | writeUInt24LE (std::uint32_t value) |
Writes a 24-bit little endian unsigned integer to the current stream and advances the current position of the stream by three bytes. | |
void | writeInt32LE (std::int32_t value) |
Writes a 32-bit little endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt32LE (std::uint32_t value) |
Writes a 32-bit little endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt40LE (std::int64_t value) |
Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt40LE (std::uint64_t value) |
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt56LE (std::int64_t value) |
Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeUInt56LE (std::uint64_t value) |
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeInt64LE (std::int64_t value) |
Writes a 64-bit little endian signed integer to the current stream and advances the current position of the stream by eight bytes. | |
void | writeUInt64LE (std::uint64_t value) |
Writes a 64-bit little endian unsigned integer to the current stream and advances the current position of the stream by eight bytes. | |
void | writeVariableLengthUIntLE (std::uint64_t value) |
Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes. | |
void | writeFloat32LE (float value) |
Writes a 32-bit little endian floating point value to the current stream and advances the current position of the stream by four bytes. | |
void | writeFloat64LE (double value) |
Writes a 64-bit little endian floating point value to the current stream and advances the current position of the stream by eight bytes. | |
void | writeString (const std::string &value) |
Writes a string to the current stream and advances the current position of the stream by the length of the string. | |
void | writeTerminatedString (const std::string &value) |
Writes a terminated string to the current stream and advances the current position of the stream by the length of the string plus 1. | |
void | writeLengthPrefixedString (const std::string &value) |
Writes the length of a string and the string itself to the current stream. | |
void | writeLengthPrefixedCString (const char *value, std::size_t size) |
Writes the length of a string and the string itself to the current stream. | |
void | writeBool (bool value) |
Writes a boolean value to the current stream and advances the current position of the stream by one byte. | |
void | writeSynchsafeUInt32BE (std::uint32_t valueToConvertAndWrite) |
Writes a 32-bit big endian synchsafe integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeFixed8BE (float valueToConvertAndWrite) |
Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by two bytes. | |
void | writeFixed16BE (float valueToConvertAndWrite) |
Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by four bytes. | |
void | writeSynchsafeUInt32LE (std::uint32_t valueToConvertAndWrite) |
Writes a 32-bit little endian synchsafe integer to the current stream and advances the current position of the stream by four bytes. | |
void | writeFixed8LE (float valueToConvertAndWrite) |
Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by two bytes. | |
void | writeFixed16LE (float valueToConvertAndWrite) |
Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by four bytes. | |
void | write (char oneChar) |
Writes a single character to the current stream and advances the current position of the stream by one byte. | |
void | write (std::uint8_t oneByte) |
Writes a single byte to the current stream and advances the current position of the stream by one byte. | |
void | write (bool oneBool) |
Writes a boolean value to the current stream and advances the current position of the stream by one byte. | |
void | write (const std::string &lengthPrefixedString) |
Writes the length of a string and the string itself to the current stream. | |
void | write (std::string_view lengthPrefixedString) |
Writes the length of a string and the string itself to the current stream. | |
void | write (const char *lengthPrefixedString) |
Writes the length of a string and the string itself to the current stream. | |
void | write (std::int16_t one16BitInt) |
Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes. | |
void | write (std::uint16_t one16BitUint) |
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes. | |
void | write (std::int32_t one32BitInt) |
Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes. | |
void | write (std::uint32_t one32BitUint) |
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes. | |
void | write (std::int64_t one64BitInt) |
Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes. | |
void | write (std::uint64_t one64BitUint) |
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes. | |
void | write (float one32BitFloat) |
Writes a 32-bit big endian floating point value to the current stream and advances the current position of the stream by four bytes. | |
void | write (double one64BitFloat) |
Writes a 64-bit big endian floating point value to the current stream and advances the current position of the stream by eight bytes. | |
Writes primitive data types to a std::ostream.
Definition at line 14 of file binarywriter.h.
|
inline |
Constructs a new BinaryWriter.
stream | Specifies the stream to write to. |
giveOwnership | Specifies whether the writer should take ownership. |
Definition at line 104 of file binarywriter.h.
|
inline |
Copies the specified BinaryWriter.
Definition at line 114 of file binarywriter.h.
|
inline |
Destroys the BinaryWriter.
Definition at line 123 of file binarywriter.h.
|
inline |
The writer will not take ownership over the assigned stream.
Definition at line 183 of file binarywriter.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 199 of file binarywriter.h.
|
inline |
Calls the flush() method of the assigned stream.
Definition at line 191 of file binarywriter.h.
|
inline |
The writer will take ownership over the assigned stream.
Definition at line 169 of file binarywriter.h.
|
inline |
Returns whether the writer takes ownership over the assigned stream.
Definition at line 157 of file binarywriter.h.
|
delete |
void CppUtilities::BinaryWriter::setStream | ( | std::ostream * | stream, |
bool | giveOwnership = false ) |
Assigns the stream the writer will write to when calling one of the write-methods.
You can assign a null pointer when ensuring that none of the write-methods is called until a stream is assigned.
stream | Specifies the stream to be assigned. |
giveOwnership | Specifies whether the writer should take ownership. |
Definition at line 30 of file binarywriter.cpp.
|
inline |
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
Definition at line 135 of file binarywriter.h.
|
inline |
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
Definition at line 145 of file binarywriter.h.
|
inline |
Writes a boolean value to the current stream and advances the current position of the stream by one byte.
Definition at line 645 of file binarywriter.h.
|
inline |
Writes a single character to the current stream and advances the current position of the stream by one byte.
Definition at line 629 of file binarywriter.h.
|
inline |
Writes a character array to the current stream and advances the current position of the stream by the length of the array.
Definition at line 207 of file binarywriter.h.
|
inline |
Writes the length of a string and the string itself to the current stream.
Advances the current position of the stream by the length of the string plus the size of the length prefix.
Definition at line 675 of file binarywriter.h.
|
inline |
Writes the length of a string and the string itself to the current stream.
Advances the current position of the stream by the length of the string plus the size of the length prefix.
Definition at line 655 of file binarywriter.h.
|
inline |
Writes the specified number of bytes from the buffer to the current stream and advances the current position of the stream by the specified length which must be less or equal to the buffer size.
Definition at line 216 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian floating point value to the current stream and advances the current position of the stream by eight bytes.
Definition at line 739 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian floating point value to the current stream and advances the current position of the stream by four bytes.
Definition at line 731 of file binarywriter.h.
|
inline |
Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 683 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 699 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 715 of file binarywriter.h.
|
inline |
Writes the length of a string and the string itself to the current stream.
Advances the current position of the stream by the length of the string plus the size of the length prefix.
Definition at line 665 of file binarywriter.h.
|
inline |
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 691 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 707 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 723 of file binarywriter.h.
|
inline |
Writes a single byte to the current stream and advances the current position of the stream by one byte.
Definition at line 637 of file binarywriter.h.
|
inline |
Writes a boolean value to the current stream and advances the current position of the stream by one byte.
Definition at line 242 of file binarywriter.h.
|
inline |
Writes a single byte to the current stream and advances the current position of the stream by one byte.
Definition at line 233 of file binarywriter.h.
|
inline |
Writes a single character to the current stream and advances the current position of the stream by one byte.
Definition at line 224 of file binarywriter.h.
|
inline |
Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by four bytes.
Definition at line 595 of file binarywriter.h.
|
inline |
Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by four bytes.
Definition at line 621 of file binarywriter.h.
|
inline |
Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by two bytes.
Definition at line 587 of file binarywriter.h.
|
inline |
Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point value to the current stream and advances the current position of the stream by two bytes.
Definition at line 613 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian floating point value to the current stream and advances the current position of the stream by four bytes.
Definition at line 374 of file binarywriter.h.
|
inline |
Writes a 32-bit little endian floating point value to the current stream and advances the current position of the stream by four bytes.
Definition at line 517 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian floating point value to the current stream and advances the current position of the stream by eight bytes.
Definition at line 383 of file binarywriter.h.
|
inline |
Writes a 64-bit little endian floating point value to the current stream and advances the current position of the stream by eight bytes.
Definition at line 526 of file binarywriter.h.
|
inline |
Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 250 of file binarywriter.h.
|
inline |
Writes a 16-bit little endian signed integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 392 of file binarywriter.h.
|
inline |
Writes a 24-bit big endian signed integer to the current stream and advances the current position of the stream by three bytes.
Definition at line 269 of file binarywriter.h.
|
inline |
Writes a 24-bit little endian signed integer to the current stream and advances the current position of the stream by three bytes.
Definition at line 411 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 289 of file binarywriter.h.
|
inline |
Writes a 32-bit little endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 432 of file binarywriter.h.
|
inline |
Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 308 of file binarywriter.h.
|
inline |
Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 451 of file binarywriter.h.
|
inline |
Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 328 of file binarywriter.h.
|
inline |
Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 471 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 347 of file binarywriter.h.
|
inline |
Writes a 64-bit little endian signed integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 490 of file binarywriter.h.
|
inline |
Writes the length of a string and the string itself to the current stream.
Advances the current position of the stream by the length of the string plus the size of the length prefix.
Throws | ConversionException if the string size exceeds the maximum. |
Definition at line 568 of file binarywriter.h.
|
inline |
Writes the length of a string and the string itself to the current stream.
Advances the current position of the stream by the length of the string plus the size of the length prefix.
Throws | ConversionException if the string size exceeds the maximum. |
Definition at line 555 of file binarywriter.h.
|
inline |
Writes a string to the current stream and advances the current position of the stream by the length of the string.
Definition at line 535 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian synchsafe integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 579 of file binarywriter.h.
|
inline |
Writes a 32-bit little endian synchsafe integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 605 of file binarywriter.h.
|
inline |
Writes a terminated string to the current stream and advances the current position of the stream by the length of the string plus 1.
Definition at line 543 of file binarywriter.h.
|
inline |
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 259 of file binarywriter.h.
|
inline |
Writes a 16-bit little endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
Definition at line 401 of file binarywriter.h.
|
inline |
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
Definition at line 279 of file binarywriter.h.
|
inline |
Writes a 24-bit little endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
Definition at line 422 of file binarywriter.h.
|
inline |
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 298 of file binarywriter.h.
|
inline |
Writes a 32-bit little endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 441 of file binarywriter.h.
|
inline |
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 318 of file binarywriter.h.
|
inline |
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 461 of file binarywriter.h.
|
inline |
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 338 of file binarywriter.h.
|
inline |
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
Definition at line 481 of file binarywriter.h.
|
inline |
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 356 of file binarywriter.h.
|
inline |
Writes a 64-bit little endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
Definition at line 499 of file binarywriter.h.
|
inline |
Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
Throws | ConversionException if value exceeds the maximum. |
Definition at line 366 of file binarywriter.h.
|
inline |
Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
Throws | ConversionException if value exceeds the maximum. |
Definition at line 509 of file binarywriter.h.