GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::application::VirtualOutputFile Class Referencefinal

Unique handle to a writable file in the virtual Filesystem. More...

#include <GREM/application/VirtualOutputFile.hpp>

Inheritance diagram for grem::application::VirtualOutputFile:

Public Member Functions

 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, and reset the handle to 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.
size_t tellp () const noexcept override
 Get the current writing position of the file.
void seekp (size_t position) override
 Set the file writing position to an absolute offset from the beginning of the file.
void skipp (ptrdiff_t offset) override
 Advance the file writing position by a relative offset, which may be negative in order to go backwards.
size_t writeSome (Span< const byte > data) override
 Write data to the end of an open file from a buffer.
void flush () override
 Synchronize with the underlying file to make sure that all buffered data that has been written so far is flushed into the actual file.
Public Member Functions inherited from grem::OutputFile
 OutputFile () noexcept=default
 Default constructor.
GREM_ALWAYS_INLINE operator Writer () &
 Get a writer for the file.
void write (Span< const byte > data)
 Write data to the end of an open file.
void write (StringView string)
 Write data from a string to the end of an open file.
Public Member Functions inherited from grem::File
 File () noexcept=default
 Default constructor.
virtual ~File ()=default
 Virtual destructor.
 File (const File &)=default
 Copy constructor.
 File (File &&) noexcept=default
 Move constructor.
File & operator= (const File &)=default
 Copy assignment.
File & operator= (File &&) noexcept=default
 Move assignment.
 operator bool () const noexcept
 Check if the file handle has an open file associated with it.

Additional Inherited Members

Public Types inherited from grem::File
enum class  Kind : uint8_t { REGULAR , DIRECTORY , SYMLINK , OTHER }
 File entry type. More...
Static Public Attributes inherited from grem::File
static constexpr size_t npos = static_cast<size_t>(-1)
 Invalid value for a file offset, used as an end-of-file marker.

Detailed Description

Unique handle to a writable file in the virtual Filesystem.

Warning
This file handle type may only be used during the lifetime of a Filesystem object, which initializes the relevant global context upon construction. Attempting to use the File API without an active Filesystem yields undefined behavior.

Constructor & Destructor Documentation

◆ VirtualOutputFile()

grem::application::VirtualOutputFile::VirtualOutputFile ( )
defaultnoexcept

Construct a closed file handle without an associated file.

Member Function Documentation

◆ close()

void grem::application::VirtualOutputFile::close ( )
overridevirtual

Close the associated file so that it can no longer be accessed through this handle, and reset the handle to a closed file handle without an associated file.

Exceptions
File::Erroron failure to close the file.
std::bad_allocon allocation failure.
Note
This function has no effect if the handle has no open file associated with it.

Implements grem::File.

◆ isOpen()

bool grem::application::VirtualOutputFile::isOpen ( ) const
inlinenodiscardoverridevirtualnoexcept

Check if the file handle has an open file associated with it.

Returns
true if there is an associated open file, false otherwise.

Implements grem::File.

◆ tellp()

size_t grem::application::VirtualOutputFile::tellp ( ) const
nodiscardoverridevirtualnoexcept

Get the current writing position of the file.

Returns
the current file writing position, or File::npos if it cannot be determined.

Implements grem::OutputFile.

◆ seekp()

void grem::application::VirtualOutputFile::seekp ( size_t position)
overridevirtual

Set the file writing position to an absolute offset from the beginning of the file.

Parameters
positionthe new writing position to set.
Exceptions
File::Erroron failure to seek to the given position.
Note
Attempting to seek to a position outside the readable length of the file will cause the function to fail.

Implements grem::OutputFile.

◆ skipp()

void grem::application::VirtualOutputFile::skipp ( ptrdiff_t offset)
overridevirtual

Advance the file writing position by a relative offset, which may be negative in order to go backwards.

Parameters
offsetthe relative offset to advance the writing position by.
Exceptions
File::Erroron failure to skip by the given offset.
Note
Attempting to seek to a position outside the readable length of the file will cause the function to fail.

Implements grem::OutputFile.

◆ writeSome()

size_t grem::application::VirtualOutputFile::writeSome ( Span< const byte > data)
nodiscardoverridevirtual

Write data to the end of an open file from a buffer.

The writing position is advanced to the new end of the file.

Parameters
dataread-only view over the buffer to copy the data from. The size of the buffer determines the number of bytes that are attempted to be written.
Returns
the number of bytes that were successfully written, which may be any non-negative integer less than or equal to the size of the given view, including 0.
Exceptions
File::Erroron failure to write to the file.

Implements grem::OutputFile.

◆ flush()

void grem::application::VirtualOutputFile::flush ( )
overridevirtual

Synchronize with the underlying file to make sure that all buffered data that has been written so far is flushed into the actual file.

Exceptions
File::Erroron failure to synchronize with the file.

Implements grem::OutputFile.


The documentation for this class was generated from the following file: