Added PathReference utility type.
This commit is contained in:
parent
60707421c8
commit
0e90cabb7e
@ -40,6 +40,21 @@ struct FileInfo
|
||||
bool isHidden : 1 = false;
|
||||
};
|
||||
|
||||
// basically just a thin wrapper around adapter + path, for utility
|
||||
class PathReference
|
||||
{
|
||||
private:
|
||||
class FileSystemAdapter* adapter_;
|
||||
fs::path path_;
|
||||
public:
|
||||
PathReference(class FileSystemAdapter* adapter, fs::path path) noexcept : adapter_(adapter), path_(std::move(path)) {}
|
||||
|
||||
[[nodiscard]] class FileSystemAdapter* getAdapter() const noexcept { return adapter_; }
|
||||
[[nodiscard]] const fs::path& getPath() const noexcept { return path_; }
|
||||
[[nodiscard]] inline FileInfo getInfo() const;
|
||||
[[nodiscard]] inline StreamError open(FileOpenMode mode, std::unique_ptr<Stream>& outStream) const;
|
||||
};
|
||||
|
||||
class FileSystemAdapter
|
||||
{
|
||||
public:
|
||||
@ -50,6 +65,8 @@ public:
|
||||
[[nodiscard]] virtual std::vector<FileInfo> listFiles(const fs::path& folder) = 0;
|
||||
[[nodiscard]] virtual FileInfo getFileInfo(const fs::path& file) = 0;
|
||||
[[nodiscard]] virtual StreamError open(const fs::path& path, FileOpenMode mode, std::unique_ptr<Stream>& outStream) = 0;
|
||||
|
||||
[[nodiscard]] PathReference getPath(fs::path path) noexcept { return PathReference(this, std::move(path)); }
|
||||
};
|
||||
|
||||
class OSFileSystemAdapter : public FileSystemAdapter
|
||||
@ -68,6 +85,16 @@ public:
|
||||
// public functions
|
||||
//
|
||||
|
||||
inline FileInfo PathReference::getInfo() const
|
||||
{
|
||||
return adapter_->getFileInfo(path_);
|
||||
}
|
||||
|
||||
inline StreamError PathReference::open(FileOpenMode mode, std::unique_ptr<Stream>& outStream) const
|
||||
{
|
||||
return adapter_->open(path_, mode, outStream);
|
||||
}
|
||||
|
||||
inline std::string formatFileType(const FileInfo& info)
|
||||
{
|
||||
if (info.isFolder) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user