1#ifndef SOURCEMETA_CORE_IO_FILEVIEW_H_
2#define SOURCEMETA_CORE_IO_FILEVIEW_H_
4#ifndef SOURCEMETA_CORE_IO_EXPORT
5#include <sourcemeta/core/io_export.h>
14namespace sourcemeta::core {
45 [[nodiscard]]
auto size() const noexcept -> std::
size_t;
58 [[nodiscard]] auto
bytes() const noexcept -> std::span<const std::uint8_t> {
59 return {this->data_, this->size_};
66 [[nodiscard]]
auto as(
const std::size_t offset = 0) const noexcept
68 assert(offset +
sizeof(T) <= this->size_);
70 return reinterpret_cast<const T *
>(this->data_ + offset);
74 const std::uint8_t *data_{
nullptr};
77 void *file_handle_{
nullptr};
78 void *mapping_handle_{
nullptr};
80 int file_descriptor_{-1};
FileView(const std::filesystem::path &path)
Memory-map the file at the given path.
auto bytes() const noexcept -> std::span< const std::uint8_t >
Definition io_fileview.h:58
auto as(const std::size_t offset=0) const noexcept -> const T *
Definition io_fileview.h:66
auto size() const noexcept -> std::size_t
The size of the memory-mapped data in bytes.