33 #include "../mxlib.hpp"
34 #include "../mxException.hpp"
52 const std::string & fileName
57 fout = fopen(fileName.c_str(),
"rb");
60 mxThrowExceptionErrno(
mx::err::fileoerr, errno,
"readRawBinary",
"Error from fopen [" + fileName +
"]");
63 int nrd = fread( data,
sizeof(T), szData, fout);
72 mxThrowExceptionErrno(
mx::err::filererr, en,
"readRawBinary",
"Error from file [" + fileName +
"]");
76 mxThrowException(
mx::err::filererr,
"readRawBinary",
"Error reading from file, did not read all elements. [" + fileName+
"]");
80 int res = fclose(fout);
84 mxThrowExceptionErrno(
mx::err::filecerr, errno,
"readRawBinary",
"Error closing file [" + fileName+
"]");
107 fout = fopen(fileName.c_str(),
"wb");
110 mxThrowExceptionErrno(
mx::err::fileoerr, errno,
"writeRawBinary",
"Error from fopen [" + fileName +
"]");
114 int nwr = fwrite( data,
sizeof(T), szData, fout);
124 mxThrowExceptionErrno(
mx::err::filewerr, en,
"writeRawBinary",
"Error writing to file [" + fileName +
"]");
128 mxThrowException(
mx::err::filewerr,
"writeRawBinary",
"Error writing to file, did not write all elements. [" + fileName+
"]");
133 int res = fclose(fout);
137 mxThrowExceptionErrno(
mx::err::filecerr, errno,
"writeRawBinary",
"Error closing file [" + fileName+
"]");
mxException for errors closing a file
mxException for errors on opening a file
mxException for errors reading from a file
mxException for errors writing to a file
int writeRawBinary(const std::string &fileName, T *data, size_t szData)
Write an array of data to file as raw binary.
int readRawBinary(T *data, size_t szData, const std::string &fileName)
Read an array of data from a file as raw binary.