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

Base interface for a readable File in a Filesystem. More...

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

Inheritance diagram for grem::InputFile:

Public Member Functions

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

Constructor & Destructor Documentation

◆ InputFile()

grem::InputFile::InputFile ( )
defaultnoexcept

Default constructor.

Member Function Documentation

◆ operator Reader()

GREM_ALWAYS_INLINE grem::InputFile::operator Reader ( ) &
inlinenodiscard

Get a reader for the file.

Returns
a reader for the file.

◆ eof()

virtual bool grem::InputFile::eof ( ) const
nodiscardpure virtualnoexcept

Check if the end of the file has been reached.

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

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ size()

virtual size_t grem::InputFile::size ( ) const
nodiscardpure virtualnoexcept

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ tellg()

virtual size_t grem::InputFile::tellg ( ) const
nodiscardpure virtualnoexcept

Get the current reading position of the file.

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

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ seekg()

virtual void grem::InputFile::seekg ( size_t position)
pure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ skipg()

virtual void grem::InputFile::skipg ( ptrdiff_t offset)
pure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readBytesIntoAllocation()

virtual Allocation< byte > grem::InputFile::readBytesIntoAllocation ( size_t maxLength = Limits< size_t >::MAX)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readBytesIntoArrayList()

virtual ArrayList< byte > grem::InputFile::readBytesIntoArrayList ( size_t maxLength = Limits< size_t >::MAX)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readBytesIntoBuffer()

virtual Buffer< byte > grem::InputFile::readBytesIntoBuffer ( size_t maxLength = Limits< size_t >::MAX)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readBytesIntoString()

virtual String grem::InputFile::readBytesIntoString ( size_t maxLength = Limits< size_t >::MAX)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readBytesIntoCString()

virtual Allocation< char > grem::InputFile::readBytesIntoCString ( size_t maxLength = Limits< size_t >::MAX)
nodiscardpure virtual

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.

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readSome()

virtual size_t grem::InputFile::readSome ( Span< byte > data)
nodiscardpure virtual

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()

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ readUntilEOF()

virtual size_t grem::InputFile::readUntilEOF ( Span< byte > data)
nodiscardpure virtual

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()

Implemented in grem::application::VirtualInputFile, and grem::NativeInputFile.

◆ read()

void grem::InputFile::read ( Span< byte > data)
inline

Read an exact 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 to read file data into. The size of the span determines the number of bytes that are read.
Exceptions
File::Erroron failure to read from the file, or if not all requested data was read.
See also
readUntilEOF()
tryRead()

◆ tryRead()

bool grem::InputFile::tryRead ( Span< byte > data)
inlinenodiscard

Try to read an exact 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 to read file data into. The size of the span determines the number of bytes that are attempted to be read.
Returns
true if all bytes were successfully read without hitting the end of the file, false if the end of the file was reached before all data could be read.
Exceptions
File::Erroron failure to read from the file.
See also
readUntilEOF()
read()

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