Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
AssetPath.h
Go to the documentation of this file.
1#pragma once
2#include <filesystem>
3#include <functional>
4
5namespace Asset {
6 struct Path {
7 Path() = default;
8 Path(const std::filesystem::path& path, const std::string& assetName);
9
10 // constructors
11 Path(Path&& other ) noexcept;
12 Path( const Path & other) noexcept;
13
14 // assignment
15 Path& operator=(const Path&) = default;
16 Path& operator=(Path&&) noexcept = default;
17
18 [[nodiscard]] const std::filesystem::path& getFilePath() const { return filePath; }
19 [[nodiscard]] const std::string& getAssetName() const { return assetName; }
20 [[nodiscard]] std::string getAssetHandle() const { return filePath.string() + assetName; }
21 [[nodiscard]] std::size_t hash() const noexcept;
22
27 [[nodiscard]] bool empty() const { return filePath.empty() || assetName.empty(); }
28
29 bool operator==(const Path& other) const {
30 return filePath == other.filePath && assetName == other.assetName;
31 }
32
33 void reset();
34
35 private:
36 std::filesystem::path filePath = "";
37 std::string assetName = std::string("");
38 };
39
40 inline Path::Path(const std::filesystem::path &path, const std::string &assetName) : filePath(path), assetName(assetName) {
41 }
42
43 inline Path::Path( Path && other ) noexcept : filePath(std::move(other.filePath)), assetName(std::move(other.assetName))
44 {
45 }
46
47 inline Path::Path( const Path & other ) noexcept : filePath(other.filePath), assetName(other.assetName)
48 {
49 }
50
51 inline std::size_t Path::hash() const noexcept
52 {
53 const std::size_t pathHash = std::filesystem::hash_value(filePath);
54 const std::size_t nameHash = std::hash<std::string>{}(assetName);
55 return pathHash ^ (nameHash + 0x9e3779b9 + (pathHash << 6) + (pathHash >> 2));
56 }
57
58 inline void Path::reset()
59 {
60 filePath = std::filesystem::path("");
61 assetName = std::string("");
62 }
63
64 static Path GetTexturePath(const std::filesystem::path& path) {
65 return {path, path.filename().generic_string()};
66 }
67}
68
69namespace std {
70 template<>
71 struct hash<Asset::Path> {
72 size_t operator()(const Asset::Path& path) const noexcept {
73 return path.hash();
74 }
75 };
76}
Classes which are related to asset loading are mostly stored in this namespace.
static Path GetTexturePath(const std::filesystem::path &path)
Definition AssetPath.h:64
STL namespace.
bool empty() const
Checks whether this path doesn't point to anything. So it is empty.
Definition AssetPath.h:27
bool operator==(const Path &other) const
Definition AssetPath.h:29
std::filesystem::path filePath
Definition AssetPath.h:36
std::size_t hash() const noexcept
Definition AssetPath.h:51
const std::filesystem::path & getFilePath() const
Definition AssetPath.h:18
Path & operator=(Path &&) noexcept=default
void reset()
Definition AssetPath.h:58
Path()=default
std::string assetName
Definition AssetPath.h:37
Path & operator=(const Path &)=default
std::string getAssetHandle() const
Definition AssetPath.h:20
const std::string & getAssetName() const
Definition AssetPath.h:19
size_t operator()(const Asset::Path &path) const noexcept
Definition AssetPath.h:72