C++ Utilities
4.8.0
Common C++ classes and routines used by my applications 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 | 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 | 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 | 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... | |
Writes primitive data types to a std::ostream.
Definition at line 13 of file binarywriter.h.
BinaryWriter::BinaryWriter | ( | std::ostream * | stream | ) |
Constructs a new BinaryWriter.
stream | Specifies the stream to write to. |
Definition at line 22 of file binarywriter.cpp.
BinaryWriter::BinaryWriter | ( | const BinaryWriter & | other | ) |
Copies the specified BinaryWriter.
Definition at line 32 of file binarywriter.cpp.
BinaryWriter::~BinaryWriter | ( | ) |
Destroys the BinaryWriter.
Definition at line 41 of file binarywriter.cpp.
|
inline |
The writer will not take ownership over the assigned stream.
Definition at line 130 of file binarywriter.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 146 of file binarywriter.h.
|
inline |
Calls the flush() method of the assigned stream.
Definition at line 138 of file binarywriter.h.
|
inline |
The writer will take ownership over the assigned stream.
Definition at line 116 of file binarywriter.h.
|
inline |
Returns whether the writer takes ownership over the assigned stream.
Definition at line 104 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 59 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 92 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 82 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 154 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 163 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 189 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 180 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 171 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 498 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 524 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 490 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 516 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 312 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 446 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 321 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 455 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 197 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 330 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 216 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 349 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 236 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 370 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 255 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 389 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 275 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 409 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 294 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 428 of file binarywriter.h.
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.
Definition at line 78 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 464 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 482 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 508 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 472 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 206 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 339 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 226 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 360 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 245 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 379 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 265 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 399 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 285 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 419 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 303 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 437 of file binarywriter.h.