Commit 38787b2a authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

use std::filesystem::file_size to determine file size

parent 32fd5c62
......@@ -14,6 +14,7 @@
#include <cmath>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <map>
#include <set>
......@@ -152,28 +153,23 @@ Eigen::MatrixXi RawDataReader::data(size_t frame)
checkInit();
std::string filename = _filenames.at(frame);
const size_t fsize = std::filesystem::file_size(filename);
if (fsize != _length) {
std::string err_msg = "data file " + filename + " is not of the expected size: "
+ "expected " + std::to_string(_length) + " bytes but found "
+ std::to_string(fsize);
throw std::runtime_error(err_msg);
}
std::ifstream file;
file.open(filename, std::ios_base::binary | std::ios_base::in);
if (!file.is_open())
throw std::runtime_error("could not open data file " + filename);
file.seekg(0, std::ios_base::end);
if (_length != size_t(file.tellg())) {
std::string err_msg = "data file " + filename + " is not of the expected size: ";
err_msg += "expected " + std::to_string(_length) + " bytes but found "
+ std::to_string(file.tellg());
throw std::runtime_error(err_msg);
}
file.seekg(0, std::ios_base::beg);
file.read(&_data[0], long(_length));
if (_length != size_t(file.gcount())) {
std::string err_msg = "cannot load file " + filename + ": ";
err_msg += "expected " + std::to_string(_length) + " bytes but found "
if (size_t(file.gcount()) != _length) {
std::string err_msg = "cannot load file " + filename + ": "
+ "expected " + std::to_string(_length) + " bytes but found "
+ std::to_string(file.gcount());
throw std::runtime_error(err_msg);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment