69 this->text +=
" (Internal error: ";
70 this->text += strerror(errno);
94 FileIo(std::string
const& file,
bool write) {
99 fileHandle = fopen(file.c_str(),
"wb");
101 fileHandle = fopen(file.c_str(),
"rb");
104 if (
nullptr == fileHandle) {
105 throw IoException(IoError::Open,
"Could not open file: " + file,
true);
111 if (
nullptr != fileHandle) {
118 template<
typename Data>
121 size_t s = fwrite(data,
sizeof(Data), length, fileHandle);
124 throw IoException(IoError::Read,
"Wrong number of bytes written.",
true);
127 throw IoException(IoError::Mode,
"Using write io handle in wrong mode.",
false);
133 template<
typename Data>
136 size_t s = fread(data,
sizeof(Data), length, fileHandle);
139 throw IoException(IoError::Read,
"Wrong number of bytes read.",
false);
142 throw IoException(IoError::Mode,
"Using read io handle in wrong mode.",
false);
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
IoError
Possible IO errors.
Definition fileIo.hpp:52
Helper structure for writing binary data.
Definition fileIo.hpp:84
void writeData(Data const *data, size_t const length)
Definition fileIo.hpp:119
FileIo(std::string const &file, bool write)
Definition fileIo.hpp:94
void readData(Data *data, size_t const length)
Definition fileIo.hpp:134
~FileIo()
Destructor.
Definition fileIo.hpp:110
IoException for CoDiPack.
Definition fileIo.hpp:60
IoException(IoError id, std::string const &text, bool appendErrno)
Constructor.
Definition fileIo.hpp:67
std::string text
Textual description.
Definition fileIo.hpp:63
IoError id
Exception ID.
Definition fileIo.hpp:64