Loading...
Searching...
No Matches
q3::internal::interpolation_stream Namespace Reference

Functions

template<typename ValueType >
std::vector< ValueType > read_array (std::istream &stream)
 
Matrix3x3 read_matrix (std::istream &stream)
 
template<typename ValueType >
std::vector< std::vector< ValueType > > read_nested_arrays (std::istream &stream)
 
template<typename ValueType >
ValueType read_scalar (std::istream &stream)
 
std::string read_string (std::istream &stream)
 
Vector3D read_vector3d (std::istream &stream)
 
void require_bytes_available (std::istream &stream, std::uint64_t bytes)
 
template<typename ValueType >
void write_array (std::ostream &stream, const std::vector< ValueType > &values)
 Length-prefixed array of trivially copyable values.
 
void write_matrix (std::ostream &stream, const Matrix3x3 &matrix)
 
template<typename ValueType >
void write_nested_arrays (std::ostream &stream, const std::vector< std::vector< ValueType > > &rows)
 
template<typename ValueType >
void write_scalar (std::ostream &stream, const ValueType &value)
 
void write_string (std::ostream &stream, const std::string &text)
 
void write_vector3d (std::ostream &stream, const Vector3D &vector)
 

Detailed Description

Length-prefixed little-endian primitives for Q3's own binary records.

Every read is bounded before it allocates: a count is checked against the bytes actually left in the file, so a corrupt or foreign length field is diagnosed as a corrupt file rather than becoming a multi-gigabyte allocation that surfaces as std::bad_alloc or libc++'s bare "vector".

io/mean_field_record/checkpoint.hpp carries its own copy of these, which has already diverged: it returns zero-filled values on a truncated read where these throw. Unifying the two is worth doing and is deliberately not done here, since it changes the behaviour of a record this branch does not otherwise touch.

Function Documentation

◆ read_array()

template<typename ValueType >
std::vector< ValueType > q3::internal::interpolation_stream::read_array ( std::istream &  stream)

Definition at line 117 of file binary_stream.hpp.

References require_bytes_available().

◆ read_matrix()

Matrix3x3 q3::internal::interpolation_stream::read_matrix ( std::istream &  stream)
inline

Definition at line 99 of file binary_stream.hpp.

References read_vector3d().

◆ read_nested_arrays()

template<typename ValueType >
std::vector< std::vector< ValueType > > q3::internal::interpolation_stream::read_nested_arrays ( std::istream &  stream)

Definition at line 145 of file binary_stream.hpp.

References require_bytes_available().

◆ read_scalar()

template<typename ValueType >
ValueType q3::internal::interpolation_stream::read_scalar ( std::istream &  stream)

Definition at line 34 of file binary_stream.hpp.

◆ read_string()

std::string q3::internal::interpolation_stream::read_string ( std::istream &  stream)
inline

Definition at line 65 of file binary_stream.hpp.

◆ read_vector3d()

Vector3D q3::internal::interpolation_stream::read_vector3d ( std::istream &  stream)
inline

◆ require_bytes_available()

void q3::internal::interpolation_stream::require_bytes_available ( std::istream &  stream,
std::uint64_t  bytes 
)
inline

A count read from the file, times an element size, must fit in what is left of the file. Without this a corrupt or foreign length field becomes a multi-gigabyte allocation (std::bad_alloc, or libc++'s bare "vector" length_error) instead of the "corrupt" diagnosis every other check gives.

Definition at line 49 of file binary_stream.hpp.

Referenced by q3::internal::wannier_payload::read(), read_array(), and read_nested_arrays().

◆ write_array()

template<typename ValueType >
void q3::internal::interpolation_stream::write_array ( std::ostream &  stream,
const std::vector< ValueType > &  values 
)

Length-prefixed array of trivially copyable values.

Definition at line 109 of file binary_stream.hpp.

Referenced by write_nested_arrays().

◆ write_matrix()

void q3::internal::interpolation_stream::write_matrix ( std::ostream &  stream,
const Matrix3x3 &  matrix 
)
inline

Definition at line 93 of file binary_stream.hpp.

References write_vector3d().

◆ write_nested_arrays()

template<typename ValueType >
void q3::internal::interpolation_stream::write_nested_arrays ( std::ostream &  stream,
const std::vector< std::vector< ValueType > > &  rows 
)

Definition at line 137 of file binary_stream.hpp.

References write_array().

Referenced by q3::internal::wannier_payload::write().

◆ write_scalar()

template<typename ValueType >
void q3::internal::interpolation_stream::write_scalar ( std::ostream &  stream,
const ValueType &  value 
)

Definition at line 30 of file binary_stream.hpp.

◆ write_string()

void q3::internal::interpolation_stream::write_string ( std::ostream &  stream,
const std::string &  text 
)
inline

Definition at line 60 of file binary_stream.hpp.

◆ write_vector3d()

void q3::internal::interpolation_stream::write_vector3d ( std::ostream &  stream,
const Vector3D &  vector 
)
inline