Added MappingFileSystemAdapter and adjusted some more stuff in the VFS module.

This commit is contained in:
2025-03-02 18:41:04 +01:00
parent 8f2cee4968
commit 6407c5ca09
6 changed files with 248 additions and 36 deletions

View File

@@ -38,7 +38,6 @@ public:
RelativeFileSystemAdapter& operator=(const RelativeFileSystemAdapter&) = default;
RelativeFileSystemAdapter& operator=(RelativeFileSystemAdapter&&) MIJIN_NOEXCEPT = default;
std::vector<fs::path> getRoots() override;
fs::path getHomeFolder() override;
std::vector<FileInfo> listFiles(const fs::path& folder) override;
FileInfo getFileInfo(const fs::path& file) override;
@@ -52,12 +51,6 @@ private:
// public functions
//
template<typename TWrapped>
std::vector<fs::path> RelativeFileSystemAdapter<TWrapped>::getRoots()
{
return { root_ };
}
template<typename TWrapped>
fs::path RelativeFileSystemAdapter<TWrapped>::getHomeFolder()
{
@@ -106,6 +99,39 @@ fs::path RelativeFileSystemAdapter<TWrapped>::appendPath(const fs::path& other)
}
return combinedPath;
}
namespace vfs_pipe
{
template<typename TBase>
struct RelativeBuilder : Builder<RelativeBuilder<TBase>, RelativeFileSystemAdapter<typename TBase::adapter_t>>
{
fs::path root;
TBase base;
std::unique_ptr<RelativeFileSystemAdapter<typename TBase::adapter_t>> build()
{
return std::make_unique<RelativeFileSystemAdapter<typename TBase::adapter_t>>(root, std::move(*base.build()));
}
};
struct RelativeOptions
{
fs::path root;
};
[[nodiscard]]
inline RelativeOptions relative_to(fs::path root) noexcept
{
return {.root = std::move(root) };
}
template<typename TBase>
[[nodiscard]]
RelativeBuilder<TBase> operator|(TBase other, RelativeOptions options) noexcept
{
return {.root = std::move(options.root), .base = std::move(other) };
}
}
} // namespace mijin
#endif // !defined(MIJIN_VIRTUAL_FILESYSTEM_RELATIVE_HPP_INCLUDED)