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 tt {
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]] size_t offset() const noexcept override { return 0; }
29
30 [[nodiscard]] size_t size() const noexcept override { return _bytes.size(); }
31
32 [[nodiscard]] std::byte const *data() const noexcept override { return _bytes.data(); }
33
34 [[nodiscard]] std::span<std::byte const> bytes() const noexcept override { return _bytes; }
35
36 [[nodiscard]] std::string_view string_view() const noexcept override { return {reinterpret_cast<char const*>(data()), size()}; }
37
38 [[nodiscard]] static std::unique_ptr<resource_view> loadView(std::string const &location) {
39 return std::make_unique<static_resource_view>(location);
40 }
41
49 static std::span<std::byte const> get_static_resource(std::string const &filename);
50
51private:
52 // Borrowed reference from a byte array inside StaticResources.
53 std::span<std::byte const> _bytes;
54};
55
56
57}
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
static std::span< std::byte const > get_static_resource(std::string const &filename)
Get the data of a static resource.
std::string_view string_view() const noexcept override
Get a span to the memory mapping.
Definition static_resource_view.hpp:36
size_t size() const noexcept override
Size of the memory mapping.
Definition static_resource_view.hpp:30
std::span< std::byte const > bytes() const noexcept override
Get a span to the memory mapping.
Definition static_resource_view.hpp:34
std::byte const * data() const noexcept override
Pointer to the memory mapping.
Definition static_resource_view.hpp:32
size_t offset() const noexcept override
Offset into the resource file.
Definition static_resource_view.hpp:28