4#ifndef GREM_CORE_SYSTEM_NATIVE_OUTPUT_FILE_HPP
5#define GREM_CORE_SYSTEM_NATIVE_OUTPUT_FILE_HPP
30 ,
public std::ofstream {
46 , std::ofstream(std::
move(static_cast<std::ofstream&>(other))) {}
55 std::ofstream::close();
58 [[nodiscard]]
bool isOpen() const noexcept
override {
59 return std::ofstream::is_open();
62 [[nodiscard]]
size_t tellp() const noexcept
override {
63 return static_cast<size_t>(
const_cast<std::ofstream*
>(
static_cast<const std::ofstream*
>(
this))->tellp());
66 void seekp(
size_t position)
override {
67 if (std::ofstream::seekp(
static_cast<std::ofstream::pos_type
>(
static_cast<std::streamoff
>(position)), std::ofstream::beg).fail()) {
72 void skipp(ptrdiff_t offset)
override {
73 if (std::ofstream::seekp(
static_cast<std::ofstream::pos_type
>(
static_cast<std::streamoff
>(offset)), std::ofstream::cur).fail()) {
79 const size_t size =
min(data.
size(),
size_t{Limits<std::streamsize>::MAX});
80 if (std::ofstream::write(
reinterpret_cast<const char*
>(data.
data()),
static_cast<std::streamsize
>(size)).fail()) {
87 if (std::ofstream::flush().fail()) {
96 : std::ofstream(std::move(stream)) {}
Wrapper over the native host filesystem.
Definition NativeFilesystem.hpp:21
NativeOutputFile & operator=(const NativeOutputFile &)=delete
Copying a file handle is not allowed.
size_t writeSome(Span< const byte > data) override
Write data to the end of an open file from a buffer.
Definition NativeOutputFile.hpp:78
NativeOutputFile() noexcept=default
Construct a closed file handle without an associated file.
bool isOpen() const noexcept override
Check if the file handle has an open file associated with it.
Definition NativeOutputFile.hpp:58
void flush() override
Synchronize with the underlying file to make sure that all buffered data that has been written so far...
Definition NativeOutputFile.hpp:86
NativeOutputFile & operator=(NativeOutputFile &&)=default
Move assignment.
size_t tellp() const noexcept override
Get the current writing position of the file.
Definition NativeOutputFile.hpp:62
void seekp(size_t position) override
Set the file writing position to an absolute offset from the beginning of the file.
Definition NativeOutputFile.hpp:66
void close() override
Close the associated file so that it can no longer be accessed through this handle,...
Definition NativeOutputFile.hpp:54
void skipp(ptrdiff_t offset) override
Advance the file writing position by a relative offset, which may be negative in order to go backward...
Definition NativeOutputFile.hpp:72
OutputFile() noexcept=default
Default constructor.
constexpr size_type size() const noexcept
Definition Span.hpp:207
constexpr pointer data() const noexcept
Definition Span.hpp:203
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
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
Exception type for errors that may arise when attempting to access files through the File API.
Definition File.hpp:37