[ox/fs] Give FileSystem ability to cleanup FS buffer

This commit is contained in:
Gary Talent 2020-02-01 00:11:59 -06:00
parent dd008c3a08
commit e927c51b61

View File

@ -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<FileStore, Directory>::FileSystemTemplate(FileStore fs) {
m_fs = fs;
}
template<typename FileStore, typename Directory>
FileSystemTemplate<FileStore, Directory>::FileSystemTemplate(void *buffer, uint64_t bufferSize, void(*freeBuffer)(uint8_t*)):
m_fs(buffer, bufferSize),
m_freeBuffer(freeBuffer) {
}
template<typename FileStore, typename Directory>
FileSystemTemplate<FileStore, Directory>::~FileSystemTemplate() {
if (m_freeBuffer && m_fs.buff()) {
m_freeBuffer(m_fs.buff());
}
}
template<typename FileStore, typename Directory>