Added comparator and hash function for path references.

This commit is contained in:
Patrick 2023-12-23 12:10:07 +01:00
parent 83d3ce9f1f
commit 1d14c1f3ff

View File

@ -11,6 +11,7 @@
#include <string>
#include <vector>
#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<mijin::PathReference>
{
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)