diff --git a/file_io/include/aare/FileInterface.h b/file_io/include/aare/FileInterface.h index bb93393..fe02699 100644 --- a/file_io/include/aare/FileInterface.h +++ b/file_io/include/aare/FileInterface.h @@ -9,7 +9,7 @@ public: // - w writing (overwrites existing file) // - a appending (appends to existing file) // TODO! do we need to support w+, r+ and a+? - FileInterface(std::filesystem::path& fname, const char* opts="r" ){}; + FileInterface(const std::filesystem::path& fname, const char* opts="r" ){}; // write one frame virtual void write(Frame& frame) = 0; diff --git a/file_io/include/aare/FileInterface.hpp b/file_io/include/aare/FileInterface.hpp index 7e2dfb6..c8774af 100644 --- a/file_io/include/aare/FileInterface.hpp +++ b/file_io/include/aare/FileInterface.hpp @@ -83,7 +83,7 @@ class FileInterface { public: std::string mode; - std::filesystem::path m_fname; + // std::filesystem::path m_fname; std::filesystem::path m_base_path; std::string m_base_name, m_ext; int m_findex; diff --git a/file_io/include/aare/NumpyFile.hpp b/file_io/include/aare/NumpyFile.hpp index 7f8192f..90da019 100644 --- a/file_io/include/aare/NumpyFile.hpp +++ b/file_io/include/aare/NumpyFile.hpp @@ -4,15 +4,21 @@ #include "aare/defs.hpp" #include #include +#include namespace aare{ class NumpyFile : public FileInterface { FILE *fp = nullptr; size_t initial_header_len = 0; + public: + std::filesystem::path m_fname; //TO be made private! + + NumpyFile(const std::filesystem::path& fname); + NumpyFile(FileConfig, header_t); void write(Frame &frame) override; Frame read() override { return get_frame(this->current_frame++); } @@ -29,8 +35,6 @@ class NumpyFile : public FileInterface { ssize_t cols() const override { return header.shape[2]; } ssize_t bitdepth() const override { return header.dtype.bitdepth(); } - NumpyFile(std::filesystem::path fname); - NumpyFile(FileConfig, header_t); header_t header; uint8_t major_ver_{}; uint8_t minor_ver_{}; diff --git a/file_io/include/aare/RawFile.hpp b/file_io/include/aare/RawFile.hpp index 59300db..5630e40 100644 --- a/file_io/include/aare/RawFile.hpp +++ b/file_io/include/aare/RawFile.hpp @@ -9,8 +9,10 @@ namespace aare { class RawFile : public FileInterface { using config = RawFileConfig; + public: + std::filesystem::path m_fname; //TO be made private! void write(Frame &frame) override{}; Frame read() override { return get_frame(this->current_frame++); }; std::vector read(size_t n_frames) override; diff --git a/file_io/src/NumpyFile.cpp b/file_io/src/NumpyFile.cpp index 0d7df8d..9b4f63d 100644 --- a/file_io/src/NumpyFile.cpp +++ b/file_io/src/NumpyFile.cpp @@ -3,19 +3,8 @@ namespace aare{ -void NumpyFile::write(Frame &frame) { - if (fp == nullptr) { - throw std::runtime_error("File not open"); - } - if (not(mode == "w" or mode == "a")) { - throw std::runtime_error("File not open for writing"); - } - fseek(fp, 0, SEEK_END); - fwrite(frame._get_data(), frame.size(), 1, fp); -} - -NumpyFile::NumpyFile(std::filesystem::path fname_) { - this->m_fname = fname_; +NumpyFile::NumpyFile(const std::filesystem::path& fname) { + this->m_fname = fname; fp = fopen(this->m_fname.c_str(), "rb"); } NumpyFile::NumpyFile(FileConfig config, header_t header) { @@ -36,6 +25,19 @@ NumpyFile::NumpyFile(FileConfig config, header_t header) { aare::NumpyHelpers::write_header(std::filesystem::path(this->m_fname.c_str()), this->header); } +void NumpyFile::write(Frame &frame) { + if (fp == nullptr) { + throw std::runtime_error("File not open"); + } + if (not(mode == "w" or mode == "a")) { + throw std::runtime_error("File not open for writing"); + } + fseek(fp, 0, SEEK_END); + fwrite(frame._get_data(), frame.size(), 1, fp); +} + + + Frame NumpyFile::get_frame(size_t frame_number) { Frame frame(header.shape[1], header.shape[2], header.dtype.bitdepth()); get_frame_into(frame_number, frame._get_data());