#include "FileFactory.hpp" #include "File.hpp" #include "RawFileFactory.hpp" #include "JsonFileFactory.hpp" #include FileFactory FileFactory::getFactory(std::filesystem::path fpath){ // check if file exists if(!std::filesystem::exists(fpath)){ throw std::runtime_error("File does not exist"); } if(fpath.extension() == ".raw"){ std::cout<<"Loading raw file"< Header FileFactory::read_header(const std::filesystem::path &fname) { Header h{}; FILE *fp = fopen(fname.c_str(), "r"); if (!fp) throw std::runtime_error( fmt::format("Could not open: {} for reading", fname.c_str())); size_t rc = fread(reinterpret_cast(&h), sizeof(h), 1, fp); fclose(fp); if (rc != 1) throw std::runtime_error("Could not read header from file"); return h; } void FileFactory::find_geometry(File& file) { uint16_t r{}; uint16_t c{}; for (int i = 0; i != file.n_subfiles; ++i) { auto h = this->read_header(file.data_fname(i, 0)); r = std::max(r, h.row); c = std::max(c, h.column); file.positions.push_back({h.row, h.column}); } r++; c++; file.rows = r * file.subfile_rows; file.cols = c * file.subfile_cols; file.rows += (r - 1) * file.cfg.module_gap_row; }