HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
StaticResourceView.hpp
1// Copyright 2019 Pokitec
2// All rights reserved.
3
4#pragma once
5
6#include "TTauri/Foundation/ResourceView.hpp"
7#include "TTauri/Foundation/required.hpp"
8#include <nonstd/span>
9#include <cstddef>
10#include <unordered_map>
11
12namespace tt {
13
17private:
18 // Borrowed reference from a byte array inside StaticResources.
19 nonstd::span<std::byte const> _bytes;
20
21public:
22 StaticResourceView(std::string const &filename);
23
24 StaticResourceView() = delete;
25 ~StaticResourceView() = default;
26 StaticResourceView(StaticResourceView const &other) = default;
27 StaticResourceView &operator=(StaticResourceView const &other) = default;
28 StaticResourceView(StaticResourceView &&other) = default;
29 StaticResourceView &operator=(StaticResourceView &&other) = default;
30
31 [[nodiscard]] size_t offset() const noexcept override { return 0; }
32
33 [[nodiscard]] size_t size() const noexcept override { return _bytes.size(); }
34
35 [[nodiscard]] std::byte const *data() const noexcept override { return _bytes.data(); }
36
37 [[nodiscard]] nonstd::span<std::byte const> bytes() const noexcept override { return _bytes; }
38
39 [[nodiscard]] std::string_view string_view() const noexcept override { return {reinterpret_cast<char const*>(data()), size()}; }
40
41 [[nodiscard]] static std::unique_ptr<ResourceView> loadView(std::string const &location) {
42 return std::make_unique<StaticResourceView>(location);
43 }
44};
45
46
47}
A read-only memory mapping of a resource.
Definition ResourceView.hpp:17
A resource that was included in the executable.
Definition StaticResourceView.hpp:16
nonstd::span< std::byte const > bytes() const noexcept override
Get a span to the memory mapping.
Definition StaticResourceView.hpp:37
std::byte const * data() const noexcept override
Pointer to the memory mapping.
Definition StaticResourceView.hpp:35
size_t size() const noexcept override
Size of the memory mapping.
Definition StaticResourceView.hpp:33
std::string_view string_view() const noexcept override
Get a span to the memory mapping.
Definition StaticResourceView.hpp:39
size_t offset() const noexcept override
Offset into the resource file.
Definition StaticResourceView.hpp:31