11#ifndef MANTID_DATAHANDLING_BIT_STREAM_H_
12#define MANTID_DATAHANDLING_BIT_STREAM_H_
14#include <boost/endian/conversion.hpp>
23 stream_.exceptions(std::ifstream::eofbit);
32 int rc = stat(filename.c_str(), &stat_buf);
33 return rc == 0 ? stat_buf.st_size : -1;
36 template <
typename T>
inline char *
getResultPointer(T *
const result,
const std::size_t &bytecount)
const {
37 return reinterpret_cast<char *
>(result) +
sizeof(T) - std::min(
sizeof(T), bytecount);
47 static_assert(
sizeof(T) >= bytecount,
"byte count of result needs to be greater or equal to bytecount");
54 template <
typename T>
inline T
readRaw(T &&result) {
55 readRaw<sizeof(result)>(result);
59 inline uint8_t
peek() {
return static_cast<uint8_t
>(
stream_.peek()); }
79 typename std::vector<uint8_t>::const_iterator
pos;
80 typename std::vector<uint8_t>::const_iterator
end;
82 template <
typename T>
inline char *
getResultPointer(T *
const result,
const std::size_t &bytecount)
const {
83 return reinterpret_cast<char *
>(result) +
sizeof(T) - bytecount;
86 inline void streamread(
char *dest,
const std::size_t &bytecount) {
87 std::copy(
pos,
pos +
static_cast<long>(bytecount), dest);
88 pos +=
static_cast<long>(bytecount);
91 inline void streamignore(
const std::size_t &bytecount) {
pos +=
static_cast<long>(bytecount); }
105 static_assert(
sizeof(T) >= bytecount,
"byte count of result needs to be greater or equal to bytecount");
112 template <
typename T>
inline T
readRaw(T &&result) {
113 readRaw<sizeof(result)>(result);
118 readRaw<bytecount>(result);
119 result = boost::endian::conditional_reverse<boost::endian::order::big, boost::endian::order::native>(result);
FileByteStream & operator>>(T &val)
FileByteStream & readRaw(T &result, const std::size_t &bytecount)
uint64_t fileSize() const
FileByteStream(const std::string &filename)
FileByteStream & readRaw(T &result)
FileByteStream & readRaw(T &result)
char * getResultPointer(T *const result, const std::size_t &bytecount) const
std::streamsize gcount() const
long getFileSize(std::string filename)
std::vector< uint8_t >::const_iterator pos
VectorByteStream & readRaw(T &result)
VectorByteStream & read(T &result)
VectorByteStream(const std::vector< uint8_t > &vector)
unsigned streampeek() const
VectorByteStream & skip()
char * getResultPointer(T *const result, const std::size_t &bytecount) const
VectorByteStream & readRaw(T &result, const std::size_t &bytecount)
std::vector< uint8_t >::const_iterator end
void streamignore(const std::size_t &bytecount)
VectorByteStream & readRaw(T &result)
VectorByteStream & operator>>(T &val)
void streamread(char *dest, const std::size_t &bytecount)