11#include "file_intf.hpp"
12#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
13#include "file_view_win32_impl.hpp"
15#include "access_mode.hpp"
16#include "../container/container.hpp"
17#include "../char_maps/char_maps.hpp"
18#include "../utility/utility.hpp"
19#include "../macros.hpp"
24hi_export_module(hikogui.file.file_view);
29hi_warning_ignore_msvc(26490);
31hi_export
namespace hi {
inline namespace v1 {
59 _pimpl(
std::make_shared<detail::file_view_impl>(
file.pimpl(), offset, size))
64 std::filesystem::path
const& path,
74 hi_assert_not_null(_pimpl);
75 return _pimpl->offset();
80 hi_assert_not_null(_pimpl);
81 return _pimpl->size();
92 if (_pimpl->unmapped()) {
108 explicit operator bool() const noexcept
113 void unmap() noexcept
115 if (
auto pimpl = std::exchange(_pimpl,
nullptr)) {
124 hi_assert_not_null(_pimpl);
125 return _pimpl->void_span();
132 hi_assert_not_null(_pimpl);
133 return _pimpl->const_void_span();
140 void flush(hi::void_span span)
const noexcept
142 hi_assert_not_null(_pimpl);
143 return _pimpl->flush(span);
147 [[nodiscard]]
friend std::span<T> as_span(
file_view const& view)
noexcept
149 if constexpr (std::is_const_v<T>) {
150 return as_span<T>(view.const_void_span());
152 return as_span<T>(view.void_span());
156 [[nodiscard]]
friend std::string_view as_string_view(file_view
const& view)
noexcept
158 hi_assert(view.offset() == 0);
159 return as_string_view(view.const_void_span());
162 [[nodiscard]]
friend bstring_view as_bstring_view(file_view
const& view)
noexcept
164 hi_assert(view.offset() == 0);
165 return as_bstring_view(view.const_void_span());
169 mutable std::shared_ptr<detail::file_view_impl> _pimpl;
access_mode
The mode in which way to open a file.
Definition access_mode.hpp:17
@ open_for_read
Default open a file for reading.
Definition access_mode.hpp:32
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:24
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
A File object.
Definition file_intf.hpp:35
Map a file into virtual memory.
Definition file_view.hpp:41
void_span void_span() const noexcept
Span to the mapping into memory.
Definition file_view.hpp:122
const_void_span const_void_span() const noexcept
Definition file_view.hpp:130
void flush(hi::void_span span) const noexcept
Flush changes in memory to the open file view.
Definition file_view.hpp:140
file_view(file const &file, std::size_t offset=0, std::size_t size=0)
Create a file-view from a file-mapping.
Definition file_view.hpp:58
bool unmapped() const noexcept
Check if this file view is closed.
Definition file_view.hpp:89