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

Assists with writing a binary file by providing standard overloads for the ostream operators (<<) to given types (and vectors of those types). More...

#include <BinaryStreamWriter.h>

Public Types

enum class  MatrixOrdering { RowMajor , ColumnMajor }
 Define the ordering of 2D structures in the file. More...
 

Public Member Functions

 BinaryStreamWriter (std::ostream &ofstrm)
 Constructor taking the stream to write. More...
 
Single-value stream operators
BinaryStreamWriteroperator<< (const int16_t &value)
 write a int16_t to the stream More...
 
BinaryStreamWriteroperator<< (const int32_t &value)
 write a int32_t to the stream More...
 
BinaryStreamWriteroperator<< (const int64_t &value)
 write a int64_t to the stream More...
 
BinaryStreamWriteroperator<< (const float &value)
 write a float (4-bytes) to the stream More...
 
BinaryStreamWriteroperator<< (const double &value)
 write a double (8-bytes) to the stream More...
 
BinaryStreamWriteroperator<< (const std::string &value)
 write a string of characters from given object. More...
 
BinaryStreamWriteroperator<< (const uint16_t &value)
 write a uint16_t to the stream More...
 
BinaryStreamWriteroperator<< (const uint32_t &value)
 write a uint32_t to the stream More...
 
1D methods
BinaryStreamWriterwrite (const std::vector< int16_t > &value, const size_t nvals)
 write an array of int16_t from the given vector. More...
 
BinaryStreamWriterwrite (const std::vector< int32_t > &value, const size_t nvals)
 write an array of int32_t from the given vector. More...
 
BinaryStreamWriterwrite (const std::vector< int64_t > &value, const size_t nvals)
 write an array of int64_t from the given vector. More...
 
BinaryStreamWriterwrite (const std::vector< float > &value, const size_t nvals)
 write an array of float balues from the given vector. More...
 
BinaryStreamWriterwrite (const std::vector< double > &value, const size_t nvals)
 write an array of double values from the given vector. More...
 
BinaryStreamWriterwrite (const std::string &value, const size_t length)
 write a series of characters from a string object. More...
 
2D methods
BinaryStreamWriterwrite (const std::vector< std::string > &value, const std::vector< int32_t > &shape, MatrixOrdering order)
 
BinaryStreamWriterwrite (const Kernel::Matrix< float > &value, const std::vector< int32_t > &shape, MatrixOrdering order)
 
BinaryStreamWriterwrite (const Kernel::Matrix< double > &value, const std::vector< int32_t > &shape, MatrixOrdering order)
 

Private Attributes

std::ostream & m_ofstrm
 Reference to the stream being written to. 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 writing a binary file by providing standard overloads for the ostream operators (<<) to given types (and vectors of those types).

It only allows for writing fixed-width integer types to avoid cross-platform differences on the sizes of various types.

Definition at line 32 of file BinaryStreamWriter.h.

Member Enumeration Documentation

◆ MatrixOrdering

Define the ordering of 2D structures in the file.

Enumerator
RowMajor 
ColumnMajor 

Definition at line 35 of file BinaryStreamWriter.h.

Constructor & Destructor Documentation

◆ BinaryStreamWriter()

Mantid::Kernel::BinaryStreamWriter::BinaryStreamWriter ( std::ostream &  ofstrm)

Constructor taking the stream to write.

Parameters
ofstrmAn open stream from which data will be write. The object does not take ownership of the stream. The caller is responsible for closing it.

Definition at line 56 of file BinaryStreamWriter.cpp.

Member Function Documentation

◆ operator<<() [1/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const double &  value)

write a double (8-bytes) to the stream

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

Definition at line 109 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [2/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const float &  value)

write a float (4-bytes) to the stream

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

Definition at line 99 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [3/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const int16_t &  value)

write a int16_t to the stream

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

Definition at line 69 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [4/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const int32_t &  value)

write a int32_t to the stream

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

Definition at line 79 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [5/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const int64_t &  value)

write a int64_t to the stream

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

Definition at line 89 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [6/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const std::string &  value)

write a string of characters from 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 BinaryStreamWriter object

Definition at line 122 of file BinaryStreamWriter.cpp.

References m_ofstrm, m_strLengthSize, and value.

◆ operator<<() [7/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const uint16_t &  value)

write a uint16_t to the stream

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

Definition at line 136 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ operator<<() [8/8]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::operator<< ( const uint32_t &  value)

write a uint32_t to the stream

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

Definition at line 146 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [1/9]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::write ( const Kernel::Matrix< double > &  value,
const std::vector< int32_t > &  shape,
MatrixOrdering  order 
)

◆ write() [2/9]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::write ( const Kernel::Matrix< float > &  value,
const std::vector< int32_t > &  shape,
MatrixOrdering  order 
)

◆ write() [3/9]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::write ( const std::string &  value,
const size_t  length 
)

write a series of characters from a string object.

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

Definition at line 212 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [4/9]

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

write an array of double values from the given vector.

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

Definition at line 201 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [5/9]

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

write an array of float balues from the given vector.

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

Definition at line 190 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [6/9]

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

write an array of int16_t from the given vector.

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

Definition at line 157 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [7/9]

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

write an array of int32_t from the given vector.

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

Definition at line 168 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [8/9]

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

write an array of int64_t from the given vector.

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

Definition at line 179 of file BinaryStreamWriter.cpp.

References m_ofstrm, and value.

◆ write() [9/9]

BinaryStreamWriter & Mantid::Kernel::BinaryStreamWriter::write ( const std::vector< std::string > &  value,
const std::vector< int32_t > &  shape,
MatrixOrdering  order 
)

Member Data Documentation

◆ m_ofstrm

std::ostream& Mantid::Kernel::BinaryStreamWriter::m_ofstrm
private

Reference to the stream being written to.

Definition at line 73 of file BinaryStreamWriter.h.

Referenced by operator<<(), and write().

◆ m_strLengthSize

uint64_t Mantid::Kernel::BinaryStreamWriter::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 BinaryStreamWriter.h.

Referenced by operator<<().


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