1 #ifndef IOUTILITIES_BINARYWRITER_H 2 #define IOUTILITIES_BINARYWRITER_H 4 #include "../conversion/types.h" 5 #include "../conversion/binaryconversion.h" 22 const std::ostream *stream()
const;
23 std::ostream *stream();
24 void setStream(std::ostream *stream,
bool giveOwnership =
false);
25 bool hasOwnership()
const;
27 void detatchOwnership();
30 void write(
const char *buffer, std::streamsize length);
31 void write(
const std::vector<char> &buffer, std::streamsize length);
32 void writeChar(
char value);
33 void writeByte(
byte value);
34 void writeInt16BE(
int16 value);
35 void writeUInt16BE(
uint16 value);
36 void writeInt24BE(
int32 value);
37 void writeUInt24BE(
uint32 value);
38 void writeInt32BE(
int32 value);
39 void writeUInt32BE(
uint32 value);
40 void writeInt40BE(
int64 value);
41 void writeUInt40BE(
uint64 value);
42 void writeInt56BE(
int64 value);
43 void writeUInt56BE(
uint64 value);
44 void writeInt64BE(
int64 value);
45 void writeUInt64BE(
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 writeFloat32LE(float32 value);
61 void writeFloat64LE(float64 value);
62 void writeString(
const std::string &value);
63 void writeTerminatedString(
const std::string &value);
64 void writeLengthPrefixedString(
const std::string &value);
65 void writeBool(
bool value);
66 void writeSynchsafeUInt32BE(
uint32 valueToConvertAndWrite);
67 void writeFixed8BE(float32 valueToConvertAndWrite);
68 void writeFixed16BE(float32 valueToConvertAndWrite);
69 void writeSynchsafeUInt32LE(
uint32 valueToConvertAndWrite);
70 void writeFixed8LE(float32 valueToConvertAndWrite);
71 void writeFixed16LE(float32 valueToConvertAndWrite);
74 std::ostream *m_stream;
150 return m_stream ? m_stream->fail() :
false;
158 m_stream->write(buffer, length);
167 m_stream->write(buffer.data(), length);
176 m_stream->write(m_buffer, 1);
184 m_buffer[0] = *
reinterpret_cast<char *
>(&value);
185 m_stream->write(m_buffer, 1);
193 writeByte(value ? 1 : 0);
201 ConversionUtilities::BE::getBytes(value, m_buffer);
202 m_stream->write(m_buffer,
sizeof(
int16));
210 ConversionUtilities::BE::getBytes(value, m_buffer);
211 m_stream->write(m_buffer,
sizeof(
uint16));
220 ConversionUtilities::BE::getBytes(value, m_buffer);
221 m_stream->write(m_buffer + 1, 3);
231 ConversionUtilities::BE::getBytes(value, m_buffer);
232 m_stream->write(m_buffer + 1, 3);
240 ConversionUtilities::BE::getBytes(value, m_buffer);
241 m_stream->write(m_buffer,
sizeof(
int32));
249 ConversionUtilities::BE::getBytes(value, m_buffer);
250 m_stream->write(m_buffer,
sizeof(
uint32));
259 ConversionUtilities::BE::getBytes(value, m_buffer);
260 m_stream->write(m_buffer + 3, 5);
269 ConversionUtilities::BE::getBytes(value, m_buffer);
270 m_stream->write(m_buffer + 3, 5);
279 ConversionUtilities::BE::getBytes(value, m_buffer);
280 m_stream->write(m_buffer + 1, 7);
289 ConversionUtilities::BE::getBytes(value, m_buffer);
290 m_stream->write(m_buffer + 1, 7);
298 ConversionUtilities::BE::getBytes(value, m_buffer);
299 m_stream->write(m_buffer,
sizeof(
int64));
307 ConversionUtilities::BE::getBytes(value, m_buffer);
308 m_stream->write(m_buffer,
sizeof(
uint64));
316 ConversionUtilities::BE::getBytes(value, m_buffer);
317 m_stream->write(m_buffer,
sizeof(float32));
325 ConversionUtilities::BE::getBytes(value, m_buffer);
326 m_stream->write(m_buffer,
sizeof(float64));
334 ConversionUtilities::LE::getBytes(value, m_buffer);
335 m_stream->write(m_buffer,
sizeof(
int16));
343 ConversionUtilities::LE::getBytes(value, m_buffer);
344 m_stream->write(m_buffer,
sizeof(
uint16));
354 ConversionUtilities::LE::getBytes(value, m_buffer);
355 m_stream->write(m_buffer, 3);
365 ConversionUtilities::LE::getBytes(value, m_buffer);
366 m_stream->write(m_buffer, 3);
374 ConversionUtilities::LE::getBytes(value, m_buffer);
375 m_stream->write(m_buffer,
sizeof(
int32));
383 ConversionUtilities::LE::getBytes(value, m_buffer);
384 m_stream->write(m_buffer,
sizeof(
uint32));
393 ConversionUtilities::LE::getBytes(value, m_buffer);
394 m_stream->write(m_buffer, 5);
403 ConversionUtilities::LE::getBytes(value, m_buffer);
404 m_stream->write(m_buffer, 5);
413 ConversionUtilities::LE::getBytes(value, m_buffer);
414 m_stream->write(m_buffer, 7);
423 ConversionUtilities::LE::getBytes(value, m_buffer);
424 m_stream->write(m_buffer, 7);
432 ConversionUtilities::LE::getBytes(value, m_buffer);
433 m_stream->write(m_buffer,
sizeof(
int64));
441 ConversionUtilities::LE::getBytes(value, m_buffer);
442 m_stream->write(m_buffer,
sizeof(
uint64));
450 ConversionUtilities::LE::getBytes(value, m_buffer);
451 m_stream->write(m_buffer,
sizeof(float32));
459 ConversionUtilities::LE::getBytes(value, m_buffer);
460 m_stream->write(m_buffer,
sizeof(float64));
468 m_stream->write(value.c_str(), value.length());
476 m_stream->write(value.c_str(), value.length() + 1);
533 #endif // IO_UTILITIES_BINARYWRITER_H 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.
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 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...
std::uint8_t byte
unsigned byte
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 ...
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...
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
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
void writeInt40BE(int64 value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...