opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
resource_path.h
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <filesystem>
5#include <ostream>
6#include <string>
7#include <string_view>
8#include <utility>
9
10namespace osc
11{
13 public:
14 template<typename... Args>
15 requires std::constructible_from<std::filesystem::path, Args&&...>
17 path_{std::forward<Args>(args)...}
18 {}
19
20 std::string string() const
21 {
22 return path_.string();
23 }
24
25 bool has_extension(std::string_view ext) const
26 {
27 return path_.extension() == ext;
28 }
29
30 std::string stem() const
31 {
32 return path_.stem().string();
33 }
34
35 friend bool operator==(const ResourcePath&, const ResourcePath&) = default;
37 {
38 return ResourcePath{lhs.path_ / rhs.path_};
39 }
40 friend ResourcePath operator/(const ResourcePath& lhs, std::string_view rhs)
41 {
42 return ResourcePath{lhs.path_ / rhs};
43 }
44 friend std::ostream& operator<<(std::ostream& out, const ResourcePath& resource_path)
45 {
46 return out << resource_path.path_;
47 }
48 private:
49 friend struct std::hash<osc::ResourcePath>;
50 std::filesystem::path path_;
51 };
52}
53
55struct std::hash<osc::ResourcePath> final {
56 size_t operator()(const osc::ResourcePath& resource_path) const noexcept
57 {
58 return std::filesystem::hash_value(resource_path.path_);
59 }
60};
Definition resource_path.h:12
bool has_extension(std::string_view ext) const
Definition resource_path.h:25
std::string stem() const
Definition resource_path.h:30
ResourcePath(Args &&... args)
Definition resource_path.h:16
friend ResourcePath operator/(const ResourcePath &lhs, const ResourcePath &rhs)
Definition resource_path.h:36
friend std::ostream & operator<<(std::ostream &out, const ResourcePath &resource_path)
Definition resource_path.h:44
std::string string() const
Definition resource_path.h:20
friend bool operator==(const ResourcePath &, const ResourcePath &)=default
friend ResourcePath operator/(const ResourcePath &lhs, std::string_view rhs)
Definition resource_path.h:40
Definition custom_decoration_generator.h:5
constexpr U to(T &&value)
Definition conversion.h:56
size_t operator()(const osc::ResourcePath &resource_path) const noexcept
Definition resource_path.h:56