HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
static_resource_list.hpp
1// Copyright Take Vos 2021.
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 "assert.hpp"
8#include "void_span.hpp"
9#include <span>
10#include <cstddef>
11#include <atomic>
12#include <optional>
13
14namespace hi::inline v1 {
15struct static_resource_item;
16
21inline std::atomic<static_resource_item const *> static_resource_list = nullptr;
22
24 static_resource_item const *next;
25 char const *filename;
26 const_void_span bytes;
27
32 [[nodiscard]] static const_void_span find(std::string_view filename) noexcept
33 {
34 for (auto ptr = static_resource_list.load(); ptr != nullptr; ptr = ptr->next) {
35 if (filename == ptr->filename) {
36 return ptr->bytes;
37 }
38 }
39 return {};
40 }
41
54 [[nodiscard]] hi_no_inline static static_resource_item const *add(static_resource_item *new_item) noexcept
55 {
56 hi_axiom(new_item != nullptr);
57 return new_item->next = static_resource_list.exchange(new_item);
58 }
59};
60
61} // namespace hi::inline v1
Definition static_resource_list.hpp:23
static const_void_span find(std::string_view filename) noexcept
Search for a static resource item.
Definition static_resource_list.hpp:32
static hi_no_inline static_resource_item const * add(static_resource_item *new_item) noexcept
Add a resource item to the list.
Definition static_resource_list.hpp:54
Definition void_span.hpp:156