moved reading of metadata into NumpyFile

This commit is contained in:
Erik Frojdh
2024-04-02 15:01:56 +02:00
parent 390ceb02d8
commit a6c0879de7
5 changed files with 82 additions and 126 deletions

View File

@ -1,56 +0,0 @@
#pragma once
#include "aare/Frame.hpp"
#include <filesystem>
namespace aare {
class FileInterface {
public:
// options:
// - r reading
// - w writing (overwrites existing file)
// - a appending (appends to existing file)
// TODO! do we need to support w+, r+ and a+?
FileInterface(const std::filesystem::path& fname, const char* opts="r" ){};
// write one frame
virtual void write(Frame& frame) = 0;
// write n_frames frames
virtual void write(std::vector<Frame>& frames) = 0;
// read one frame
virtual Frame read() = 0;
// read n_frames frames
virtual std::vector<Frame> read(size_t n_frames) = 0; //Is this the right interface?
// read one frame into the provided buffer
virtual void read_into(std::byte* image_buf) = 0;
// read n_frames frame into the provided buffer
virtual void read_into(std::byte* image_buf, size_t n_frames) = 0;
// read the frame number on position frame_index
virtual size_t frame_number(size_t frame_index) = 0;
// size of one frame, important fro teh read_into function
virtual size_t bytes_per_frame() const = 0;
// goto frame number
virtual void seek(size_t frame_number) = 0;
// return the position of the file pointer (in number of frames)
virtual size_t tell() = 0;
// total number of frames in the file
virtual size_t total_frames() = 0;
virtual size_t rows() const = 0;
virtual size_t cols() const = 0;
// function to query the data type of the file
/*virtual DataType dtype = 0; */
virtual ~FileInterface() = 0;
};
} // namespace aare

View File

@ -15,9 +15,11 @@ class NumpyFile : public FileInterface {
void get_frame_into(size_t, std::byte *);
Frame get_frame(size_t frame_number);
void load_metadata();
std::filesystem::path m_fname;
public:
std::filesystem::path m_fname; //TO be made private!
NumpyFile(const std::filesystem::path& fname);
NumpyFile(FileConfig, header_t);

View File

@ -13,7 +13,7 @@ class NumpyFileFactory : public FileFactory {
public:
NumpyFileFactory(std::filesystem::path fpath);
void parse_metadata(FileInterface *_file) override;
void parse_metadata(FileInterface *_file) override{/*TODO! remove after refactor*/};
NumpyFile* load_file_read() override;
NumpyFile* load_file_write(FileConfig) override;
void parse_fname(FileInterface*)override{};