13#include "../void_span.hpp"
21hi_warning_ignore_msvc(26490);
23namespace hi {
inline namespace v1 {
40 _size = _file->size() - _offset;
57 return _file->access_mode();
60 [[nodiscard]] void_span void_span()
const noexcept
64 return {_data, _size};
67 [[nodiscard]] const_void_span const_void_span()
const noexcept
69 return {_data, _size};
72 [[nodiscard]]
virtual bool unmapped()
const noexcept = 0;
73 virtual void flush(hi::void_span span)
const noexcept = 0;
74 virtual void unmap() = 0;
80 void *_data =
nullptr;
100 constexpr file_view()
noexcept =
default;
117 std::filesystem::path
const& path,
128 return _pimpl->offset();
134 return _pimpl->size();
145 if (_pimpl->unmapped()) {
161 explicit operator bool() const noexcept
166 void unmap() noexcept
168 if (
auto pimpl = std::exchange(_pimpl,
nullptr)) {
178 return _pimpl->void_span();
186 return _pimpl->const_void_span();
193 void flush(hi::void_span span)
const noexcept
196 return _pimpl->flush(span);
200 [[nodiscard]]
friend std::span<T> as_span(
file_view const& view)
noexcept
202 if constexpr (std::is_const_v<T>) {
203 return as_span<T>(view.const_void_span());
205 return as_span<T>(view.void_span());
209 [[nodiscard]]
friend std::string_view as_string_view(file_view
const& view)
noexcept
212 return as_string_view(view.const_void_span());
215 [[nodiscard]]
friend bstring_view as_bstring_view(file_view
const& view)
noexcept
218 return as_bstring_view(view.const_void_span());
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:87
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:118
access_mode
The mode in which way to open a file.
Definition file.hpp:36
@ open_for_read
Default open a file for reading.
@ write
Allow write access to a file.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:15
geometry/margins.hpp
Definition assert.hpp:18
A File object.
Definition file.hpp:106
Definition file_view.hpp:27
Map a file into virtual memory.
Definition file_view.hpp:97
void_span void_span() const noexcept
Span to the mapping into memory.
Definition file_view.hpp:175
const_void_span const_void_span() const noexcept
Definition file_view.hpp:183
void flush(hi::void_span span) const noexcept
Flush changes in memory to the open file view.
Definition file_view.hpp:193
file_view(file const &file, std::size_t offset=0, std::size_t size=0)
Create a file-view from a file-mapping.
bool unmapped() const noexcept
Check if this file view is closed.
Definition file_view.hpp:142