Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
Mantid::Kernel::BinaryStreamReader Class Reference

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
BinaryStreamReaderoperator>> (int16_t &value)
 Read a int16_t from the stream. More...
 
BinaryStreamReaderoperator>> (int32_t &value)
 Read a int32_t from the stream. More...
 
BinaryStreamReaderoperator>> (int64_t &value)
 Read a int64_t from the stream. More...
 
BinaryStreamReaderoperator>> (float &value)
 Read a float (4-bytes) from the stream. More...
 
BinaryStreamReaderoperator>> (double &value)
 Read a double (8-bytes) from the stream. More...
 
BinaryStreamReaderoperator>> (std::string &value)
 Read a string of characters into given object. More...
 
BinaryStreamReaderoperator>> (uint16_t &value)
 Read a uint16_t from the stream. More...
 
BinaryStreamReaderoperator>> (uint32_t &value)
 Read a uint32_t from the stream. More...
 
1D methods
BinaryStreamReaderread (std::vector< int16_t > &value, const size_t nvals)
 Read an array of int16_t into the given vector. More...
 
BinaryStreamReaderread (std::vector< int32_t > &value, const size_t nvals)
 Read an array of int32_t into the given vector. More...
 
BinaryStreamReaderread (std::vector< int64_t > &value, const size_t nvals)
 Read an array of int64_t into the given vector. More...
 
BinaryStreamReaderread (std::vector< float > &value, const size_t nvals)
 Read an array of float balues into the given vector. More...
 
BinaryStreamReaderread (std::vector< double > &value, const size_t nvals)
 Read an array of double values into the given vector. More...
 
BinaryStreamReaderread (std::string &value, const size_t length)
 Read a series of characters into a string object. More...
 
2D methods
BinaryStreamReaderread (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...
 
BinaryStreamReaderread (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...
 
BinaryStreamReaderread (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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ MatrixOrdering

Define the ordering of 2D structures in the file.

Enumerator
RowMajor 
ColumnMajor 

Definition at line 35 of file BinaryStreamReader.h.

Constructor & Destructor Documentation

◆ BinaryStreamReader()

Mantid::Kernel::BinaryStreamReader::BinaryStreamReader ( std::istream &  istrm)

Constructor taking the stream to read.

Parameters
istrmAn 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.

Member Function Documentation

◆ moveStreamToPosition()

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.

Parameters
nbytesThe 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().

◆ operator>>() [1/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( double &  value)

Read a double (8-bytes) from the stream.

Parameters
valueThe value is stored in this object
Returns
A reference to the BinaryStreamReader object

Definition at line 145 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [2/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( float &  value)

Read a float (4-bytes) from the stream.

Parameters
valueThe value is stored in the given stream
Returns
A reference to the BinaryStreamReader object

Definition at line 135 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [3/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( int16_t &  value)

Read a int16_t from the stream.

Parameters
valuethe value is stored in the given stream
Returns
BinaryStreamReader&

Definition at line 105 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [4/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( int32_t &  value)

Read a int32_t from the stream.

Parameters
valueThe value is stored in the given stream
Returns
A reference to the BinaryStreamReader object

Definition at line 115 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [5/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( int64_t &  value)

Read a int64_t from the stream.

Parameters
valueThe value is stored in the given stream
Returns
A reference to the BinaryStreamReader object

Definition at line 125 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [6/8]

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.

Parameters
valueThe string value is stored in the given object. It is resized to the appropriate length
Returns
A reference to the BinaryStreamReader object

Definition at line 158 of file BinaryStreamReader.cpp.

References m_istrm, m_strLengthSize, and value.

◆ operator>>() [7/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( uint16_t &  value)

Read a uint16_t from the stream.

Parameters
valueThe value is stored in the given stream
Returns
A reference to the BinaryStreamReader object

Definition at line 173 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ operator>>() [8/8]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::operator>> ( uint32_t &  value)

Read a uint32_t from the stream.

Parameters
valueThe value is stored in the given stream
Returns
A reference to the BinaryStreamReader object

Definition at line 183 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [1/9]

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.

Parameters
valueThe Matrix to fill. Its size is increased if necessary
shape2D-vector defined as (nrows, ncols)
orderDefines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor)
Returns
A reference to the BinaryStreamReader object

Definition at line 314 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [2/9]

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.

Parameters
valueThe Matrix to fill. Its size is increased if necessary
shape2D-vector defined as (nrows, ncols)
orderDefines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor)
Returns
A reference to the BinaryStreamReader object

Definition at line 299 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [3/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::string &  value,
const size_t  length 
)

Read a series of characters into a string object.

Parameters
valueThe string to fill. Its size is increased if necessary
lengthThe number characters to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

Definition at line 249 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [4/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::vector< double > &  value,
const size_t  nvals 
)

Read an array of double values into the given vector.

Parameters
valueThe array to fill. Its size is increased if necessary
nvalsThe number values to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

Definition at line 238 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [5/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::vector< float > &  value,
const size_t  nvals 
)

Read an array of float balues into the given vector.

Parameters
valueThe array to fill. Its size is increased if necessary
nvalsThe number values to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

Definition at line 227 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [6/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::vector< int16_t > &  value,
const size_t  nvals 
)

Read an array of int16_t into the given vector.

Parameters
valueThe array to fille. Its size is increased if necessary
nvalsThe number values to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

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().

◆ read() [7/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::vector< int32_t > &  value,
const size_t  nvals 
)

Read an array of int32_t into the given vector.

Parameters
valueThe array to fill. Its size is increased if necessary
nvalsThe number values to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

Definition at line 205 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [8/9]

BinaryStreamReader & Mantid::Kernel::BinaryStreamReader::read ( std::vector< int64_t > &  value,
const size_t  nvals 
)

Read an array of int64_t into the given vector.

Parameters
valueThe array to fill. Its size is increased if necessary
nvalsThe number values to attempt to read from the stream
Returns
A reference to the BinaryStreamReader object

Definition at line 216 of file BinaryStreamReader.cpp.

References m_istrm, and value.

◆ read() [9/9]

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.

Parameters
valueThe array to fill. Its size is increased if necessary
shape2D-vector defined as (nstrs, strLength)
orderDefines whether the stream of bytes is interpreted as moving across the rows first (RowMajor) or down columns first (ColumnMajor)
Returns
A reference to the BinaryStreamReader object

Definition at line 264 of file BinaryStreamReader.cpp.

References read(), RowMajor, and value.

Member Data Documentation

◆ m_istrm

std::istream& Mantid::Kernel::BinaryStreamReader::m_istrm
private

Reference to the stream being read.

Definition at line 73 of file BinaryStreamReader.h.

Referenced by moveStreamToPosition(), operator>>(), and read().

◆ m_strLengthSize

uint64_t Mantid::Kernel::BinaryStreamReader::m_strLengthSize
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>>().


The documentation for this class was generated from the following files: