4#ifndef GREM_CORE_SYSTEM_NATIVE_INPUT_FILE_HPP
5#define GREM_CORE_SYSTEM_NATIVE_INPUT_FILE_HPP
32 ,
public std::ifstream {
48 , std::ifstream(std::
move(static_cast<std::ifstream&>(other)))
49 , fileSize(std::exchange(other.fileSize,
size_t{0})) {}
58 std::ifstream::close();
61 [[nodiscard]]
bool isOpen() const noexcept
override {
62 return std::ifstream::is_open();
65 [[nodiscard]]
bool eof() const noexcept
override {
66 return !
isOpen() || std::ifstream::eof();
69 [[nodiscard]]
size_t size() const noexcept
override {
73 [[nodiscard]]
size_t tellg() const noexcept
override {
74 return static_cast<size_t>(
const_cast<std::ifstream*
>(
static_cast<const std::ifstream*
>(
this))->tellg());
77 void seekg(
size_t position)
override {
78 if (std::ifstream::seekg(
static_cast<std::ifstream::pos_type
>(
static_cast<std::streamoff
>(position)), std::ifstream::beg).fail()) {
83 void skipg(ptrdiff_t offset)
override {
84 if (std::ifstream::seekg(
static_cast<std::ifstream::pos_type
>(
static_cast<std::streamoff
>(offset)), std::ifstream::cur).fail()) {
90 return readInto<Allocation<byte>>(maxLength);
94 return readInto<ArrayList<byte>>(maxLength);
98 return readInto<Buffer<byte>>(maxLength);
102 return readInto<String>(maxLength);
107 const size_t fileOffset =
tellg();
108 if (fileOffset < fileSize) {
109 const size_t length =
min(fileSize - fileOffset, maxLength);
125 const size_t size =
min(data.
size(),
size_t{Limits<std::streamsize>::MAX});
126 if (std::ifstream::read(
reinterpret_cast<char*
>(data.
data()),
static_cast<std::streamsize
>(
size)).bad()) {
129 const std::streamsize bytesRead = std::ifstream::gcount();
130 if (bytesRead <= 0) {
131 if (bytesRead < 0 || !std::ifstream::eof()) {
136 return static_cast<size_t>(bytesRead);
145 : std::ifstream(std::move(stream))
146 , fileSize(fileSize) {}
148 template <
typename Container>
149 [[nodiscard]] Container readInto(
size_t maxLength) {
151 const size_t fileOffset =
tellg();
152 if (fileOffset < fileSize) {
153 result.resize(
min(fileSize - fileOffset, maxLength));
Definition Allocation.hpp:25
constexpr void resize(size_type count)
Definition Allocation.hpp:273
constexpr pointer data() noexcept
Definition Allocation.hpp:425
Definition ArrayList.hpp:27
Wrapper over the native host filesystem.
Definition NativeFilesystem.hpp:21
constexpr size_type size() const noexcept
Definition Span.hpp:207
constexpr pointer data() const noexcept
Definition Span.hpp:203
auto asWritableBytes(Span< T, N > s) noexcept
Definition Span.hpp:368
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
GREM_ALWAYS_INLINE constexpr decltype(auto) min(A &&a, B &&b)
Get the smaller of two values, or the first value if they are equivalent.
Definition fundamentals.hpp:585
GREM_ALWAYS_INLINE constexpr T GREM_VECTORCALL length(T a)
Definition math.hpp:2001
Exception type for errors that may arise when attempting to access files through the File API.
Definition File.hpp:37
static constexpr T MAX
Definition fundamentals.hpp:29