19#ifndef FILEMANAGER_IMPL
20#error "This file should not be included directly! Use FileManager.h instead"
25#include <boost/filesystem/operations.hpp>
30struct FileManager::FileMetadata {
31 boost::filesystem::path m_path;
33 Timestamp m_last_used;
34 uint64_t m_used_count;
35 std::function<bool(
void)> m_request_close;
37 FileMetadata(
const boost::filesystem::path& path,
bool write)
38 : m_path(
path), m_write(write), m_last_used(Clock::now()), m_used_count(0) {}
41template <
typename TFD>
42auto FileManager::open(
const boost::filesystem::path& path,
bool write, std::function<
bool(FileId)> request_close)
43 -> std::pair<FileId, TFD> {
44 notifyIntentToOpen(write);
47 FileId
id =
reinterpret_cast<FileId
>(meta.get());
48 meta->m_request_close = [id, request_close]() ->
bool {
return request_close(
id); };
53 std::lock_guard<std::mutex>
lock(m_mutex);
61template <
typename TFD>
std::pair< FileId, TFD > open(const boost::filesystem::path &path, bool write, std::function< bool(FileId)> request_close)
std::map< FileId, std::unique_ptr< FileMetadata > > m_files
void close(FileId id, TFD &fd)
virtual void notifyClosedFile(FileId)=0
std::unique_ptr< T > make_unique(Args &&... args)
Constructs an object of type T and wraps it in a std::unique_ptr using args as the parameter list for...
static TFD open(const boost::filesystem::path &path, bool write)