HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
resource_view.hpp
1// Copyright Take Vos 2019-2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "void_span.hpp"
8#include <span>
9#include <variant>
10#include <functional>
11#include <cstddef>
12#include <string_view>
13#include <type_traits>
14
15namespace hi::inline v1 {
16class URL;
17
21public:
22 resource_view() = default;
23 virtual ~resource_view() = default;
24 resource_view(resource_view const& other) = default;
25 resource_view(resource_view&& other) = default;
26 resource_view& operator=(resource_view const& other) = default;
27 resource_view& operator=(resource_view&& other) = default;
28
32 [[nodiscard]] virtual std::size_t offset() const noexcept = 0;
33
34
37 [[nodiscard]] virtual const_void_span span() const noexcept = 0;
38};
39
41public:
44 [[nodiscard]] virtual void_span writable_span() noexcept = 0;
45};
46
49[[nodiscard]] inline std::string_view as_string_view(resource_view const &rhs) noexcept
50{
51 return as_string_view(rhs.span());
52}
53
54[[nodiscard]] inline bstring_view as_bstring_view(resource_view const &rhs) noexcept
55{
56 return as_bstring_view(rhs.span());
57}
58
59template<typename T, size_t E = std::dynamic_extent>
60[[nodiscard]] inline std::span<T, E> as_span(resource_view const& rhs) noexcept requires(std::is_const_v<T>)
61{
62 return as_span<T, E>(rhs.span());
63}
64
65template<typename T, size_t E = std::dynamic_extent>
66[[nodiscard]] inline std::span<T, E> as_writable_span(writable_resource_view& rhs) noexcept
67{
68 return as_span<T, E>(rhs.writable_span());
69}
70
71} // namespace hi::inline v1
STL namespace.
A read-only memory mapping of a resource.
Definition resource_view.hpp:20
virtual std::size_t offset() const noexcept=0
Offset into the resource file.
Definition resource_view.hpp:40
virtual void_span writable_span() noexcept=0
Get a span to the memory mapping.
Definition void_span.hpp:19
Definition void_span.hpp:156