载入中...
搜索中...
未找到
Uri.h
浏览该文件的文档.
1#pragma once
2
8#include "common/Export.h"
9#include "common/Result.h"
10
11#include <cstdint>
12#include <functional>
13#include <string>
14#include <string_view>
15#include <utility>
16
17namespace eve {
18
25enum class UriScheme : std::uint8_t {
26 Asset,
27 Project,
28 Builtin,
30 Memory,
31};
32
34[[nodiscard]] EVENGINE_API_FOUNDATION const char* uriSchemeName(UriScheme scheme) noexcept;
35
45public:
52 [[nodiscard]] static Result<Uri> parse(std::string_view text);
53
62 [[nodiscard]] static Result<Uri> fromParts(UriScheme scheme, std::string_view path, std::string_view query = {},
63 std::string_view fragment = {});
64
66 [[nodiscard]] UriScheme scheme() const noexcept { return scheme_; }
67
69 [[nodiscard]] std::string_view path() const noexcept { return path_; }
70
72 [[nodiscard]] std::string_view query() const noexcept { return query_; }
73
75 [[nodiscard]] std::string_view fragment() const noexcept { return fragment_; }
76
78 [[nodiscard]] const std::string& format() const noexcept { return formatted_; }
79
81 friend bool operator==(const Uri&, const Uri&) noexcept = default;
82
83private:
84 Uri(UriScheme scheme, std::string path, std::string query, std::string fragment);
85
86 UriScheme scheme_;
87 std::string path_;
88 std::string query_;
89 std::string fragment_;
90 std::string formatted_;
91};
92
102public:
108 [[nodiscard]] static Result<ResourceUri> parse(std::string_view text);
109
118 [[nodiscard]] static Result<ResourceUri> fromParts(UriScheme scheme, std::string_view path,
119 std::string_view query = {}, std::string_view fragment = {});
120
127 [[nodiscard]] static Result<ResourceUri> fromLegacyProjectPath(std::string_view path);
128
130 [[nodiscard]] UriScheme scheme() const noexcept { return uri_.scheme(); }
131
133 [[nodiscard]] std::string_view path() const noexcept { return uri_.path(); }
134
136 [[nodiscard]] std::string_view query() const noexcept { return uri_.query(); }
137
139 [[nodiscard]] std::string_view fragment() const noexcept { return uri_.fragment(); }
140
142 [[nodiscard]] const std::string& format() const noexcept { return uri_.format(); }
143
145 [[nodiscard]] const Uri& uri() const noexcept { return uri_; }
146
148 friend bool operator==(const ResourceUri&, const ResourceUri&) noexcept = default;
149
150private:
151 explicit ResourceUri(Uri uri) : uri_(std::move(uri)) {}
152
153 Uri uri_;
154};
155
156} // namespace eve
157
158namespace std {
159
160template <>
162struct hash<eve::Uri> {
164 std::size_t operator()(const eve::Uri& value) const noexcept {
165 return std::hash<std::string_view>{}(value.format());
166 }
167};
168
169template <>
171struct hash<eve::ResourceUri> {
173 std::size_t operator()(const eve::ResourceUri& value) const noexcept {
174 return std::hash<std::string_view>{}(value.format());
175 }
176};
177
178} // namespace std
double value
std::array< std::uint8_t, 32 > hash
Definition Evpack.cpp:172
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string text
std::string path
Definition PlayHost.cpp:110
std::string uri
Move-only, checked operation results for the common layer.
A semantically named resource locator.
Definition Uri.h:101
std::string_view path() const noexcept
Return the relative virtual path, borrowed from this value.
Definition Uri.h:133
std::string_view fragment() const noexcept
Return the fragment component, borrowed from this value.
Definition Uri.h:139
const Uri & uri() const noexcept
Return the structural URI view owned by this resource URI.
Definition Uri.h:145
const std::string & format() const noexcept
Return the stable canonical URI text owned by this value.
Definition Uri.h:142
friend bool operator==(const ResourceUri &, const ResourceUri &) noexcept=default
Compare resource URI values.
UriScheme scheme() const noexcept
Return the resource namespace.
Definition Uri.h:130
std::string_view query() const noexcept
Return the query component, borrowed from this value.
Definition Uri.h:136
Move-only operation result carrying either a value or Status.
Definition Result.h:155
An immutable, canonical URI value.
Definition Uri.h:44
std::string_view fragment() const noexcept
Return the fragment component without #, borrowed from this URI.
Definition Uri.h:75
std::string_view path() const noexcept
Return the virtual path, borrowed from this URI until it is moved or destroyed.
Definition Uri.h:69
friend bool operator==(const Uri &, const Uri &) noexcept=default
Compare canonical URI values.
std::string_view query() const noexcept
Return the query component without ?, borrowed from this URI.
Definition Uri.h:72
const std::string & format() const noexcept
Return the stable canonical URI text owned by this value.
Definition Uri.h:78
UriScheme scheme() const noexcept
Return the parsed scheme.
Definition Uri.h:66
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
UriScheme
URI schemes understood by the resource layer.
Definition Uri.h:25
const char * uriSchemeName(UriScheme scheme) noexcept
Return the stable lower-case spelling of a resource URI scheme.
Definition Uri.cpp:130