8#include "../utility/utility.hpp"
9#include "../macros.hpp"
13hi_export_module(hikogui.file.file_view : impl);
15hi_export
namespace hi::inline
v1 {
18 _file_mapping_object(_file_mapping_object), _offset(offset)
21 size = _file_mapping_object->size - _offset;
23 hi_assert(_offset + size <= _file_mapping_object->size);
26 if (accessMode() >= (AccessMode::Read | AccessMode::Write)) {
27 prot = PROT_WRITE | PROT_READ;
28 }
else if (accessMode() >= AccessMode::Read) {
31 throw io_error(
"{}: Illegal access mode write-only when viewing file.", location());
34 int flags = MAP_SHARED;
37 if ((data = ::mmap(0, size, prot, flags, _file_mapping_object->file->fileHandle, _offset)) == MAP_FAILED) {
41 auto *bytes_ptr =
new void_span(data, size);
45file_view::file_view(std::filesystem::path
const &path, AccessMode accessMode,
std::size_t offset,
std::size_t size) :
46 file_view(findOrCreateFileMappingObject(path, accessMode, offset + size), offset, size)
50file_view::file_view(file_view
const &other) noexcept :
51 _file_mapping_object(
other._file_mapping_object), _bytes(
other._bytes), _offset(
other._offset)
53 hi_assert(&other !=
this);
56file_view &file_view::operator=(file_view
const &other)
noexcept
58 hi_return_on_self_assignment(other);
59 _file_mapping_object =
other._file_mapping_object;
60 _offset =
other._offset;
61 _bytes =
other._bytes;
65file_view::file_view(file_view &&other) noexcept :
68 hi_assert(&other !=
this);
71file_view &file_view::operator=(file_view &&other)
noexcept
73 hi_return_on_self_assignment(other);
75 _offset =
other._offset;
80void file_view::unmap(void_span *bytes)
noexcept
82 if (bytes !=
nullptr) {
83 if (!bytes->empty()) {
84 if (!munmap(bytes->data(), bytes->size())) {
95 if (!msync(base, size, flags)) {
Defines the file_view class.
@ other
The gui_event does not have associated data.
hi_export std::string get_last_error_message(uint32_t error_code)
Get the error message from an error code.
Definition exception_win32_impl.hpp:21
DOXYGEN BUG.
Definition algorithm_misc.hpp:20