1 #ifndef IOUTILITIES_BINARYWRITER_H 2 #define IOUTILITIES_BINARYWRITER_H 4 #include "../conversion/binaryconversion.h" 5 #include "../conversion/types.h" 21 const std::ostream *stream()
const;
22 std::ostream *stream();
23 void setStream(std::ostream *stream,
bool giveOwnership =
false);
24 bool hasOwnership()
const;
26 void detatchOwnership();
29 void write(
const char *buffer, std::streamsize length);
30 void write(
const std::vector<char> &buffer, std::streamsize length);
31 void writeChar(
char value);
32 void writeByte(
byte value);
33 void writeInt16BE(
int16 value);
34 void writeUInt16BE(
uint16 value);
35 void writeInt24BE(
int32 value);
36 void writeUInt24BE(
uint32 value);
37 void writeInt32BE(
int32 value);
38 void writeUInt32BE(
uint32 value);
39 void writeInt40BE(
int64 value);
40 void writeUInt40BE(
uint64 value);
41 void writeInt56BE(
int64 value);
42 void writeUInt56BE(
uint64 value);
43 void writeInt64BE(
int64 value);
44 void writeUInt64BE(
uint64 value);
45 void writeVariableLengthUIntBE(
uint64 value);
46 void writeFloat32BE(float32 value);
47 void writeFloat64BE(float64 value);
48 void writeInt16LE(
int16 value);
49 void writeUInt16LE(
uint16 value);
50 void writeInt24LE(
int32 value);
51 void writeUInt24LE(
uint32 value);
52 void writeInt32LE(
int32 value);
53 void writeUInt32LE(
uint32 value);
54 void writeInt40LE(
int64 value);
55 void writeUInt40LE(
uint64 value);
56 void writeInt56LE(
int64 value);
57 void writeUInt56LE(
uint64 value);
58 void writeInt64LE(
int64 value);
59 void writeUInt64LE(
uint64 value);
60 void writeVariableLengthUIntLE(
uint64 value);
61 void writeFloat32LE(float32 value);
62 void writeFloat64LE(float64 value);
63 void writeString(
const std::string &value);
64 void writeTerminatedString(
const std::string &value);
65 void writeLengthPrefixedString(
const std::string &value);
66 void writeLengthPrefixedCString(
const char *value, std::size_t size);
67 void writeBool(
bool value);
68 void writeSynchsafeUInt32BE(
uint32 valueToConvertAndWrite);
69 void writeFixed8BE(float32 valueToConvertAndWrite);
70 void writeFixed16BE(float32 valueToConvertAndWrite);
71 void writeSynchsafeUInt32LE(
uint32 valueToConvertAndWrite);
72 void writeFixed8LE(float32 valueToConvertAndWrite);
73 void writeFixed16LE(float32 valueToConvertAndWrite);
76 void write(
char oneChar);
77 void write(
byte oneByte);
78 void write(
bool oneBool);
79 void write(
const std::string &lengthPrefixedString);
80 void write(
const char *lengthPrefixedString);
81 void write(
int16 one16BitInt);
82 void write(
uint16 one16BitUint);
83 void write(
int32 one32BitInt);
84 void write(
uint32 one32BitUint);
85 void write(
int64 one64BitInt);
86 void write(
uint64 one64BitUint);
87 void write(float32 one32BitFloat);
88 void write(float64 one64BitFloat);
93 std::ostream *m_stream;
169 return m_stream ? m_stream->fail() :
false;
177 m_stream->write(buffer, length);
186 m_stream->write(buffer.data(), length);
195 m_stream->write(m_buffer, 1);
203 m_buffer[0] = *reinterpret_cast<char *>(&value);
204 m_stream->write(m_buffer, 1);
221 m_stream->write(m_buffer,
sizeof(
int16));
230 m_stream->write(m_buffer,
sizeof(
uint16));
240 m_stream->write(m_buffer + 1, 3);
251 m_stream->write(m_buffer + 1, 3);
260 m_stream->write(m_buffer,
sizeof(
int32));
269 m_stream->write(m_buffer,
sizeof(
uint32));
279 m_stream->write(m_buffer + 3, 5);
289 m_stream->write(m_buffer + 3, 5);
299 m_stream->write(m_buffer + 1, 7);
309 m_stream->write(m_buffer + 1, 7);
318 m_stream->write(m_buffer,
sizeof(
int64));
327 m_stream->write(m_buffer,
sizeof(
uint64));
345 m_stream->write(m_buffer,
sizeof(float32));
354 m_stream->write(m_buffer,
sizeof(float64));
363 m_stream->write(m_buffer,
sizeof(
int16));
372 m_stream->write(m_buffer,
sizeof(
uint16));
383 m_stream->write(m_buffer, 3);
394 m_stream->write(m_buffer, 3);
403 m_stream->write(m_buffer,
sizeof(
int32));
412 m_stream->write(m_buffer,
sizeof(
uint32));
422 m_stream->write(m_buffer, 5);
432 m_stream->write(m_buffer, 5);
442 m_stream->write(m_buffer, 7);
452 m_stream->write(m_buffer, 7);
461 m_stream->write(m_buffer,
sizeof(
int64));
470 m_stream->write(m_buffer,
sizeof(
uint64));
488 m_stream->write(m_buffer,
sizeof(float32));
497 m_stream->write(m_buffer,
sizeof(float64));
505 m_stream->write(value.c_str(), value.length());
513 m_stream->write(value.c_str(), value.length() + 1);
677 #endif // IO_UTILITIES_BINARYWRITER_H void writeVariableLengthUIntLE(uint64 value)
Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the cur...
void writeSynchsafeUInt32BE(uint32 valueToConvertAndWrite)
Writes a 32-bit big endian synchsafe integer to the current stream and advances the current position ...
void writeInt24LE(int32 value)
Writes a 24-bit little endian signed integer to the current stream and advances the current position ...
std::int64_t int64
signed 64-bit integer
void writeFloat64LE(float64 value)
Writes a 64-bit little endian floating point value to the current stream and advances the current pos...
void writeInt56LE(int64 value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
CPP_UTILITIES_EXPORT constexpr uint16 toFixed8(float32 float32value)
Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number.
bool hasOwnership() const
Returns whether the writer takes ownership over the assigned stream.
Writes primitive data types to a std::ostream.
#define CPP_UTILITIES_EXPORT
void writeInt40LE(int64 value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
void writeUInt24BE(uint32 value)
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position o...
void writeUInt16BE(uint16 value)
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position o...
void writeUInt56BE(uint64 value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
std::uint64_t uint64
unsigned 64-bit integer
void writeUInt40BE(uint64 value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
void writeByte(byte value)
Writes a single byte to the current stream and advances the current position of the stream by one byt...
void writeUInt16LE(uint16 value)
Writes a 16-bit little endian unsigned integer to the current stream and advances the current positio...
void writeBool(bool value)
Writes a boolean value to the current stream and advances the current position of the stream by one b...
void writeUInt24LE(uint32 value)
Writes a 24-bit little endian unsigned integer to the current stream and advances the current positio...
void giveOwnership()
The writer will take ownership over the assigned stream.
void writeVariableLengthUIntBE(uint64 value)
Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the curren...
void writeInt16LE(int16 value)
Writes a 16-bit little endian signed integer to the current stream and advances the current position ...
void flush()
Calls the flush() method of the assigned stream.
void writeFloat64BE(float64 value)
Writes a 64-bit big endian floating point value to the current stream and advances the current positi...
void writeFloat32BE(float32 value)
Writes a 32-bit big endian floating point value to the current stream and advances the current positi...
Contains utility classes helping to read and write streams.
void detatchOwnership()
The writer will not take ownership over the assigned stream.
void writeUInt40LE(uint64 value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
void writeSynchsafeUInt32LE(uint32 valueToConvertAndWrite)
Writes a 32-bit little endian synchsafe integer to the current stream and advances the current positi...
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...
void writeString(const std::string &value)
Writes a string to the current stream and advances the current position of the stream by the length o...
void writeInt56BE(int64 value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
void writeChar(char value)
Writes a single character to the current stream and advances the current position of the stream by on...
std::uint32_t uint32
unsigned 32-bit integer
void writeFixed8LE(float32 valueToConvertAndWrite)
Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point value...
void writeUInt56LE(uint64 value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
void writeUInt32LE(uint32 value)
Writes a 32-bit little endian unsigned integer to the current stream and advances the current positio...
void writeInt32LE(int32 value)
Writes a 32-bit little endian signed integer to the current stream and advances the current position ...
void writeInt16BE(int16 value)
Writes a 16-bit big endian signed integer to the current stream and advances the current position of ...
void writeInt64LE(int64 value)
Writes a 64-bit little endian signed integer to the current stream and advances the current position ...
std::int32_t int32
signed 32-bit integer
CPP_UTILITIES_EXPORT constexpr uint32 toSynchsafeInt(uint32 normalInt)
Returns a 32-bit synchsafe integer converted from a normal 32-bit integer.
void writeFixed8BE(float32 valueToConvertAndWrite)
Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point value to...
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
void writeUInt32BE(uint32 value)
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position o...
void writeInt24BE(int32 value)
Writes a 24-bit big endian signed integer to the current stream and advances the current position of ...
void writeFloat32LE(float32 value)
Writes a 32-bit little endian floating point value to the current stream and advances the current pos...
void writeLengthPrefixedCString(const char *value, std::size_t size)
Writes the length of a string and the string itself to the current stream.
void writeFixed16BE(float32 valueToConvertAndWrite)
Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point value ...
void writeInt64BE(int64 value)
Writes a 64-bit big endian signed integer to the current stream and advances the current position of ...
CPP_UTILITIES_EXPORT void getBytes(int16 value, char *outputbuffer)
Stores the specified 16-bit signed integer value at a specified position in a char array.
void writeUInt64LE(uint64 value)
Writes a 64-bit little endian unsigned integer to the current stream and advances the current positio...
std::int16_t int16
signed 16-bit integer
void writeInt32BE(int32 value)
Writes a 32-bit big endian signed integer to the current stream and advances the current position of ...
CPP_UTILITIES_EXPORT constexpr uint32 toFixed16(float32 float32value)
Returns the 16.16 fixed point representation converted from the specified 32-bit floating point numbe...
void writeFixed16LE(float32 valueToConvertAndWrite)
Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point val...
void writeUInt64BE(uint64 value)
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position o...
void writeTerminatedString(const std::string &value)
Writes a terminated string to the current stream and advances the current position of the stream by t...
bool fail() const
Returns an indication whether the fail bit of the assigned stream is set.
std::uint16_t uint16
unsigned 16-bit integer
CPP_UTILITIES_EXPORT void getBytes(int16 value, char *outputbuffer)
Stores the specified 16-bit signed integer value at a specified position in a char array.
void writeInt40BE(int64 value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...