HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
file_view.hpp
1// Copyright Take Vos 2019, 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 "file_mapping.hpp"
8#include "resource_view.hpp"
9#include "void_span.hpp"
10#include <span>
11
12hi_warning_push();
13// C26490: Don't use reinterpret_cast (type.1).
14// We need to convert bytes to chars to get a string_view from the byte buffer.
15hi_warning_ignore_msvc(26490);
16
17namespace hi::inline v1 {
18
22public:
23 file_view(std::shared_ptr<file_mapping> const& mappingObject, std::size_t offset, std::size_t size);
25 URL const& location,
26 access_mode accessMode = access_mode::open_for_read,
27 std::size_t offset = 0,
28 std::size_t size = 0);
29 ~file_view() = default;
30
31 file_view() = delete;
32 file_view(file_view const& other) noexcept;
33 file_view(file_view&& other) noexcept;
34 file_view& operator=(file_view const& other) noexcept;
35 file_view& operator=(file_view&& other) noexcept;
36
39 [[nodiscard]] access_mode accessMode() const noexcept
40 {
41 return _file_mapping_object->accessMode();
42 }
43
46 [[nodiscard]] URL const& location() const noexcept
47 {
48 return _file_mapping_object->location();
49 }
50
53 [[nodiscard]] std::size_t offset() const noexcept override
54 {
55 return _offset;
56 }
57
60 [[nodiscard]] void_span writable_span() noexcept override
61 {
62 return *_bytes;
63 }
64
67 [[nodiscard]] const_void_span span() const noexcept override
68 {
69 return *_bytes;
70 }
71
76 void flush(void *base, std::size_t size);
77
81 [[nodiscard]] static std::unique_ptr<resource_view> loadView(URL const& location)
82 {
83 return std::make_unique<file_view>(location);
84 }
85
86private:
93 static void unmap(void_span *bytes) noexcept;
94
104 [[nodiscard]] static std::shared_ptr<file_mapping>
105 findOrCreateFileMappingObject(URL const& path, access_mode accessMode, std::size_t size);
106
107private:
110 std::shared_ptr<file_mapping> _file_mapping_object;
111
117
120 std::size_t _offset;
121};
122
123} // namespace hi::inline v1
124
125hi_warning_pop();
Definition file_view.hpp:21
void_span writable_span() noexcept override
Definition file_view.hpp:60
static std::unique_ptr< resource_view > loadView(URL const &location)
Definition file_view.hpp:81
access_mode accessMode() const noexcept
Definition file_view.hpp:39
void flush(void *base, std::size_t size)
Flush changes in memory to the open file.
const_void_span span() const noexcept override
Definition file_view.hpp:67
std::size_t offset() const noexcept override
Definition file_view.hpp:53
URL const & location() const noexcept
Definition file_view.hpp:46
Definition resource_view.hpp:40
Definition URL.hpp:47
Definition void_span.hpp:19
Definition void_span.hpp:156