From 1d14c1f3ff3e6845fd39bec587548407aa6b5683 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 23 Dec 2023 12:10:07 +0100 Subject: [PATCH] Added comparator and hash function for path references. --- source/mijin/virtual_filesystem/filesystem.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/mijin/virtual_filesystem/filesystem.hpp b/source/mijin/virtual_filesystem/filesystem.hpp index b7ae653..54d70a3 100644 --- a/source/mijin/virtual_filesystem/filesystem.hpp +++ b/source/mijin/virtual_filesystem/filesystem.hpp @@ -11,6 +11,7 @@ #include #include #include "../io/stream.hpp" +#include "../util/hash.hpp" namespace fs = std::filesystem; @@ -49,6 +50,8 @@ private: public: PathReference(class FileSystemAdapter* adapter, fs::path path) noexcept : adapter_(adapter), path_(std::move(path)) {} + auto operator<=>(const PathReference& other) const noexcept = default; + [[nodiscard]] class FileSystemAdapter* getAdapter() const noexcept { return adapter_; } [[nodiscard]] const fs::path& getPath() const noexcept { return path_; } [[nodiscard]] inline FileInfo getInfo() const; @@ -129,4 +132,16 @@ inline std::string formatFileSize(std::size_t sizeInBytes) } // namespace mijin +template<> +struct std::hash +{ + std::size_t operator()(const mijin::PathReference& pathRef) const noexcept + { + std::size_t hash = 0; + mijin::hashCombine(hash, pathRef.getAdapter()); + mijin::hashCombine(hash, pathRef.getPath()); + return hash; + } +}; + #endif // !defined(MIJIN_VIRTUAL_FILESYSTEM_FILESYSTEM_HPP_INCLUDED)