GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::OutputFile Class Referenceabstract

Base interface for a writable file in a Filesystem. More...

#include <GREM/core/system/File.hpp>

Inheritance diagram for grem::OutputFile:

Public Member Functions

 OutputFile () noexcept=default
 Default constructor.
GREM_ALWAYS_INLINE operator Writer () &
 Get a writer for the file.
virtual size_t tellp () const noexcept=0
 Get the current writing position of the file.
virtual void seekp (size_t position)=0
 Set the file writing position to an absolute offset from the beginning of the file.
virtual void skipp (ptrdiff_t offset)=0
 Advance the file writing position by a relative offset, which may be negative in order to go backwards.
virtual size_t writeSome (Span< const byte > data)=0
 Write data to the end of an open file from a buffer.
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.
virtual void flush ()=0
 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::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.
virtual void close ()=0
 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.
virtual bool isOpen () const noexcept=0
 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

Base interface for a writable file in a Filesystem.

Constructor & Destructor Documentation

◆ OutputFile()

grem::OutputFile::OutputFile ( )
defaultnoexcept

Default constructor.

Member Function Documentation

◆ operator Writer()

GREM_ALWAYS_INLINE grem::OutputFile::operator Writer ( ) &
inlinenodiscard

Get a writer for the file.

Returns
a writer for the file.

◆ tellp()

virtual size_t grem::OutputFile::tellp ( ) const
nodiscardpure virtualnoexcept

Get the current writing position of the file.

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

Implemented in grem::application::VirtualOutputFile, and grem::NativeOutputFile.

◆ seekp()

virtual void grem::OutputFile::seekp ( size_t position)
pure virtual

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.

Implemented in grem::application::VirtualOutputFile, and grem::NativeOutputFile.

◆ skipp()

virtual void grem::OutputFile::skipp ( ptrdiff_t offset)
pure virtual

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.

Implemented in grem::application::VirtualOutputFile, and grem::NativeOutputFile.

◆ writeSome()

virtual size_t grem::OutputFile::writeSome ( Span< const byte > data)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualOutputFile, and grem::NativeOutputFile.

◆ write() [1/2]

void grem::OutputFile::write ( Span< const byte > data)
inline

Write data to the end of an open file.

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

Parameters
datadata to write.
Exceptions
File::Erroron failure to write to the file, or if not all of the data was written.

◆ write() [2/2]

void grem::OutputFile::write ( StringView string)
inline

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

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

Parameters
stringstring containing the data to write.
Exceptions
File::Erroron failure to write to the file, or if not all of the data was written.

◆ flush()

virtual void grem::OutputFile::flush ( )
pure virtual

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.

Implemented in grem::application::VirtualOutputFile, and grem::NativeOutputFile.


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