|
Orrery
A GPU-accelerated N-body gravitational simulator
|
Writes the scalar types the formats in this layer are built from. More...
#include <orrery/sim/binary_stream.hpp>
Public Member Functions | |
| BinaryWriter (std::ostream &out) noexcept | |
| void | write_u8 (std::uint8_t value) |
| void | write_u32 (std::uint32_t value) |
| void | write_u64 (std::uint64_t value) |
| void | write_real (core::Real value) |
| Write a Real as its IEEE 754 bit pattern, four bytes or eight according to the precision this build was configured with. | |
| void | write_reals (std::span< const core::Real > values) |
| Write a contiguous run of Real, which is how both formats carry particle components. | |
| void | write_bytes (std::string_view text) |
| Write the exact bytes of text, with no length prefix and no terminator. | |
| void | write_string (std::string_view text) |
| Write a 32-bit length followed by that many bytes. | |
| std::uint64_t | checksum () const noexcept |
| The checksum of everything written so far. | |
| bool | ok () const noexcept |
| Whether every write so far reached the stream. | |
Writes the scalar types the formats in this layer are built from.
Holds the stream by reference and does not own it, so that a caller can write a header through one of these and the bulk arrays through another, or wrap a std::ostringstream in a test rather than a file. The checksum accumulates across everything one instance writes, which is why the caller keeps hold of it rather than making a fresh one per field.
|
inline |
Write a Real as its IEEE 754 bit pattern, four bytes or eight according to the precision this build was configured with.
The formats record which in their headers, so a reader can refuse a file rather than silently read a double-precision checkpoint as twice as many single-precision particles.
| void orrery::sim::BinaryWriter::write_bytes | ( | std::string_view | text | ) |
Write the exact bytes of text, with no length prefix and no terminator.
For the fixed-length magic strings at the head of each format. Anything of variable length is written as a length followed by the bytes, which is what write_string does.
|
inlinenodiscardnoexcept |
Whether every write so far reached the stream.
Checked once at the end of a format rather than after each field. A stream that has failed stays failed, so a single test after the last write catches a failure at any point in it, and a disc that filled up halfway through a million particles should not cost a branch per component.