1 #ifndef IOUTILITIES_BINARYWRITER_H 2 #define IOUTILITIES_BINARYWRITER_H 4 #include "../conversion/binaryconversion.h" 5 #include "../conversion/types.h" 20 const std::ostream *stream()
const;
21 std::ostream *stream();
22 void setStream(std::ostream *stream,
bool giveOwnership =
false);
23 bool hasOwnership()
const;
25 void detatchOwnership();
28 void write(
const char *buffer, std::streamsize length);
29 void write(
const std::vector<char> &buffer, std::streamsize length);
30 void writeChar(
char value);
31 void writeByte(
byte value);
32 void writeInt16BE(
int16 value);
33 void writeUInt16BE(
uint16 value);
34 void writeInt24BE(
int32 value);
35 void writeUInt24BE(
uint32 value);
36 void writeInt32BE(
int32 value);
37 void writeUInt32BE(
uint32 value);
38 void writeInt40BE(
int64 value);
39 void writeUInt40BE(
uint64 value);
40 void writeInt56BE(
int64 value);
41 void writeUInt56BE(
uint64 value);
42 void writeInt64BE(
int64 value);
43 void writeUInt64BE(
uint64 value);
44 void writeFloat32BE(float32 value);
45 void writeFloat64BE(float64 value);
46 void writeInt16LE(
int16 value);
47 void writeUInt16LE(
uint16 value);
48 void writeInt24LE(
int32 value);
49 void writeUInt24LE(
uint32 value);
50 void writeInt32LE(
int32 value);
51 void writeUInt32LE(
uint32 value);
52 void writeInt40LE(
int64 value);
53 void writeUInt40LE(
uint64 value);
54 void writeInt56LE(
int64 value);
55 void writeUInt56LE(
uint64 value);
56 void writeInt64LE(
int64 value);
57 void writeUInt64LE(
uint64 value);
58 void writeFloat32LE(float32 value);
59 void writeFloat64LE(float64 value);
60 void writeString(
const std::string &value);
61 void writeTerminatedString(
const std::string &value);
62 void writeLengthPrefixedString(
const std::string &value);
63 void writeBool(
bool value);
64 void writeSynchsafeUInt32BE(
uint32 valueToConvertAndWrite);
65 void writeFixed8BE(float32 valueToConvertAndWrite);
66 void writeFixed16BE(float32 valueToConvertAndWrite);
67 void writeSynchsafeUInt32LE(
uint32 valueToConvertAndWrite);
68 void writeFixed8LE(float32 valueToConvertAndWrite);
69 void writeFixed16LE(float32 valueToConvertAndWrite);
72 std::ostream *m_stream;
148 return m_stream ? m_stream->fail() :
false;
156 m_stream->write(buffer, length);
165 m_stream->write(buffer.data(), length);
174 m_stream->write(m_buffer, 1);
182 m_buffer[0] = *
reinterpret_cast<char *
>(&value);
183 m_stream->write(m_buffer, 1);
191 writeByte(value ? 1 : 0);
199 ConversionUtilities::BE::getBytes(value, m_buffer);
200 m_stream->write(m_buffer,
sizeof(
int16));
208 ConversionUtilities::BE::getBytes(value, m_buffer);
209 m_stream->write(m_buffer,
sizeof(
uint16));
218 ConversionUtilities::BE::getBytes(value, m_buffer);
219 m_stream->write(m_buffer + 1, 3);
229 ConversionUtilities::BE::getBytes(value, m_buffer);
230 m_stream->write(m_buffer + 1, 3);
238 ConversionUtilities::BE::getBytes(value, m_buffer);
239 m_stream->write(m_buffer,
sizeof(
int32));
247 ConversionUtilities::BE::getBytes(value, m_buffer);
248 m_stream->write(m_buffer,
sizeof(
uint32));
257 ConversionUtilities::BE::getBytes(value, m_buffer);
258 m_stream->write(m_buffer + 3, 5);
267 ConversionUtilities::BE::getBytes(value, m_buffer);
268 m_stream->write(m_buffer + 3, 5);
277 ConversionUtilities::BE::getBytes(value, m_buffer);
278 m_stream->write(m_buffer + 1, 7);
287 ConversionUtilities::BE::getBytes(value, m_buffer);
288 m_stream->write(m_buffer + 1, 7);
296 ConversionUtilities::BE::getBytes(value, m_buffer);
297 m_stream->write(m_buffer,
sizeof(
int64));
305 ConversionUtilities::BE::getBytes(value, m_buffer);
306 m_stream->write(m_buffer,
sizeof(
uint64));
314 ConversionUtilities::BE::getBytes(value, m_buffer);
315 m_stream->write(m_buffer,
sizeof(float32));
323 ConversionUtilities::BE::getBytes(value, m_buffer);
324 m_stream->write(m_buffer,
sizeof(float64));
332 ConversionUtilities::LE::getBytes(value, m_buffer);
333 m_stream->write(m_buffer,
sizeof(
int16));
341 ConversionUtilities::LE::getBytes(value, m_buffer);
342 m_stream->write(m_buffer,
sizeof(
uint16));
352 ConversionUtilities::LE::getBytes(value, m_buffer);
353 m_stream->write(m_buffer, 3);
363 ConversionUtilities::LE::getBytes(value, m_buffer);
364 m_stream->write(m_buffer, 3);
372 ConversionUtilities::LE::getBytes(value, m_buffer);
373 m_stream->write(m_buffer,
sizeof(
int32));
381 ConversionUtilities::LE::getBytes(value, m_buffer);
382 m_stream->write(m_buffer,
sizeof(
uint32));
391 ConversionUtilities::LE::getBytes(value, m_buffer);
392 m_stream->write(m_buffer, 5);
401 ConversionUtilities::LE::getBytes(value, m_buffer);
402 m_stream->write(m_buffer, 5);
411 ConversionUtilities::LE::getBytes(value, m_buffer);
412 m_stream->write(m_buffer, 7);
421 ConversionUtilities::LE::getBytes(value, m_buffer);
422 m_stream->write(m_buffer, 7);
430 ConversionUtilities::LE::getBytes(value, m_buffer);
431 m_stream->write(m_buffer,
sizeof(
int64));
439 ConversionUtilities::LE::getBytes(value, m_buffer);
440 m_stream->write(m_buffer,
sizeof(
uint64));
448 ConversionUtilities::LE::getBytes(value, m_buffer);
449 m_stream->write(m_buffer,
sizeof(float32));
457 ConversionUtilities::LE::getBytes(value, m_buffer);
458 m_stream->write(m_buffer,
sizeof(float64));
466 m_stream->write(value.c_str(), value.length());
474 m_stream->write(value.c_str(), value.length() + 1);
530 #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 ...