silence warnings

This commit is contained in:
Erik Frojdh 2024-03-08 16:13:17 +01:00
parent e8f81e618d
commit b8cd465a12
5 changed files with 24 additions and 21 deletions

View File

@ -17,6 +17,7 @@ class File {
private: private:
public: public:
virtual ~File() = default;
std::filesystem::path fname; std::filesystem::path fname;
std::filesystem::path base_path; std::filesystem::path base_path;
std::string base_name, ext; std::string base_name, ext;

View File

@ -6,13 +6,14 @@ class FileFactory{
// Class that will be used to create File objects // Class that will be used to create File objects
// follows the factory pattern // follows the factory pattern
protected: protected:
std::filesystem::path fpath; std::filesystem::path m_fpath;
public: public:
static FileFactory<detector,DataType>* get_factory(std::filesystem::path); static FileFactory<detector,DataType>* get_factory(std::filesystem::path);
// virtual int deleteFile() = 0; // virtual int deleteFile() = 0;
virtual File<detector,DataType>* load_file()=0;//TODO: add option to load all file to memory or keep it on disk virtual File<detector,DataType>* load_file()=0;//TODO: add option to load all file to memory or keep it on disk
virtual void parse_metadata(File<detector,DataType>*)=0; virtual void parse_metadata(File<detector,DataType>*)=0;
virtual void parse_fname(File<detector,DataType>*)=0; virtual void parse_fname(File<detector,DataType>*)=0;
virtual ~FileFactory() = default;

View File

@ -7,7 +7,12 @@
class SubFile { class SubFile {
protected: protected:
FILE *fp = nullptr; FILE *fp = nullptr;
uint16_t bitdepth; uint16_t m_bitdepth;
std::filesystem::path m_fname;
ssize_t m_rows{};
ssize_t m_cols{};
ssize_t n_frames{};
int m_sub_file_index_{};
public: public:
// pointer to a read_impl function. pointer will be set to the appropriate read_impl function in the constructor // pointer to a read_impl function. pointer will be set to the appropriate read_impl function in the constructor
@ -22,11 +27,7 @@ class SubFile {
size_t get_frame(std::byte *buffer, int frame_number); size_t get_frame(std::byte *buffer, int frame_number);
// TODO: define the inlines as variables and assign them in constructor // TODO: define the inlines as variables and assign them in constructor
inline size_t bytes_per_frame() { return (bitdepth / 8) * rows * cols; } inline size_t bytes_per_frame() { return (m_bitdepth / 8) * m_rows * m_cols; }
inline size_t pixels_per_frame() { return rows * cols; } inline size_t pixels_per_frame() { return m_rows * m_cols; }
std::filesystem::path fname;
ssize_t rows{};
ssize_t cols{};
ssize_t n_frames{};
int sub_file_index_{};
}; };

View File

@ -13,7 +13,7 @@ template <DetectorType detector,typename DataType>
JsonFileFactory<detector,DataType>::JsonFileFactory(std::filesystem::path fpath) { JsonFileFactory<detector,DataType>::JsonFileFactory(std::filesystem::path fpath) {
if (not is_master_file(fpath)) if (not is_master_file(fpath))
throw std::runtime_error("Json file is not a master file"); throw std::runtime_error("Json file is not a master file");
this->fpath = fpath; this->m_fpath = fpath;
} }
template <DetectorType detector,typename DataType> template <DetectorType detector,typename DataType>
@ -63,7 +63,7 @@ void JsonFileFactory<detector,DataType>::open_subfiles(File<detector,DataType> *
template <DetectorType detector,typename DataType> template <DetectorType detector,typename DataType>
File<detector,DataType> *JsonFileFactory<detector,DataType>::load_file() { File<detector,DataType> *JsonFileFactory<detector,DataType>::load_file() {
JsonFile<detector,DataType> *file = new JsonFile<detector,DataType>(); JsonFile<detector,DataType> *file = new JsonFile<detector,DataType>();
file->fname = this->fpath; file->fname = this->m_fpath;
this->parse_fname(file); this->parse_fname(file);
this->parse_metadata(file); this->parse_metadata(file);
file->find_number_of_subfiles(); file->find_number_of_subfiles();
@ -113,9 +113,9 @@ void JsonFileFactory<detector, DataType>::find_geometry(File<detector, DataType>
template <DetectorType detector, typename DataType> template <DetectorType detector, typename DataType>
void JsonFileFactory<detector, DataType>::parse_fname(File<detector, DataType> *file) { void JsonFileFactory<detector, DataType>::parse_fname(File<detector, DataType> *file) {
file->base_path = this->fpath.parent_path(); file->base_path = this->m_fpath.parent_path();
file->base_name = this->fpath.stem(); file->base_name = this->m_fpath.stem();
file->ext = this->fpath.extension(); file->ext = this->m_fpath.extension();
auto pos = file->base_name.rfind("_"); auto pos = file->base_name.rfind("_");
file->findex = std::stoi(file->base_name.substr(pos + 1)); file->findex = std::stoi(file->base_name.substr(pos + 1));

View File

@ -9,10 +9,10 @@
*/ */
SubFile::SubFile(std::filesystem::path fname, DetectorType detector, ssize_t rows, ssize_t cols, uint16_t bitdepth) { SubFile::SubFile(std::filesystem::path fname, DetectorType detector, ssize_t rows, ssize_t cols, uint16_t bitdepth) {
this->rows = rows; this->m_rows = rows;
this->cols = cols; this->m_cols = cols;
this->fname = fname; this->m_fname = fname;
this->bitdepth = bitdepth; this->m_bitdepth = bitdepth;
fp = fopen(fname.c_str(), "rb"); fp = fopen(fname.c_str(), "rb");
if (fp == nullptr) { if (fp == nullptr) {
throw std::runtime_error("Could not open file " + fname.string()); throw std::runtime_error("Could not open file " + fname.string());
@ -77,12 +77,12 @@ template <typename DataType> size_t SubFile::read_impl_flip(std::byte *buffer) {
size_t rc = fread(reinterpret_cast<char *>(&tmp[0]), this->bytes_per_frame(), 1, this->fp); size_t rc = fread(reinterpret_cast<char *>(&tmp[0]), this->bytes_per_frame(), 1, this->fp);
// copy to place // copy to place
const size_t start = this->cols * (this->rows - 1) * sizeof(DataType); const size_t start = this->m_cols * (this->m_rows - 1) * sizeof(DataType);
const size_t row_size = this->cols * sizeof(DataType); const size_t row_size = this->m_cols * sizeof(DataType);
auto dst = buffer + start; auto dst = buffer + start;
auto src = &tmp[0]; auto src = &tmp[0];
for (int i = 0; i != this->rows; ++i) { for (int i = 0; i != this->m_rows; ++i) {
memcpy(dst, src, row_size); memcpy(dst, src, row_size);
dst -= row_size; dst -= row_size;
src += row_size; src += row_size;