intial commit
This commit is contained in:
87
source/mijin/virtual_filesystem/relative.hpp
Normal file
87
source/mijin/virtual_filesystem/relative.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(MIJIN_VIRTUAL_FILESYSTEM_RELATIVE_HPP_INCLUDED)
|
||||
#define MIJIN_VIRTUAL_FILESYSTEM_RELATIVE_HPP_INCLUDED 1
|
||||
|
||||
#include "./filesystem.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
|
||||
//
|
||||
// public defines
|
||||
//
|
||||
|
||||
//
|
||||
// public constants
|
||||
//
|
||||
|
||||
//
|
||||
// public types
|
||||
//
|
||||
|
||||
template<typename TWrapped>
|
||||
class RelativeFileSystemAdapter : public FileSystemAdapter
|
||||
{
|
||||
private:
|
||||
TWrapped wrapped_;
|
||||
fs::path root_;
|
||||
public:
|
||||
template<typename... TArgs>
|
||||
explicit RelativeFileSystemAdapter(fs::path root, TArgs&&... args)
|
||||
: wrapped_(std::forward<TArgs>(args)...), root_(std::move(root)) {}
|
||||
RelativeFileSystemAdapter(const RelativeFileSystemAdapter&) = default;
|
||||
RelativeFileSystemAdapter(RelativeFileSystemAdapter&&) noexcept = default;
|
||||
|
||||
RelativeFileSystemAdapter& operator=(const RelativeFileSystemAdapter&) = default;
|
||||
RelativeFileSystemAdapter& operator=(RelativeFileSystemAdapter&&) 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;
|
||||
StreamError open(const fs::path& path, FileOpenMode mode, std::unique_ptr<Stream>& outStream) override;
|
||||
};
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
template<typename TWrapped>
|
||||
std::vector<fs::path> RelativeFileSystemAdapter<TWrapped>::getRoots()
|
||||
{
|
||||
return { root_ };
|
||||
}
|
||||
|
||||
template<typename TWrapped>
|
||||
fs::path RelativeFileSystemAdapter<TWrapped>::getHomeFolder()
|
||||
{
|
||||
return root_;
|
||||
}
|
||||
|
||||
template<typename TWrapped>
|
||||
std::vector<FileInfo> RelativeFileSystemAdapter<TWrapped>::listFiles(const fs::path& folder)
|
||||
{
|
||||
std::vector<FileInfo> result = wrapped_.listFiles(root_ / folder);
|
||||
for (FileInfo& fileInfo : result) {
|
||||
fileInfo.path = "/" / fileInfo.path.lexically_relative(root_);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename TWrapped>
|
||||
FileInfo RelativeFileSystemAdapter<TWrapped>::getFileInfo(const fs::path& file)
|
||||
{
|
||||
return wrapped_.getFileInfo(root_ / file);
|
||||
}
|
||||
|
||||
template<typename TWrapped>
|
||||
StreamError RelativeFileSystemAdapter<TWrapped>::open(const fs::path& path, FileOpenMode mode, std::unique_ptr<Stream>& outStream)
|
||||
{
|
||||
return wrapped_.open(root_ / path, mode, outStream);
|
||||
}
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
#endif // !defined(MIJIN_VIRTUAL_FILESYSTEM_RELATIVE_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user