10#include "access_mode.hpp"
11#include "file_intf.hpp"
12#include "file_win32_impl.hpp"
13#include "../utility/utility.hpp"
14#include "../char_maps/char_maps.hpp"
15#include "../telemetry/telemetry.hpp"
16#include "../container/container.hpp"
17#include "../macros.hpp"
23hi_export_module(hikogui.file.file_view_impl);
25hi_export
namespace hi {
inline namespace v1 {
37 if (_data !=
nullptr) {
40 if (_mapping_handle) {
41 destroy_mapping(_mapping_handle);
49 _size = _file->size() - _offset;
52 if (_offset + _size > _file->size()) {
53 throw io_error(
"Requested mapping is beyond file size.");
56 if (_file->size() == 0) {
61 _mapping_handle = make_mapping(file_handle(),
access_mode(), _offset + _size);
63 _data = make_view(_mapping_handle,
access_mode(), _offset, _size);
65 destroy_mapping(_mapping_handle);
83 hi_assert_not_null(_file);
84 return _file->access_mode();
87 [[
nodiscard]] void_span void_span()
const noexcept
89 hi_assert_not_null(_file);
91 return {_data, _size};
94 [[
nodiscard]] const_void_span const_void_span()
const noexcept
96 return {_data, _size};
99 [[
nodiscard]]
bool unmapped()
const noexcept
101 if (_file !=
nullptr) {
102 if (_file->closed()) {
119 destroy_mapping(_mapping_handle);
120 _mapping_handle =
nullptr;
125 void flush(hi::void_span span)
const noexcept
133 mutable HANDLE _mapping_handle =
nullptr;
137 void *_data =
nullptr;
141 hi_assert_not_null(_file);
142 return _file->file_handle();
154 hi_assert(size != 0);
159 }
else if (to_bool(
access_mode & hi::access_mode::read)) {
162 throw io_error(
"Illegal access mode when mapping file.");
175 static void destroy_view(
void *data)
184 hi_assert(size != 0);
192 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_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
hi_export std::string get_last_error_message()
Get the OS error message from the last error received on this thread.
Definition exception_win32_impl.hpp:30
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
A File object.
Definition file_intf.hpp:33
Definition file_view_win32_impl.hpp:28
Exception thrown during I/O on an error.
Definition exception_intf.hpp:173