6#include "../utility/utility.hpp"
7#include "../macros.hpp"
19 size = _file_mapping_object->size - _offset;
21 hi_assert(_offset + size <= _file_mapping_object->size);
24 if (accessMode() >= (AccessMode::Read | AccessMode::Write)) {
25 prot = PROT_WRITE | PROT_READ;
26 }
else if (accessMode() >= AccessMode::Read) {
29 throw io_error(
"{}: Illegal access mode write-only when viewing file.", location());
32 int flags = MAP_SHARED;
35 if ((data = ::mmap(0, size, prot, flags, _file_mapping_object->file->fileHandle, _offset)) == MAP_FAILED) {
39 auto *bytes_ptr =
new void_span(data, size);
43file_view::file_view(std::filesystem::path
const &path, AccessMode accessMode,
std::size_t offset,
std::size_t size) :
44 file_view(findOrCreateFileMappingObject(path, accessMode, offset + size), offset, size)
48file_view::file_view(file_view
const &other) noexcept :
49 _file_mapping_object(
other._file_mapping_object), _bytes(
other._bytes), _offset(
other._offset)
51 hi_assert(&other !=
this);
54file_view &file_view::operator=(file_view
const &other)
noexcept
56 hi_return_on_self_assignment(other);
57 _file_mapping_object =
other._file_mapping_object;
58 _offset =
other._offset;
59 _bytes =
other._bytes;
63file_view::file_view(file_view &&other) noexcept :
66 hi_assert(&other !=
this);
69file_view &file_view::operator=(file_view &&other)
noexcept
71 hi_return_on_self_assignment(other);
73 _offset =
other._offset;
78void file_view::unmap(void_span *bytes)
noexcept
80 if (bytes !=
nullptr) {
81 if (!bytes->empty()) {
82 if (!munmap(bytes->data(), bytes->size())) {
93 if (!msync(base, size, flags)) {
Defines the file_view class.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:16
std::string get_last_error_message(uint32_t error_code)
Get the error message from an error code.
Definition exception_win32_impl.hpp:22
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377