Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
AssetPath.h
1#pragma once
2#include <filesystem>
3#include <functional>
4
5namespace Asset {
13 struct Path {
17 Path() = default;
18
23 Path(const std::filesystem::path& path);
24
29 Path(std::filesystem::path&& path) noexcept;
30
35 [[nodiscard]] const std::filesystem::path& fsPath() const { return filePath; }
36
41 [[nodiscard]] const std::filesystem::path& getFilePath() const { return filePath; }
42
47 [[nodiscard]] std::string string() const { return filePath.string(); }
48
53 [[nodiscard]] bool empty() const { return filePath.empty(); }
54
59 [[nodiscard]] std::size_t hash() const noexcept;
60
65 operator const std::filesystem::path&() const { return filePath; }
66
72 bool operator==(const Path& other) const { return filePath == other.filePath; }
73
77 void reset();
78
79 private:
80 std::filesystem::path filePath = "";
81 };
82
89 struct MeshPath {
93 MeshPath() = default;
94
100 MeshPath(const std::filesystem::path& path, const std::string& assetName);
101
106 MeshPath(MeshPath&& other ) noexcept;
107
112 MeshPath( const MeshPath & other) noexcept;
113
117 MeshPath& operator=(const MeshPath&) = default;
118
122 MeshPath& operator=(MeshPath&&) noexcept = default;
123
128 [[nodiscard]] const std::filesystem::path& getFilePath() const { return filePath_; }
129
134 [[nodiscard]] const std::string& getAssetName() const { return assetName_; }
135
140 [[nodiscard]] std::string getAssetHandle() const { return filePath_.string() + assetName_; }
141
146 [[nodiscard]] std::size_t hash() const noexcept;
147
152 [[nodiscard]] bool empty() const { return filePath_.empty() || assetName_.empty(); }
153
159 bool operator==(const MeshPath& other) const {
160 return filePath_ == other.filePath_ && assetName_ == other.assetName_;
161 }
162
166 void reset();
167
168 private:
169 std::filesystem::path filePath_ = "";
170 std::string assetName_ = std::string("");
171 };
172}
173
174namespace std {
178 template<>
179 struct hash<Asset::Path> {
185 size_t operator()(const Asset::Path& path) const noexcept {
186 return path.hash();
187 }
188 };
189
193 template<>
194 struct hash<Asset::MeshPath> {
200 size_t operator()(const Asset::MeshPath& path) const noexcept {
201 return path.hash();
202 }
203 };
204}
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:89
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:159
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:169
MeshPath & operator=(const MeshPath &)=default
Copy-assigns an asset path.
const std::filesystem::path & getFilePath() const
Gets the source file path.
Definition AssetPath.h:128
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:140
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:134
bool empty() const
Checks whether this path doesn't point to anything. So it is empty.
Definition AssetPath.h:152
std::string assetName_
Definition AssetPath.h:170
Identifies a single asset file on disk.
Definition AssetPath.h:13
bool empty() const
Checks whether the stored path is empty.
Definition AssetPath.h:53
bool operator==(const Path &other) const
Compares two asset file paths.
Definition AssetPath.h:72
std::string string() const
Converts the stored path to a string.
Definition AssetPath.h:47
std::filesystem::path filePath
Definition AssetPath.h:80
std::size_t hash() const noexcept
Calculates a hash for unordered containers.
const std::filesystem::path & getFilePath() const
Gets the stored filesystem path.
Definition AssetPath.h:41
const std::filesystem::path & fsPath() const
Gets the stored filesystem path.
Definition AssetPath.h:35
void reset()
Clears the stored filesystem path.
Path()=default
Creates an empty asset file path.
Path(const std::filesystem::path &path)
Creates an asset path from a filesystem path.
Path(std::filesystem::path &&path) noexcept
Move-constructs an asset path from a filesystem path.
size_t operator()(const Asset::MeshPath &path) const noexcept
Hashes a mesh asset path.
Definition AssetPath.h:200
size_t operator()(const Asset::Path &path) const noexcept
Hashes an asset file path.
Definition AssetPath.h:185