C++ Utilities
5.4.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. More... | |
BinaryWriter (const BinaryWriter &other) | |
Copies the specified BinaryWriter. More... | |
BinaryWriter & | operator= (const BinaryWriter &rhs)=delete |
~BinaryWriter () | |
Destroys the BinaryWriter. More... | |
const std::ostream * | stream () const |
Returns a pointer to the stream the writer will write to when calling one of the write-methods. More... | |
std::ostream * | stream () |
Returns a pointer to the stream the writer will write to when calling one of the write-methods. More... | |
void | setStream (std::ostream *stream, bool giveOwnership=false) |
Assigns the stream the writer will write to when calling one of the write-methods. More... | |
bool | hasOwnership () const |
Returns whether the writer takes ownership over the assigned stream. More... | |
void | giveOwnership () |
The writer will take ownership over the assigned stream. More... | |
void | detatchOwnership () |
The writer will not take ownership over the assigned stream. More... | |
void | flush () |
Calls the flush() method of the assigned stream. More... | |
bool | fail () const |
Returns an indication whether the fail bit of the assigned stream is set. More... | |
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. More... | |
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. More... | |
void | writeChar (char value) |
Writes a single character to the current stream and advances the current position of the stream by one byte. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | writeLengthPrefixedString (const std::string &value) |
Writes the length of a string and the string itself to the current stream. More... | |
void | writeLengthPrefixedCString (const char *value, std::size_t size) |
Writes the length of a string and the string itself to the current stream. More... | |
void | writeBool (bool value) |
Writes a boolean value to the current stream and advances the current position of the stream by one byte. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | write (char oneChar) |
Writes a single character to the current stream and advances the current position of the stream by one byte. More... | |
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. More... | |
void | write (bool oneBool) |
Writes a boolean value to the current stream and advances the current position of the stream by one byte. More... | |
void | write (const std::string &lengthPrefixedString) |
Writes the length of a string and the string itself to the current stream. More... | |
void | write (const char *lengthPrefixedString) |
Writes the length of a string and the string itself to the current stream. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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 103 of file binarywriter.h.
|
inline |
Copies the specified BinaryWriter.
Definition at line 113 of file binarywriter.h.
|
inline |
Destroys the BinaryWriter.
Definition at line 122 of file binarywriter.h.
|
inline |
The writer will not take ownership over the assigned stream.
Definition at line 182 of file binarywriter.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 198 of file binarywriter.h.
|
inline |
Calls the flush() method of the assigned stream.
Definition at line 190 of file binarywriter.h.
|
inline |
The writer will take ownership over the assigned stream.
Definition at line 168 of file binarywriter.h.
|
inline |
Returns whether the writer takes ownership over the assigned stream.
Definition at line 156 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 134 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 144 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 644 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 628 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 206 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 664 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 654 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 215 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 728 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 720 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 672 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 688 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 704 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 680 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 696 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 712 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 636 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 241 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 232 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 223 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 594 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 620 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 586 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 612 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 373 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 516 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 382 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 525 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 249 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 391 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 268 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 410 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 288 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 431 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 307 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 450 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 327 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 470 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 346 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 489 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 567 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 554 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 534 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 578 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 604 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 542 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 258 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 400 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 278 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 421 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 297 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 440 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 317 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 460 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 337 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 480 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 355 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 498 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 365 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 508 of file binarywriter.h.