Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
uri_handler.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include <cstdint>
12
#include <string>
13
#include <string_view>
14
#include <utility>
15
16
namespace
toast {
17
18
enum class
URI : uint8_t {
19
error,
20
asset,
21
artwork,
22
node,
23
};
24
25
namespace
_detail
{
26
constexpr
std::string_view asset_uri =
"asset://"
;
27
constexpr
std::string_view artwork_uri =
"artwork://"
;
28
constexpr
std::string_view node_uri =
"node://"
;
29
30
inline
std::string assets_path;
31
inline
std::string artworks_path;
32
}
33
35
inline
auto
setAssetsPath
(std::string_view path) ->
void
{
36
_detail::assets_path = path;
37
}
38
40
inline
auto
setArtworkPath
(std::string_view path) ->
void
{
41
_detail::artworks_path = path;
42
}
43
44
inline
auto
handleURI(std::string_view path) -> std::pair<URI, std::string> {
45
if
(path.starts_with(_detail::asset_uri)) {
46
std::string p = _detail::assets_path + std::string(path.substr(_detail::asset_uri.size()));
47
return
{URI::asset, p};
48
}
49
if
(path.starts_with(_detail::artwork_uri)) {
50
std::string p = _detail::artworks_path + std::string(path.substr(_detail::artwork_uri.size()));
51
return
{URI::artwork, p};
52
}
53
if
(path.starts_with(_detail::node_uri)) {
54
return
{URI::node, std::string {path.substr(_detail::node_uri.size())}};
55
}
56
57
return
{URI::error, std::string {path}};
58
}
59
60
}
toast::_detail
Member-robber pattern used by the generated reflection code.
Definition
defer.hpp:16
toast::setAssetsPath
auto setAssetsPath(std::string_view path) -> void
must be called before any handleURI(); not thread-safe after initialization
Definition
uri_handler.hpp:35
toast::setArtworkPath
auto setArtworkPath(std::string_view path) -> void
must be called before any handleURI(); not thread-safe after initialization
Definition
uri_handler.hpp:40
engine
src
toast
uri_handler.hpp
Generated by
1.17.0