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

Generic boxed unique handle to a writable file in any filesystem. More...

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

Public Member Functions

 OutputFileHandle () noexcept=default
 Construct a null file handle without an associated file.
GREM_ALWAYS_INLINE operator Writer () &
 Get a writer for the underlying file interface.
GREM_ALWAYS_INLINE OutputFile * get () noexcept
 Get a pointer to the underlying file interface.
GREM_ALWAYS_INLINE const OutputFile * get () const noexcept
 Get a pointer to the underlying file interface.
GREM_ALWAYS_INLINE operator OutputFile & ()
 Get a reference to the underlying file interface.
GREM_ALWAYS_INLINE operator const OutputFile & () const
 Get a reference to the underlying file interface.
GREM_ALWAYS_INLINE operator bool () const noexcept
 Check if the file handle has an open file associated with it.
GREM_ALWAYS_INLINE void close ()
 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.
GREM_ALWAYS_INLINE bool isOpen () const noexcept
 Check if the file handle has an open file associated with it.
GREM_ALWAYS_INLINE size_t tellp () const noexcept
 Get the current writing position of the file.
GREM_ALWAYS_INLINE void seekp (size_t position)
 Set the file writing position to an absolute offset from the beginning of the file.
GREM_ALWAYS_INLINE void skipp (ptrdiff_t offset)
 Advance the file writing position by a relative offset, which may be negative in order to go backwards.
GREM_ALWAYS_INLINE size_t writeSome (Span< const byte > data)
 Write data to the end of an open file from a buffer.
GREM_ALWAYS_INLINE void write (Span< const byte > data)
 Write data to the end of an open file.
GREM_ALWAYS_INLINE void write (StringView data)
 Write data to the end of an open file.
GREM_ALWAYS_INLINE void flush ()
 Synchronize with the underlying file to make sure that all buffered data that has been written so far is flushed into the actual file.

Static Public Member Functions

template<typename Implementation, typename... Args>
static GREM_ALWAYS_INLINE OutputFileHandle create (Args &&... args)
 Create a boxed file with a specific implementation.

Detailed Description

Generic boxed unique handle to a writable file in any filesystem.

Constructor & Destructor Documentation

◆ OutputFileHandle()

grem::OutputFileHandle::OutputFileHandle ( )
defaultnoexcept

Construct a null file handle without an associated file.

Member Function Documentation

◆ create()

template<typename Implementation, typename... Args>
GREM_ALWAYS_INLINE OutputFileHandle grem::OutputFileHandle::create ( Args &&... args)
inlinestaticnodiscard

Create a boxed file with a specific implementation.

Template Parameters
Implementationconcrete file type.
Parameters
argsarguments to forward to the concrete file constructor.
Returns
the new boxed file.
Exceptions
anyexception thrown by the concrete file's constructor.
std::bad_allocon allocation failure.

◆ operator Writer()

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

Get a writer for the underlying file interface.

Returns
a writer for the underlying file interface.
Warning
The file handle must not be null.

◆ get() [1/2]

GREM_ALWAYS_INLINE OutputFile * grem::OutputFileHandle::get ( )
inlinenodiscardnoexcept

Get a pointer to the underlying file interface.

Returns
a non-owning pointer to the underlying file interface.

◆ get() [2/2]

GREM_ALWAYS_INLINE const OutputFile * grem::OutputFileHandle::get ( ) const
inlinenodiscardnoexcept

Get a pointer to the underlying file interface.

Returns
a non-owning read-only pointer to the underlying file interface.

◆ operator OutputFile &()

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

Get a reference to the underlying file interface.

Returns
a reference to the underlying file interface.
Warning
The file handle must not be null.

◆ operator const OutputFile &()

GREM_ALWAYS_INLINE grem::OutputFileHandle::operator const OutputFile & ( ) const
inlinenodiscard

Get a reference to the underlying file interface.

Returns
a read-only reference to the underlying file interface.
Warning
The file handle must not be null.

◆ operator bool()

GREM_ALWAYS_INLINE grem::OutputFileHandle::operator bool ( ) const
inlineexplicitnoexcept

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

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

◆ close()

GREM_ALWAYS_INLINE void grem::OutputFileHandle::close ( )
inline

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.

◆ isOpen()

GREM_ALWAYS_INLINE bool grem::OutputFileHandle::isOpen ( ) const
inlinenodiscardnoexcept

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

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

◆ tellp()

GREM_ALWAYS_INLINE size_t grem::OutputFileHandle::tellp ( ) const
inlinenodiscardnoexcept

Get the current writing position of the file.

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

◆ seekp()

GREM_ALWAYS_INLINE void grem::OutputFileHandle::seekp ( size_t position)
inline

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.

◆ skipp()

GREM_ALWAYS_INLINE void grem::OutputFileHandle::skipp ( ptrdiff_t offset)
inline

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.

◆ writeSome()

GREM_ALWAYS_INLINE size_t grem::OutputFileHandle::writeSome ( Span< const byte > data)
inlinenodiscard

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.

◆ write() [1/2]

GREM_ALWAYS_INLINE void grem::OutputFileHandle::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]

GREM_ALWAYS_INLINE void grem::OutputFileHandle::write ( StringView 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.

◆ flush()

GREM_ALWAYS_INLINE void grem::OutputFileHandle::flush ( )
inline

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.

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