HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
static_resource_view.hpp
1// Copyright Take Vos 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 "resource_view.hpp"
8#include "required.hpp"
9#include <span>
10#include <cstddef>
11#include <unordered_map>
12
13namespace hi::inline v1 {
14
18public:
19 static_resource_view(std::string const &filename);
20
21 static_resource_view() = delete;
22 ~static_resource_view() = default;
23 static_resource_view(static_resource_view const &other) = default;
24 static_resource_view &operator=(static_resource_view const &other) = default;
26 static_resource_view &operator=(static_resource_view &&other) = default;
27
28 [[nodiscard]] std::size_t offset() const noexcept override
29 {
30 return 0;
31 }
32
33 [[nodiscard]] std::size_t size() const noexcept override
34 {
35 return _bytes.size();
36 }
37
38 [[nodiscard]] std::byte const *data() const noexcept override
39 {
40 return _bytes.data();
41 }
42
43 [[nodiscard]] std::span<std::byte const> bytes() const noexcept override
44 {
45 return _bytes;
46 }
47
48 [[nodiscard]] std::string_view string_view() const noexcept override
49 {
50 return {reinterpret_cast<char const *>(data()), size()};
51 }
52
53 [[nodiscard]] static std::unique_ptr<resource_view> loadView(std::string const &location)
54 {
55 return std::make_unique<static_resource_view>(location);
56 }
57
65 static std::span<std::byte const> get_static_resource(std::string const &filename);
66
67private:
68 // Borrowed reference from a byte array inside StaticResources.
69 std::span<std::byte const> _bytes;
70};
71
72} // namespace hi::inline v1
This file includes required definitions.
A read-only memory mapping of a resource.
Definition resource_view.hpp:18
A resource that was included in the executable.
Definition static_resource_view.hpp:17
std::span< std::byte const > bytes() const noexcept override
Get a span to the memory mapping.
Definition static_resource_view.hpp:43
std::byte const * data() const noexcept override
Pointer to the memory mapping.
Definition static_resource_view.hpp:38
static std::span< std::byte const > get_static_resource(std::string const &filename)
Get the data of a static resource.
std::size_t size() const noexcept override
Size of the memory mapping.
Definition static_resource_view.hpp:33
std::size_t offset() const noexcept override
Offset into the resource file.
Definition static_resource_view.hpp:28
std::string_view string_view() const noexcept override
Get a span to the memory mapping.
Definition static_resource_view.hpp:48