29template <
typename T>
inline void readFromStream(std::istream &stream, T &
value) {
30 stream.read(
reinterpret_cast<char *
>(&
value),
sizeof(T));
41template <
typename T>
inline void readFromStream(std::istream &stream, std::vector<T> &
value,
size_t nvals) {
42 if (
value.size() < nvals)
44 stream.read(
reinterpret_cast<char *
>(
value.data()), nvals *
sizeof(T));
57inline void readFromStream(std::istream &stream, Matrix<T> &
value,
const std::vector<int32_t> &shape,
59 assert(2 <= shape.size());
60 const size_t s0(shape[0]), s1(shape[1]), totalLength(s0 * s1);
61 std::vector<T> buffer;
62 readFromStream(stream, buffer, totalLength);
63 value = Matrix<T>(s0, s1);
65 for (
size_t i = 0; i < s0; ++i) {
67 const size_t offset = i * s1;
68 for (
size_t j = 0; j < s1; ++j) {
69 row[j] = buffer[offset + j];
73 for (
size_t i = 0; i < s0; ++i) {
75 for (
size_t j = 0; j < s1; ++j) {
76 row[j] = buffer[j * s0 + i];
94 : m_istrm(istrm), m_strLengthSize(static_cast<uint64_t>(sizeof(int32_t))) {
96 throw std::runtime_error(
"BinaryStreamReader: Input stream is in a bad state. Cannot continue.");
163 value.resize(
static_cast<std::string::size_type
>(length));
164 m_istrm.read(
const_cast<char *
>(
value.data()),
static_cast<size_t>(length));
250 value.resize(length);
266 assert(2 <= shape.size());
268 const size_t s0(shape[0]), s1(shape[1]), totalLength(s0 * s1);
270 this->
read(buffer, totalLength);
274 for (
auto &str :
value) {
275 str = buffer.substr(pos, s1);
279 for (
size_t i = 0; i < s0; ++i) {
280 auto &str =
value[i];
282 for (
size_t j = 0; j < s1; ++j) {
283 str[j] = buffer[j * s0 + i];
double value
The value of the point.
Assists with reading a binary file by providing standard overloads for the istream operators (>>) to ...
BinaryStreamReader(std::istream &istrm)
Constructor taking the stream to read.
BinaryStreamReader & operator>>(int16_t &value)
Read a int16_t from the stream.
std::istream & m_istrm
Reference to the stream being read.
uint64_t m_strLengthSize
The default size in bytes of the type used to encode the length of a string in the file.
MatrixOrdering
Define the ordering of 2D structures in the file.
BinaryStreamReader & read(std::vector< int16_t > &value, const size_t nvals)
Read an array of int16_t into the given vector.
void moveStreamToPosition(size_t nbytes)
Move the stream to nbytes past the beginning of the file.