Mantid
|
Assists with reading a binary file by providing standard overloads for the istream operators (>>) to given types (and vectors of those types). More...
#include <BinaryStreamReader.h>
Public Types | |
enum class | MatrixOrdering { RowMajor , ColumnMajor } |
Define the ordering of 2D structures in the file. More... | |
Public Member Functions | |
BinaryStreamReader (std::istream &istrm) | |
Constructor taking the stream to read. More... | |
void | moveStreamToPosition (size_t nbytes) |
Move the stream to nbytes past the beginning of the file. More... | |
Single-value stream operators | |
BinaryStreamReader & | operator>> (int16_t &value) |
Read a int16_t from the stream. More... | |
BinaryStreamReader & | operator>> (int32_t &value) |
Read a int32_t from the stream. More... | |
BinaryStreamReader & | operator>> (int64_t &value) |
Read a int64_t from the stream. More... | |
BinaryStreamReader & | operator>> (float &value) |
Read a float (4-bytes) from the stream. More... | |
BinaryStreamReader & | operator>> (double &value) |
Read a double (8-bytes) from the stream. More... | |
BinaryStreamReader & | operator>> (std::string &value) |
Read a string of characters into given object. More... | |
BinaryStreamReader & | operator>> (uint16_t &value) |
Read a uint16_t from the stream. More... | |
BinaryStreamReader & | operator>> (uint32_t &value) |
Read a uint32_t from the stream. More... | |
1D methods | |
BinaryStreamReader & | read (std::vector< int16_t > &value, const size_t nvals) |
Read an array of int16_t into the given vector. More... | |
BinaryStreamReader & | read (std::vector< int32_t > &value, const size_t nvals) |
Read an array of int32_t into the given vector. More... | |
BinaryStreamReader & | read (std::vector< int64_t > &value, const size_t nvals) |
Read an array of int64_t into the given vector. More... | |
BinaryStreamReader & | read (std::vector< float > &value, const size_t nvals) |
Read an array of float balues into the given vector. More... | |
BinaryStreamReader & | read (std::vector< double > &value, const size_t nvals) |
Read an array of double values into the given vector. More... | |
BinaryStreamReader & | read (std::string &value, const size_t length) |
Read a series of characters into a string object. More... | |
2D methods | |
BinaryStreamReader & | read (std::vector< std::string > &value, const std::vector< int32_t > &shape, MatrixOrdering order) |
Read a stream of characters and interpret them as a 2D matrix of specified shape & order. More... | |
BinaryStreamReader & | read (Kernel::Matrix< float > &value, const std::vector< int32_t > &shape, MatrixOrdering order) |
Read a stream of floats and interpret them as a 2D matrix of specified shape & order. More... | |
BinaryStreamReader & | read (Kernel::Matrix< double > &value, const std::vector< int32_t > &shape, MatrixOrdering order) |
Read a stream of doubles and interpret them as a 2D matrix of specified shape & order. More... | |
Private Attributes | |
std::istream & | m_istrm |
Reference to the stream being read. More... | |
uint64_t | m_strLengthSize |
The default size in bytes of the type used to encode the length of a string in the file. More... | |
Assists with reading a binary file by providing standard overloads for the istream operators (>>) to given types (and vectors of those types).
It only allows for reading fixed-width integer types to avoid cross-platform differences on the sizes of various types.
Definition at line 32 of file BinaryStreamReader.h.
|
strong |
Define the ordering of 2D structures in the file.
Enumerator | |
---|---|
RowMajor | |
ColumnMajor |
Definition at line 35 of file BinaryStreamReader.h.
Mantid::Kernel::BinaryStreamReader::BinaryStreamReader | ( | std::istream & | istrm | ) |
Constructor taking the stream to read.
istrm | An open stream from which data will be read. The object does not take ownership of the stream. The caller is responsible for closing it. |
Definition at line 93 of file BinaryStreamReader.cpp.
void Mantid::Kernel::BinaryStreamReader::moveStreamToPosition | ( | size_t | nbytes | ) |
Move the stream to nbytes past the beginning of the file.
Will move the stream to the given position.
nbytes | The number of bytes from position 0 to move |
Definition at line 324 of file BinaryStreamReader.cpp.
References m_istrm.
Referenced by Mantid::DataHandling::LoadPSIMuonBin::readArrayVariables(), Mantid::DataHandling::LoadPSIMuonBin::readInHistograms(), Mantid::DataHandling::LoadBinaryStl::readShape(), Mantid::DataHandling::LoadPSIMuonBin::readSingleVariables(), and Mantid::DataHandling::LoadPSIMuonBin::readStringVariables().
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | double & | value | ) |
Read a double (8-bytes) from the stream.
value | The value is stored in this object |
Definition at line 145 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | float & | value | ) |
Read a float (4-bytes) from the stream.
value | The value is stored in the given stream |
Definition at line 135 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | int16_t & | value | ) |
Read a int16_t from the stream.
value | the value is stored in the given stream |
Definition at line 105 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | int32_t & | value | ) |
Read a int32_t from the stream.
value | The value is stored in the given stream |
Definition at line 115 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | int64_t & | value | ) |
Read a int64_t from the stream.
value | The value is stored in the given stream |
Definition at line 125 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | std::string & | value | ) |
Read a string of characters into given object.
This method assumes that the stream currently points at a type specifying the length followed directly by the string itself.
value | The string value is stored in the given object. It is resized to the appropriate length |
Definition at line 158 of file BinaryStreamReader.cpp.
References m_istrm, m_strLengthSize, and value.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | uint16_t & | value | ) |
Read a uint16_t from the stream.
value | The value is stored in the given stream |
Definition at line 173 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> | ( | uint32_t & | value | ) |
Read a uint32_t from the stream.
value | The value is stored in the given stream |
Definition at line 183 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | Kernel::Matrix< double > & | value, |
const std::vector< int32_t > & | shape, | ||
BinaryStreamReader::MatrixOrdering | order | ||
) |
Read a stream of doubles and interpret them as a 2D matrix of specified shape & order.
value | The Matrix to fill. Its size is increased if necessary |
shape | 2D-vector defined as (nrows, ncols) |
order | Defines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor) |
Definition at line 314 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | Kernel::Matrix< float > & | value, |
const std::vector< int32_t > & | shape, | ||
BinaryStreamReader::MatrixOrdering | order | ||
) |
Read a stream of floats and interpret them as a 2D matrix of specified shape & order.
value | The Matrix to fill. Its size is increased if necessary |
shape | 2D-vector defined as (nrows, ncols) |
order | Defines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor) |
Definition at line 299 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::string & | value, |
const size_t | length | ||
) |
Read a series of characters into a string object.
value | The string to fill. Its size is increased if necessary |
length | The number characters to attempt to read from the stream |
Definition at line 249 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< double > & | value, |
const size_t | nvals | ||
) |
Read an array of double values into the given vector.
value | The array to fill. Its size is increased if necessary |
nvals | The number values to attempt to read from the stream |
Definition at line 238 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< float > & | value, |
const size_t | nvals | ||
) |
Read an array of float balues into the given vector.
value | The array to fill. Its size is increased if necessary |
nvals | The number values to attempt to read from the stream |
Definition at line 227 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< int16_t > & | value, |
const size_t | nvals | ||
) |
Read an array of int16_t into the given vector.
value | The array to fille. Its size is increased if necessary |
nvals | The number values to attempt to read from the stream |
Definition at line 194 of file BinaryStreamReader.cpp.
References m_istrm, and value.
Referenced by Mantid::DataHandling::LoadPSIMuonBin::confidence(), Mantid::DataHandling::LoadPSIMuonBin::exec(), read(), Mantid::DataHandling::LoadPSIMuonBin::readArrayVariables(), and Mantid::DataHandling::LoadPSIMuonBin::readStringVariables().
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< int32_t > & | value, |
const size_t | nvals | ||
) |
Read an array of int32_t into the given vector.
value | The array to fill. Its size is increased if necessary |
nvals | The number values to attempt to read from the stream |
Definition at line 205 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< int64_t > & | value, |
const size_t | nvals | ||
) |
Read an array of int64_t into the given vector.
value | The array to fill. Its size is increased if necessary |
nvals | The number values to attempt to read from the stream |
Definition at line 216 of file BinaryStreamReader.cpp.
BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read | ( | std::vector< std::string > & | value, |
const std::vector< int32_t > & | shape, | ||
BinaryStreamReader::MatrixOrdering | order | ||
) |
Read a stream of characters and interpret them as a 2D matrix of specified shape & order.
value | The array to fill. Its size is increased if necessary |
shape | 2D-vector defined as (nstrs, strLength) |
order | Defines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor) |
Definition at line 264 of file BinaryStreamReader.cpp.
|
private |
Reference to the stream being read.
Definition at line 73 of file BinaryStreamReader.h.
Referenced by moveStreamToPosition(), operator>>(), and read().
|
private |
The default size in bytes of the type used to encode the length of a string in the file.
Used by operator>>(std::string&). Use largest fixed-width unsigned integer as sizeof(size_t) varies
Definition at line 77 of file BinaryStreamReader.h.
Referenced by operator>>().