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 {
13 struct Path {
14 Path() = default;
15 Path(const std::filesystem::path& path);
16 Path(std::filesystem::path&& path) noexcept;
17
18 [[nodiscard]] const std::filesystem::path& fsPath() const { return filePath; }
19 [[nodiscard]] const std::filesystem::path& getFilePath() const { return filePath; }
20 [[nodiscard]] std::string string() const { return filePath.string(); }
21 [[nodiscard]] bool empty() const { return filePath.empty(); }
22 [[nodiscard]] std::size_t hash() const noexcept;
23
24 operator const std::filesystem::path&() const { return filePath; }
25
26 bool operator==(const Path& other) const { return filePath == other.filePath; }
27
28 void reset();
29
30 private:
31 std::filesystem::path filePath = "";
32 };
33
40 struct MeshPath {
44 MeshPath() = default;
45
51 MeshPath(const std::filesystem::path& path, const std::string& assetName);
52
57 MeshPath(MeshPath&& other ) noexcept;
58
63 MeshPath( const MeshPath & other) noexcept;
64
68 MeshPath& operator=(const MeshPath&) = default;
69
73 MeshPath& operator=(MeshPath&&) noexcept = default;
74
79 [[nodiscard]] const std::filesystem::path& getFilePath() const { return filePath_; }
80
85 [[nodiscard]] const std::string& getAssetName() const { return assetName_; }
86
91 [[nodiscard]] std::string getAssetHandle() const { return filePath_.string() + assetName_; }
92
97 [[nodiscard]] std::size_t hash() const noexcept;
98
103 [[nodiscard]] bool empty() const { return filePath_.empty() || assetName_.empty(); }
104
110 bool operator==(const MeshPath& other) const {
111 return filePath_ == other.filePath_ && assetName_ == other.assetName_;
112 }
113
117 void reset();
118
119 private:
120 std::filesystem::path filePath_ = "";
121 std::string assetName_ = std::string("");
122 };
123}
124
125namespace std {
126 template<>
127 struct hash<Asset::Path> {
128 size_t operator()(const Asset::Path& path) const noexcept {
129 return path.hash();
130 }
131 };
132
133 template<>
134 struct hash<Asset::MeshPath> {
135 size_t operator()(const Asset::MeshPath& path) const noexcept {
136 return path.hash();
137 }
138 };
139}
Classes which are related to asset loading are mostly stored in this namespace.
STL namespace.
Identifies a named mesh-like asset inside an asset file.
Definition AssetPath.h:40
std::size_t hash() const noexcept
Calculates a hash for use in unordered containers.
bool operator==(const MeshPath &other) const
Compares two asset paths by file path and asset name.
Definition AssetPath.h:110
MeshPath()=default
Creates an empty asset path.
MeshPath & operator=(MeshPath &&) noexcept=default
Move-assigns an asset path.
MeshPath(const std::filesystem::path &path, const std::string &assetName)
Creates an asset path for a named asset in a file.
std::filesystem::path filePath_
Definition AssetPath.h:120
MeshPath & operator=(const MeshPath &)=default
Copy-assigns an asset path.
const std::filesystem::path & getFilePath() const
Gets the source file path.
Definition AssetPath.h:79
MeshPath(MeshPath &&other) noexcept
Move-constructs an asset path.
std::string getAssetHandle() const
Gets a combined string key for file path and asset name.
Definition AssetPath.h:91
MeshPath(const MeshPath &other) noexcept
Copy-constructs an asset path.
void reset()
Clears the file path and asset name.
const std::string & getAssetName() const
Gets the asset name inside the source file.
Definition AssetPath.h:85
bool empty() const
Checks whether this path doesn't point to anything. So it is empty.
Definition AssetPath.h:103
std::string assetName_
Definition AssetPath.h:121
Identifies a single asset file on disk.
Definition AssetPath.h:13
bool empty() const
Definition AssetPath.h:21
bool operator==(const Path &other) const
Definition AssetPath.h:26
std::string string() const
Definition AssetPath.h:20
std::filesystem::path filePath
Definition AssetPath.h:31
std::size_t hash() const noexcept
const std::filesystem::path & getFilePath() const
Definition AssetPath.h:19
const std::filesystem::path & fsPath() const
Definition AssetPath.h:18
void reset()
Path()=default
Path(const std::filesystem::path &path)
Path(std::filesystem::path &&path) noexcept
size_t operator()(const Asset::MeshPath &path) const noexcept
Definition AssetPath.h:135
size_t operator()(const Asset::Path &path) const noexcept
Definition AssetPath.h:128