10#include "file_file.hpp"
11#include "../utility/utility.hpp"
12#include "../telemetry/telemetry.hpp"
13#include "../macros.hpp"
16hi_export_module(hikogui.file.file_view : impl);
18namespace hi {
inline namespace v1 {
30 if (_data !=
nullptr) {
33 if (_mapping_handle) {
34 destroy_mapping(_mapping_handle);
42 _size = _file->size() - _offset;
45 if (_offset + _size > _file->size()) {
46 throw io_error(
"Requested mapping is beyond file size.");
49 if (_file->size() == 0) {
54 _mapping_handle = make_mapping(file_handle(),
access_mode(), _offset + _size);
56 _data = make_view(_mapping_handle,
access_mode(), _offset, _size);
58 destroy_mapping(_mapping_handle);
76 hi_assert_not_null(_file);
77 return _file->access_mode();
80 [[
nodiscard]] void_span void_span()
const noexcept
82 hi_assert_not_null(_file);
84 return {_data, _size};
87 [[
nodiscard]] const_void_span const_void_span()
const noexcept
89 return {_data, _size};
92 [[
nodiscard]]
bool unmapped()
const noexcept
94 if (_file !=
nullptr) {
95 if (_file->closed()) {
112 destroy_mapping(_mapping_handle);
113 _mapping_handle =
nullptr;
118 void flush(hi::void_span span)
const noexcept
126 mutable HANDLE _mapping_handle =
nullptr;
130 void *_data =
nullptr;
134 hi_assert_not_null(_file);
135 return _file->file_handle();
147 hi_assert(size != 0);
152 }
else if (to_bool(
access_mode & hi::access_mode::read)) {
155 throw io_error(
"Illegal access mode when mapping file.");
168 static void destroy_view(
void *data)
177 hi_assert(size != 0);
185 throw io_error(std::format(
"Illegal access mode when viewing file."));
Rules for working with win32 headers.
access_mode
The mode in which way to open a file.
Definition access_mode.hpp:17
@ read
Allow read access to a file.
@ write
Allow write access to a file.
@ flush
Align the text naturally based on the writing direction of each paragraph.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:31
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A File object.
Definition file_file_intf.hpp:30
Definition file_view_win32_impl.hpp:21
Exception thrown during I/O on an error.
Definition exception_intf.hpp:172