Toast Engine
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
16namespace toast {
17
18enum class URI : uint8_t {
19 error,
20 asset,
21 artwork,
22 node,
23};
24
25namespace _detail {
26constexpr std::string_view asset_uri = "asset://";
27constexpr std::string_view artwork_uri = "artwork://";
28constexpr std::string_view node_uri = "node://";
29
30inline std::string assets_path;
31inline std::string artworks_path;
32}
33
35inline auto setAssetsPath(std::string_view path) -> void {
36 _detail::assets_path = path;
37}
38
40inline auto setArtworkPath(std::string_view path) -> void {
41 _detail::artworks_path = path;
42}
43
44inline 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}
Member-robber pattern used by the generated reflection code.
Definition defer.hpp:16
auto setAssetsPath(std::string_view path) -> void
must be called before any handleURI(); not thread-safe after initialization
Definition uri_handler.hpp:35
auto setArtworkPath(std::string_view path) -> void
must be called before any handleURI(); not thread-safe after initialization
Definition uri_handler.hpp:40