31 struct Error : std::runtime_error {
32 explicit Error(
const std::string& message)
33 : std::runtime_error(message) {}
35 explicit Error(
const char* message)
36 : std::runtime_error(message) {}
42 enum class Kind : std::uint8_t {
64 static constexpr std::size_t
NPOS =
static_cast<std::size_t
>(-1);
69 constexpr
File() noexcept = default;
76 constexpr explicit operator
bool() const noexcept {
100 [[nodiscard]] constexpr
bool isOpen() const noexcept {
101 return static_cast<bool>(file);
109 [[nodiscard]]
bool eof() const noexcept;
117 [[nodiscard]] std::
size_t size() const noexcept;
125 [[nodiscard]] std::
size_t tellg() const noexcept;
133 [[nodiscard]] std::
size_t tellp() const noexcept;
196 [[nodiscard]] std::vector<std::
byte>
readAll() &&;
228 [[nodiscard]] std::
size_t read(std::span<std::
byte> data);
245 std::
size_t write(std::span<const std::
byte> data);
258 constexpr explicit
File(
void* handle) noexcept
262 void operator()(
void* handle)
const noexcept;
265 UniqueHandle<void*, FileDeleter> file{};
Unique handle to a file in the virtual Filesystem.
Definition: File.hpp:25
std::size_t tellp() const noexcept
Get the current writing position of the file.
std::size_t write(std::span< const std::byte > data)
Write data to the end of an open file from a buffer.
std::size_t read(std::span< std::byte > data)
Read data from an open file into a buffer, starting at the current reading position.
std::vector< std::byte > readAll() &&
Read the full contents of an open file into an array of bytes.
bool eof() const noexcept
Check if the end of the file has been reached.
std::size_t tellg() const noexcept
Get the current reading position of the file.
constexpr File() noexcept=default
Construct a closed virtual file handle without an associated file.
static constexpr std::size_t NPOS
Invalid value for a file offset, used as an end-of-file marker.
Definition: File.hpp:64
std::size_t size() const noexcept
Get the readable length of the full file contents, in bytes.
void seekg(std::size_t position)
Set the file reading position to an absolute offset from the beginning of the file.
void skipg(std::ptrdiff_t offset)
Advance the file reading position by a relative offset, which may be negative in order to go backward...
void seekp(std::size_t position)
Set the file writing position to an absolute offset from the beginning of the file.
std::string readAllIntoString() &&
Read the full contents of an open file into a string of bytes.
void flush()
Synchronize with the underlying file to make sure that all buffered data that has been written so far...
void close()
Close the associated file so that it can no longer be accessed through this handle,...
Kind
Virtual file entry type.
Definition: File.hpp:42
@ OTHER
Something else, such as a network socket or a device.
@ DIRECTORY
Directory/folder.
void skipp(std::ptrdiff_t offset)
Advance the file writing position by a relative offset, which may be negative in order to go backward...
constexpr bool isOpen() const noexcept
Check if the file handle has an open file associated with it.
Definition: File.hpp:100
Persistent system for managing the virtual filesystem.
Definition: Filesystem.hpp:185
Definition: Application.hpp:9
Exception type for errors that may arise when attempting to access files through the virtual File API...
Definition: File.hpp:31
Error(const char *message)
Definition: File.hpp:35
Error(const std::string &message)
Definition: File.hpp:32