C++ Utilities
4.6.1
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 14 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 31 of file binarywriter.cpp.
BinaryWriter::~BinaryWriter | ( | ) |
Destroys the BinaryWriter.
Definition at line 39 of file binarywriter.cpp.
|
inline |
The writer will not take ownership over the assigned stream.
Definition at line 132 of file binarywriter.h.
|
inline |
Returns an indication whether the fail bit of the assigned stream is set.
Definition at line 148 of file binarywriter.h.
|
inline |
Calls the flush() method of the assigned stream.
Definition at line 140 of file binarywriter.h.
|
inline |
The writer will take ownership over the assigned stream.
Definition at line 118 of file binarywriter.h.
|
inline |
Returns whether the writer takes ownership over the assigned stream.
Definition at line 106 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 57 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 94 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 84 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 156 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 165 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 191 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 182 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 173 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 500 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 526 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 492 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 518 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 314 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 448 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 323 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 457 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 199 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 332 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 218 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 351 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 238 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 372 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 257 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 391 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 277 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 411 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 296 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 430 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 76 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 466 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 484 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 510 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 474 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 208 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 341 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 228 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 362 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 247 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 381 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 267 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 401 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 287 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 421 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 305 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 439 of file binarywriter.h.