C++ Utilities
4.17.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) | |
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 (byte value) |
Writes a single byte to the current stream and advances the current position of the stream by one byte. More... | |
void | writeInt16BE (int16 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 (uint16 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 (int32 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 (uint32 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 (int32 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 (uint32 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 (int64 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 (uint64 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 (int64 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 (uint64 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 (int64 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 (uint64 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 (uint64 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 (float32 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 (float64 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 (int16 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 (uint16 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 (int32 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 (uint32 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 (int32 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 (uint32 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 (int64 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 (uint64 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 (int64 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 (uint64 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 (int64 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 (uint64 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 (uint64 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 (float32 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 (float64 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 (uint32 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 (float32 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 (float32 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 (uint32 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 (float32 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 (float32 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 (byte 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 (int16 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 (uint16 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 (int32 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 (uint32 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 (int64 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 (uint64 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 (float32 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 (float64 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.
BinaryWriter::BinaryWriter | ( | std::ostream * | stream | ) |
Constructs a new BinaryWriter.
stream | Specifies the stream to write to. |
Definition at line 23 of file binarywriter.cpp.
BinaryWriter::BinaryWriter | ( | const BinaryWriter & | other | ) |
Copies the specified BinaryWriter.
Definition at line 33 of file binarywriter.cpp.
BinaryWriter::~BinaryWriter | ( | ) |
Destroys the BinaryWriter.
Definition at line 42 of file binarywriter.cpp.
|
inline |
The writer will not take ownership over the assigned stream.
Definition at line 151 of file binarywriter.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 167 of file binarywriter.h.
|
inline |
Calls the flush() method of the assigned stream.
Definition at line 159 of file binarywriter.h.
|
inline |
The writer will take ownership over the assigned stream.
Definition at line 137 of file binarywriter.h.
|
inline |
Returns whether the writer takes ownership over the assigned stream.
Definition at line 125 of file binarywriter.h.
|
delete |
void 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 | Indicated whether the reader should take ownership (default is false). |
Definition at line 60 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 113 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 103 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 175 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 184 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 571 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 579 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 587 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 597 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 607 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 615 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 623 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 631 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 639 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 647 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 655 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 663 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 671 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 210 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 201 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 192 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 537 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 563 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 529 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 555 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 342 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 485 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 351 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 494 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 218 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 360 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 237 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 379 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 257 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 400 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 276 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 419 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 296 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 439 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 315 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 458 of file binarywriter.h.
void BinaryWriter::writeLengthPrefixedCString | ( | const char * | value, |
std::size_t | size | ||
) |
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 115 of file binarywriter.cpp.
void BinaryWriter::writeLengthPrefixedString | ( | const std::string & | value | ) |
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 101 of file binarywriter.cpp.
|
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 503 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 521 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 547 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 511 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 227 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 369 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 247 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 390 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 266 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 409 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 286 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 429 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 306 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 449 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 324 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 467 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 334 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 477 of file binarywriter.h.