GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
VirtualOutputFile.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_OUTPUT_FILE_HPP
5#define GREM_APPLICATION_VIRTUAL_OUTPUT_FILE_HPP
6
8
18
19#ifdef GREM_USE_MULTITHREADING
21
22#include <utility> // std::move
23#endif
24
25namespace grem::application {
26
35class VirtualOutputFile final : public OutputFile {
36public:
40 VirtualOutputFile() 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) size_t tellp() const noexcept override;
49
50 GREM_API(application) void seekp(size_t position) override;
51 GREM_API(application) void skipp(ptrdiff_t offset) override;
52
53 [[nodiscard]] GREM_API(application) size_t writeSome(Span<const byte> data) override;
54 GREM_API(application) void flush() override;
55
56private:
57 friend VirtualFilesystem;
58
59#ifdef GREM_USE_MULTITHREADING
60 VirtualOutputFile(void* handle, VirtualFilesystem::FileLock lock) noexcept
61 : file(handle)
62 , lock(std::move(lock)) {}
63#else
64 explicit VirtualOutputFile(void* handle) noexcept
65 : file(handle) {}
66#endif
67
68 struct FileDeleter {
69 GREM_API(application) void operator()(void* handle) const noexcept;
70 };
71
72 UniqueHandle<void*, FileDeleter> file{};
73#ifdef GREM_USE_MULTITHREADING
74 VirtualFilesystem::FileLock lock{};
75#endif
76};
77
78} // namespace grem::application
79
80#endif
OutputFile() noexcept=default
Default constructor.
Definition Span.hpp:146
void skipp(ptrdiff_t offset) override
Advance the file writing position by a relative offset, which may be negative in order to go backward...
bool isOpen() const noexcept override
Check if the file handle has an open file associated with it.
Definition VirtualOutputFile.hpp:44
void seekp(size_t position) override
Set the file writing position to an absolute offset from the beginning of the file.
void flush() override
Synchronize with the underlying file to make sure that all buffered data that has been written so far...
VirtualOutputFile() noexcept=default
Construct a closed file handle without an associated file.
void close() override
Close the associated file so that it can no longer be accessed through this handle,...
size_t writeSome(Span< const byte > data) override
Write data to the end of an open file from a buffer.
size_t tellp() const noexcept override
Get the current writing position of the file.
Definition Application.hpp:18
GREM_ALWAYS_INLINE void lock(Lockable1 &lock1, Lockable2 &lock2, LockableN &... lockN)
Definition synchronization.hpp:1268