From e927c51b61c1582d7cad626a5f9234c2638daa90 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 1 Feb 2020 00:11:59 -0600 Subject: [PATCH] [ox/fs] Give FileSystem ability to cleanup FS buffer --- deps/ox/src/ox/fs/filesystem/filesystem.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/deps/ox/src/ox/fs/filesystem/filesystem.hpp b/deps/ox/src/ox/fs/filesystem/filesystem.hpp index a8eed502..a14957d8 100644 --- a/deps/ox/src/ox/fs/filesystem/filesystem.hpp +++ b/deps/ox/src/ox/fs/filesystem/filesystem.hpp @@ -94,10 +94,13 @@ class FileSystemTemplate: public FileSystem { }; FileStore m_fs; + void(*m_freeBuffer)(uint8_t*) = nullptr; public: FileSystemTemplate() = default; + FileSystemTemplate(void *buffer, uint64_t bufferSize, void(*freeBuffer)(uint8_t*) = [] (uint8_t *buff) { delete buff; }); + FileSystemTemplate(FileStore fs); ~FileSystemTemplate(); @@ -167,8 +170,17 @@ FileSystemTemplate::FileSystemTemplate(FileStore fs) { m_fs = fs; } +template +FileSystemTemplate::FileSystemTemplate(void *buffer, uint64_t bufferSize, void(*freeBuffer)(uint8_t*)): + m_fs(buffer, bufferSize), + m_freeBuffer(freeBuffer) { +} + template FileSystemTemplate::~FileSystemTemplate() { + if (m_freeBuffer && m_fs.buff()) { + m_freeBuffer(m_fs.buff()); + } } template