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
4namespace Asset {
5 struct Path {
6 Path() = default;
7 Path(const std::filesystem::path& path, const std::string& assetName);
8
9 // constructors
10 Path(Path&& other ) noexcept;
11 Path( const Path & other) noexcept;
12
13 // assignment
14 Path& operator=(const Path&) = default;
15 Path& operator=(Path&&) noexcept = default;
16
17 [[nodiscard]] std::filesystem::path getFilePath() const { return filePath; }
18 [[nodiscard]] std::string getAssetName() const { return assetName; }
19 [[nodiscard]] std::string getAssetHandle() const { return filePath.string() + assetName; }
20
25 [[nodiscard]] bool empty() const { return filePath.empty() || assetName.empty(); }
26
27 bool operator==(const Path& other) const {
28 return getAssetHandle() == other.getAssetHandle();
29 }
30
31 void reset();
32
33 private:
34 std::filesystem::path filePath = "";
35 std::string assetName = std::string("");
36 };
37
38 inline Path::Path(const std::filesystem::path &path, const std::string &assetName) : filePath(path), assetName(assetName) {
39 }
40
41 inline Path::Path( Path && other ) noexcept : filePath(std::move(other.filePath)), assetName(std::move(other.assetName))
42 {
43 }
44
45 inline Path::Path( const Path & other ) noexcept : filePath(other.filePath), assetName(other.assetName)
46 {
47 }
48
49 inline void Path::reset()
50 {
51 filePath = std::filesystem::path("");
52 assetName = std::string("");
53 }
54
55 static Path GetTexturePath(const std::filesystem::path& path) {
56 return {path, path.filename().generic_string()};
57 }
58}
59
60namespace std {
61 template<>
62 struct hash<Asset::Path> {
63 size_t operator()(const Asset::Path& path) const noexcept {
64 return std::hash<std::string>{}(path.getAssetHandle());
65 }
66 };
67}
Classes which are related to asset loading are mostly stored in this namespace.
static Path GetTexturePath(const std::filesystem::path &path)
Definition AssetPath.h:55
STL namespace.
bool empty() const
Checks whether this path doesn't point to anything. So it is empty.
Definition AssetPath.h:25
std::string getAssetName() const
Definition AssetPath.h:18
bool operator==(const Path &other) const
Definition AssetPath.h:27
std::filesystem::path getFilePath() const
Definition AssetPath.h:17
std::filesystem::path filePath
Definition AssetPath.h:34
Path & operator=(Path &&) noexcept=default
void reset()
Definition AssetPath.h:49
Path()=default
std::string assetName
Definition AssetPath.h:35
Path & operator=(const Path &)=default
std::string getAssetHandle() const
Definition AssetPath.h:19
size_t operator()(const Asset::Path &path) const noexcept
Definition AssetPath.h:63