13#include "../container/module.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;
113 std::filesystem::path
const& path,
124 return _pimpl->offset();
130 return _pimpl->size();
141 if (_pimpl->unmapped()) {
157 explicit operator bool() const noexcept
162 void unmap() noexcept
164 if (
auto pimpl = std::exchange(_pimpl,
nullptr)) {
174 return _pimpl->void_span();
182 return _pimpl->const_void_span();
189 void flush(hi::void_span span)
const noexcept
192 return _pimpl->flush(span);
196 [[nodiscard]]
friend std::span<T> as_span(
file_view const& view)
noexcept
198 if constexpr (std::is_const_v<T>) {
199 return as_span<T>(view.const_void_span());
201 return as_span<T>(view.void_span());
205 [[nodiscard]]
friend std::string_view as_string_view(file_view
const& view)
noexcept
208 return as_string_view(view.const_void_span());
211 [[nodiscard]]
friend bstring_view as_bstring_view(file_view
const& view)
noexcept
214 return as_bstring_view(view.const_void_span());
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199
#define hi_assert_not_null(x,...)
Assert if an expression is not nullptr.
Definition assert.hpp:238
access_mode
The mode in which way to open a file.
Definition file.hpp:35
@ open_for_read
Default open a file for reading.
@ write
Allow write access to a file.
@ flush
Align the text naturally based on the writing direction of each paragraph.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A File object.
Definition file.hpp:105
Definition file_view.hpp:27
Map a file into virtual memory.
Definition file_view.hpp:93
void_span void_span() const noexcept
Span to the mapping into memory.
Definition file_view.hpp:171
const_void_span const_void_span() const noexcept
Definition file_view.hpp:179
void flush(hi::void_span span) const noexcept
Flush changes in memory to the open file view.
Definition file_view.hpp:189
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:138