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

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

#include <GREM/application/VirtualInputFile.hpp>

Inheritance diagram for grem::application::VirtualInputFile:

Public Member Functions

 VirtualInputFile () 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.
bool eof () const noexcept override
 Check if the end of the file has been reached.
size_t size () const noexcept override
 Get the readable length of the full file contents, in bytes.
size_t tellg () const noexcept override
 Get the current reading position of the file.
void seekg (size_t position) override
 Set the file reading position to an absolute offset from the beginning of the file.
void skipg (ptrdiff_t offset) override
 Advance the file reading position by a relative offset, which may be negative in order to go backwards.
Allocation< byte > readBytesIntoAllocation (size_t maxLength=Limits< size_t >::MAX) override
 Read from an open file into an allocation of bytes.
ArrayList< byte > readBytesIntoArrayList (size_t maxLength=Limits< size_t >::MAX) override
 Read from an open file into an array list of bytes.
Buffer< byte > readBytesIntoBuffer (size_t maxLength=Limits< size_t >::MAX) override
 Read from an open file into a buffer of bytes.
String readBytesIntoString (size_t maxLength=Limits< size_t >::MAX) override
 Read from an open file into a string of bytes.
Allocation< char > readBytesIntoCString (size_t maxLength=Limits< size_t >::MAX) override
 Read from an open file into an allocated null-terminated string of bytes.
size_t readSome (Span< byte > data) override
 Read some amount of data from an open file, starting at the current reading position.
size_t readUntilEOF (Span< byte > data) override
 Read data from an open file into a buffer, starting at the current reading position.
Public Member Functions inherited from grem::InputFile
 InputFile () noexcept=default
 Default constructor.
GREM_ALWAYS_INLINE operator Reader () &
 Get a reader for the file.
void read (Span< byte > data)
 Read an exact amount of data from an open file, starting at the current reading position.
bool tryRead (Span< byte > data)
 Try to read an exact amount of data from an open file, starting at the current reading position.
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 readable 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

◆ VirtualInputFile()

grem::application::VirtualInputFile::VirtualInputFile ( )
defaultnoexcept

Construct a closed file handle without an associated file.

Member Function Documentation

◆ close()

void grem::application::VirtualInputFile::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::VirtualInputFile::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.

◆ eof()

bool grem::application::VirtualInputFile::eof ( ) const
nodiscardoverridevirtualnoexcept

Check if the end of the file has been reached.

Returns
true if the end of the file has been reached, false otherwise.

Implements grem::InputFile.

◆ size()

size_t grem::application::VirtualInputFile::size ( ) const
nodiscardoverridevirtualnoexcept

Get the readable length of the full file contents, in bytes.

Returns
the length of the file, or File::npos if the length cannot be determined.

Implements grem::InputFile.

◆ tellg()

size_t grem::application::VirtualInputFile::tellg ( ) const
nodiscardoverridevirtualnoexcept

Get the current reading position of the file.

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

Implements grem::InputFile.

◆ seekg()

void grem::application::VirtualInputFile::seekg ( size_t position)
overridevirtual

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

Parameters
positionthe new reading 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::InputFile.

◆ skipg()

void grem::application::VirtualInputFile::skipg ( ptrdiff_t offset)
overridevirtual

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

Parameters
offsetthe relative offset to advance the reading 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::InputFile.

◆ readBytesIntoAllocation()

Allocation< byte > grem::application::VirtualInputFile::readBytesIntoAllocation ( size_t maxLength = Limits< size_t >::MAX)
nodiscardoverridevirtual

Read from an open file into an allocation of bytes.

Parameters
maxLengthmaximum number of bytes to read.
Returns
an allocation containing the file contents read from the current read position until the end of the file, or until maxLength bytes, whichever comes first.
Exceptions
File::Erroron failure to read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.

Implements grem::InputFile.

◆ readBytesIntoArrayList()

ArrayList< byte > grem::application::VirtualInputFile::readBytesIntoArrayList ( size_t maxLength = Limits< size_t >::MAX)
nodiscardoverridevirtual

Read from an open file into an array list of bytes.

Parameters
maxLengthmaximum number of bytes to read.
Returns
an array list of the file contents read from the current read position until the end of the file, or until maxLength bytes, whichever comes first.
Exceptions
File::Erroron failure to read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.

Implements grem::InputFile.

◆ readBytesIntoBuffer()

Buffer< byte > grem::application::VirtualInputFile::readBytesIntoBuffer ( size_t maxLength = Limits< size_t >::MAX)
nodiscardoverridevirtual

Read from an open file into a buffer of bytes.

Parameters
maxLengthmaximum number of bytes to read.
Returns
a buffer of the file contents read from the current read position until the end of the file, or until maxLength bytes, whichever comes first.
Exceptions
File::Erroron failure to read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.

Implements grem::InputFile.

◆ readBytesIntoString()

String grem::application::VirtualInputFile::readBytesIntoString ( size_t maxLength = Limits< size_t >::MAX)
nodiscardoverridevirtual

Read from an open file into a string of bytes.

Parameters
maxLengthmaximum number of bytes to read.
Returns
a string of the file contents read from the current read position until the end of the file, or until maxLength bytes, whichever comes first.
Exceptions
File::Erroron failure to read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.

Implements grem::InputFile.

◆ readBytesIntoCString()

Allocation< char > grem::application::VirtualInputFile::readBytesIntoCString ( size_t maxLength = Limits< size_t >::MAX)
nodiscardoverridevirtual

Read from an open file into an allocated null-terminated string of bytes.

Parameters
maxLengthmaximum number of bytes to read.
Returns
an allocated null-terminated string of the file contents read from the current read position until the end of the file, or until maxLength bytes, whichever comes first.
Exceptions
File::Erroron failure to read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.

Implements grem::InputFile.

◆ readSome()

size_t grem::application::VirtualInputFile::readSome ( Span< byte > data)
nodiscardoverridevirtual

Read some amount of data from an open file, starting at the current reading position.

The reading position is advanced to the end of the bytes that were read.

Parameters
datawritable span over the buffer to read file data into. The size of the span determines the number of bytes that are attempted to be read.
Returns
the number of bytes that were read, which may be any non-negative integer less than or equal to the size of the given span, including 0 if the reading position was already at the end of the file, though always a positive value otherwise.
Note
The number of bytes read could be smaller than requested, even if more bytes are available. To read as many bytes as possible, use readUntilEOF() instead.
Exceptions
File::Erroron failure to read from the file.
See also
readUntilEOF()
read()
tryRead()

Implements grem::InputFile.

◆ readUntilEOF()

size_t grem::application::VirtualInputFile::readUntilEOF ( Span< byte > data)
nodiscardoverridevirtual

Read data from an open file into a buffer, starting at the current reading position.

The reading position is advanced to the end of the bytes that were read.

Parameters
datawritable span over the buffer to read file data into. The size of the span determines the number of bytes that are attempted to be read.
Returns
the number of bytes that were successfully read, i.e. data.size() or (fileSize - previousReadingPosition), whichever is smaller. This includes 0 if and only if the reading position was already at the end of the file.
Note
If the end of the file is reached before the entire span's worth of data could be read, this will be reflected in the returned number of read bytes. To make sure all requested data was read, use read() instead.
Exceptions
File::Erroron failure to read from the file.
See also
readSome()
read()
tryRead()

Implements grem::InputFile.


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