GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
VirtualInputFile.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Ivar Härnqvist
2// SPDX-License-Identifier: MIT
3
4#ifndef GREM_APPLICATION_VIRTUAL_INPUT_FILE_HPP
5#define GREM_APPLICATION_VIRTUAL_INPUT_FILE_HPP
6
8
18
19#ifdef GREM_USE_MULTITHREADING
21
22#include <utility> // std::move
23#endif
24
25namespace grem::application {
26
35class VirtualInputFile final : public InputFile {
36public:
40 VirtualInputFile() noexcept = default;
41
42 GREM_API(application) void close() override;
43
44 [[nodiscard]] bool isOpen() const noexcept override {
45 return static_cast<bool>(file);
46 }
47
48 [[nodiscard]] GREM_API(application) bool eof() const noexcept override;
49 [[nodiscard]] GREM_API(application) size_t size() const noexcept override;
50
51 [[nodiscard]] GREM_API(application) size_t tellg() const noexcept override;
52
53 GREM_API(application) void seekg(size_t position) override;
54
55 GREM_API(application) void skipg(ptrdiff_t offset) override;
56
57 [[nodiscard]] GREM_API(application) Allocation<byte> readBytesIntoAllocation(size_t maxLength = Limits<size_t>::MAX) override;
58 [[nodiscard]] GREM_API(application) ArrayList<byte> readBytesIntoArrayList(size_t maxLength = Limits<size_t>::MAX) override;
59 [[nodiscard]] GREM_API(application) Buffer<byte> readBytesIntoBuffer(size_t maxLength = Limits<size_t>::MAX) override;
60 [[nodiscard]] GREM_API(application) String readBytesIntoString(size_t maxLength = Limits<size_t>::MAX) override;
61 [[nodiscard]] GREM_API(application) Allocation<char> readBytesIntoCString(size_t maxLength = Limits<size_t>::MAX) override;
62
63 [[nodiscard]] GREM_API(application) size_t readSome(Span<byte> data) override;
64 [[nodiscard]] GREM_API(application) size_t readUntilEOF(Span<byte> data) override;
65
66private:
67 friend VirtualFilesystem;
68
69#ifdef GREM_USE_MULTITHREADING
70 VirtualInputFile(void* handle, VirtualFilesystem::FileLock lock) noexcept
71 : file(handle)
72 , lock(std::move(lock)) {}
73#else
74 explicit VirtualInputFile(void* handle) noexcept
75 : file(handle) {}
76#endif
77
78 struct FileDeleter {
79 GREM_API(application) void operator()(void* handle) const noexcept;
80 };
81
82 UniqueHandle<void*, FileDeleter> file{};
83#ifdef GREM_USE_MULTITHREADING
84 VirtualFilesystem::FileLock lock{};
85#endif
86};
87
88} // namespace grem::application
89
90#endif
Definition Allocation.hpp:25
Definition ArrayList.hpp:27
Definition Buffer.hpp:28
InputFile() noexcept=default
Default constructor.
Definition Span.hpp:146
ArrayList< byte > readBytesIntoArrayList(size_t maxLength=Limits< size_t >::MAX) override
Read from an open file into an array list of bytes.
size_t tellg() const noexcept override
Get the current reading position of the file.
size_t readUntilEOF(Span< byte > data) override
Read data from an open file into a buffer, starting at the current reading position.
void seekg(size_t position) override
Set the file reading position to an absolute offset from the beginning of the file.
bool isOpen() const noexcept override
Check if the file handle has an open file associated with it.
Definition VirtualInputFile.hpp:44
size_t size() const noexcept override
Get the readable length of the full file contents, in bytes.
Allocation< char > readBytesIntoCString(size_t maxLength=Limits< size_t >::MAX) override
Read from an open file into an allocated null-terminated string of bytes.
Allocation< byte > readBytesIntoAllocation(size_t maxLength=Limits< size_t >::MAX) override
Read from an open file into an allocation of bytes.
bool eof() const noexcept override
Check if the end of the file has been reached.
String readBytesIntoString(size_t maxLength=Limits< size_t >::MAX) override
Read from an open file into a string of bytes.
void skipg(ptrdiff_t offset) override
Advance the file reading position by a relative offset, which may be negative in order to go backward...
VirtualInputFile() noexcept=default
Construct a closed file handle without an associated file.
size_t readSome(Span< byte > data) override
Read some amount of data from an open file, starting at the current reading position.
Buffer< byte > readBytesIntoBuffer(size_t maxLength=Limits< size_t >::MAX) override
Read from an open file into a buffer of bytes.
void close() override
Close the associated file so that it can no longer be accessed through this handle,...
Definition Application.hpp:18
GREM_ALWAYS_INLINE void lock(Lockable1 &lock1, Lockable2 &lock2, LockableN &... lockN)
Definition synchronization.hpp:1268
StringBase< char, std::char_traits< char >, std::allocator< char > > String
Definition String.hpp:17
Definition fundamentals.hpp:27