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

Base interface for a filesystem. More...

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

Inheritance diagram for grem::Filesystem:

Public Member Functions

constexpr Filesystem () noexcept=default
 Default constructor.
virtual ~Filesystem ()=default
 Virtual destructor.
constexpr Filesystem (const Filesystem &)=default
 Copy constructor.
constexpr Filesystem (Filesystem &&) noexcept=default
 Move constructor.
Filesystem & operator= (const Filesystem &)=default
 Copy assignment.
Filesystem & operator= (Filesystem &&) noexcept=default
 Move assignment.
virtual CStringView getOutputDirectory () const noexcept=0
 Get the current output directory of the filesystem.
virtual CStringView findInputArchiveOfFile (CStringView filepath) const noexcept=0
 Get the host filepath of the mounted input archive on the host filesystem that contains a given virtual file.
virtual void createOutputDirectory (CStringView filepath)=0
 Create a new host directory relative to the current output directory, while also creating any missing parent directories along the way as needed.
virtual void createParentOutputDirectories (CStringView filepath)=0
 Create any missing parent directories above a host directory relative to the current output directory.
virtual void deleteOutputFile (CStringView filepath)=0
 Delete a host file or directory relative to the current output directory.
virtual bool inputFileExists (CStringView filepath) const =0
 Check if a given virtual filepath has a corresponding host file mounted.
virtual File::Metadata getFileMetadata (CStringView filepath) const =0
 Get the metadata of a file that is mounted at a given virtual filepath.
virtual void forEachInputFilenameInDirectory (CStringView filepath, FunctionView< bool(CStringView filename)> callback) const =0
 Iterate the filenames of all readable virtual filepaths that are direct children of a given directory.
void forEachInputFilenameInDirectory (CStringView filepath, auto callback) const
 Iterate the filenames of all readable virtual filepaths that are direct children of a given directory.
virtual InputFileHandle openInputFile (CStringView filepath) const =0
 Open an input file in the virtual filesystem for reading.
virtual InputFileHandle tryOpenInputFile (CStringView filepath) const =0
 Try to open an input file in the virtual filesystem for reading.
Allocation< byte > readInputFile (CStringView filepath) const
 Open an input file in the virtual filesystem for reading and read its full contents into an array of bytes.
Optional< Allocation< byte > > tryReadInputFile (CStringView filepath) const
 Try to open an input file in the virtual filesystem for reading and read its full contents into an array of bytes.
ArrayList< byte > readInputFileArrayList (CStringView filepath) const
 Open an input file in the virtual filesystem for reading and read its full contents into an array list of bytes.
Optional< ArrayList< byte > > tryReadInputFileArrayList (CStringView filepath) const
 Try to open an input file in the virtual filesystem for reading and read its full contents into an array list of bytes.
Buffer< byte > readInputFileBuffer (CStringView filepath) const
 Open an input file in the virtual filesystem for reading and read its full contents into a buffer of bytes.
Optional< Buffer< byte > > tryReadInputFileBuffer (CStringView filepath) const
 Try to open an input file in the virtual filesystem for reading and read its full contents into a buffer of bytes.
String readInputFileString (CStringView filepath) const
 Open an input file in the virtual filesystem for reading and read its full contents into a string of bytes.
Optional< String > tryReadInputFileString (CStringView filepath) const
 Try to open an input file in the virtual filesystem for reading and read its full contents into a string of bytes.
Allocation< char > readInputFileCString (CStringView filepath) const
 Open an input file in the virtual filesystem for reading and read its full contents into an allocated null-terminated string of bytes.
Allocation< char > tryReadInputFileCString (CStringView filepath) const
 Try to open an input file in the virtual filesystem for reading and read its full contents into an allocated null-terminated string of bytes.
virtual OutputFileHandle openEmptyOutputFile (CStringView filepath)=0
 Create a file relative to the current output directory and open it for writing, overwriting any existing file at the same filepath.
virtual void createEmptyOutputFile (CStringView filepath)=0
 Create an empty file relative to the current output directory, overwriting any existing file at the same filepath.
virtual OutputFileHandle openOutputFileForAppending (CStringView filepath)=0
 Open a file relative to the current output directory for appended writing, or create an empty file and open it if one didn't already exist.

Detailed Description

Base interface for a filesystem.

Constructor & Destructor Documentation

◆ Filesystem() [1/3]

grem::Filesystem::Filesystem ( )
constexprdefaultnoexcept

Default constructor.

◆ ~Filesystem()

virtual grem::Filesystem::~Filesystem ( )
virtualdefault

Virtual destructor.

◆ Filesystem() [2/3]

grem::Filesystem::Filesystem ( const Filesystem & )
constexprdefault

Copy constructor.

◆ Filesystem() [3/3]

grem::Filesystem::Filesystem ( Filesystem && )
constexprdefaultnoexcept

Move constructor.

Member Function Documentation

◆ operator=() [1/2]

Filesystem & grem::Filesystem::operator= ( const Filesystem & )
default

Copy assignment.

◆ operator=() [2/2]

Filesystem & grem::Filesystem::operator= ( Filesystem && )
defaultnoexcept

Move assignment.

◆ getOutputDirectory()

virtual CStringView grem::Filesystem::getOutputDirectory ( ) const
nodiscardpure virtualnoexcept

Get the current output directory of the filesystem.

Returns
the host filepath corresponding to the current output directory, or an empty string if no output directory is currently set.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ findInputArchiveOfFile()

virtual CStringView grem::Filesystem::findInputArchiveOfFile ( CStringView filepath) const
nodiscardpure virtualnoexcept

Get the host filepath of the mounted input archive on the host filesystem that contains a given virtual file.

Parameters
filepathvirtual filepath of the file to get the archive of.
Returns
the host filepath of the directory or archive that was previously passed to mountInputArchive(), in which the corresponding virtual file was found, or an empty string if the virtual file was not found at any active mount point.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ createOutputDirectory()

virtual void grem::Filesystem::createOutputDirectory ( CStringView filepath)
pure virtual

Create a new host directory relative to the current output directory, while also creating any missing parent directories along the way as needed.

Parameters
filepathvirtual filepath, relative to the current output directory, of the new directory to be created.
Exceptions
File::Erroron failure to create the directories.
std::bad_allocon allocation failure.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ createParentOutputDirectories()

virtual void grem::Filesystem::createParentOutputDirectories ( CStringView filepath)
pure virtual

Create any missing parent directories above a host directory relative to the current output directory.

Parameters
filepathvirtual filepath, relative to the current output directory, of the directory whose missing parent directories to create.
Exceptions
File::Erroron failure to create the directories.
std::bad_allocon allocation failure.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ deleteOutputFile()

virtual void grem::Filesystem::deleteOutputFile ( CStringView filepath)
pure virtual

Delete a host file or directory relative to the current output directory.

Parameters
filepathvirtual filepath, relative to the current output directory, of the file or directory to delete.
Exceptions
File::Erroron failure to delete the given file or directory.
std::bad_allocon allocation failure.
Warning
If successful, this will delete the actual file that corresponds to the given virtual filepath on the host filesystem; not just the virtual file entry.
Although deleting a file will prevent it from being read again through conventional means, the physical data that was contained in the file may or may not remain untouched on disk, meaning that this function cannot be relied upon to securly erase sensitive data.
Note
Directories must be empty before they can be successfully deleted using this function.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ inputFileExists()

virtual bool grem::Filesystem::inputFileExists ( CStringView filepath) const
nodiscardpure virtual

Check if a given virtual filepath has a corresponding host file mounted.

Parameters
filepathvirtual filepath to check for a mounted file.
Returns
true if a file is mounted at the given filepath, false otherwise.
See also
getFileMetadata()
forEachInputFilenameInDirectory()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ getFileMetadata()

virtual File::Metadata grem::Filesystem::getFileMetadata ( CStringView filepath) const
nodiscardpure virtual

Get the metadata of a file that is mounted at a given virtual filepath.

Parameters
filepathvirtual filepath of the file to get the metadata of.
Returns
the file metadata, see File::Metadata.
Exceptions
File::Erroron failure to get the metadata, such as if no file is mounted at the given filepath.
std::bad_allocon allocation failure.

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ forEachInputFilenameInDirectory() [1/2]

virtual void grem::Filesystem::forEachInputFilenameInDirectory ( CStringView filepath,
FunctionView< bool(CStringView filename)> callback ) const
pure virtual

Iterate the filenames of all readable virtual filepaths that are direct children of a given directory.

Parameters
filepathvirtual filepath of the input directory to enumerate.
callbackfunction to execute for each file, which should accept the current filename as a parameter and return a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Exceptions
File::Erroron failure to enumerate the directory.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
This function is not recursive, and only yields the filename component of the direct descendants of the given directory, without the leading directory path. The full virtual filepath of each filepath can be constructed using formatString("{}/{}", filepath, filename), where filepath is the directory filepath that was passed to the function, and filename is the current filename. Note that this path may refer to any kind of file, including a subdirectory. Use getFileMetadata() to find out which kind of file it refers to.
See also
inputFileExists()
getFileMetadata()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ forEachInputFilenameInDirectory() [2/2]

void grem::Filesystem::forEachInputFilenameInDirectory ( CStringView filepath,
auto callback ) const
inline

Iterate the filenames of all readable virtual filepaths that are direct children of a given directory.

Parameters
filepathvirtual filepath of the input directory to enumerate.
callbackfunction to execute for each file, which should accept the current filename as a parameter.
Exceptions
File::Erroron failure to enumerate the directory.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
This function is not recursive, and only yields the filename component of the direct descendants of the given directory, without the leading directory path. The full virtual filepath of each filepath can be constructed using formatString("{}/{}", filepath, filename), where filepath is the directory filepath that was passed to the function, and filename is the current filename. Note that this path may refer to any kind of file, including a subdirectory. Use getFileMetadata() to find out which kind of file it refers to.
See also
inputFileExists()
getFileMetadata()

◆ openInputFile()

virtual InputFileHandle grem::Filesystem::openInputFile ( CStringView filepath) const
nodiscardpure virtual

Open an input file in the virtual filesystem for reading.

Parameters
filepathvirtual filepath of the mounted input file to open.
Returns
a new file handle with an input stream set up to read the opened file starting at file position 0.
Exceptions
File::Erroron failure to open the file for reading.
std::bad_allocon allocation failure.
See also
tryOpenInputFile()
openEmptyOutputFile()
openOutputFileForAppending()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ tryOpenInputFile()

virtual InputFileHandle grem::Filesystem::tryOpenInputFile ( CStringView filepath) const
nodiscardpure virtual

Try to open an input file in the virtual filesystem for reading.

Parameters
filepathvirtual filepath of the mounted input file to open.
Returns
a new file handle with an input stream set up to read the opened file starting at file position 0, or a closed file handle if the file could not be opened.
Exceptions
std::bad_allocon allocation failure.
See also
openInputFile()
openEmptyOutputFile()
openOutputFileForAppending()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ readInputFile()

Allocation< byte > grem::Filesystem::readInputFile ( CStringView filepath) const
inlinenodiscard

Open an input file in the virtual filesystem for reading and read its full contents into an array of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an array containing a copy of the full contents of the file.
Exceptions
File::Erroron failure to open the file for reading or read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
openInputFile()
tryReadInputFile()

◆ tryReadInputFile()

Optional< Allocation< byte > > grem::Filesystem::tryReadInputFile ( CStringView filepath) const
inlinenodiscard

Try to open an input file in the virtual filesystem for reading and read its full contents into an array of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an array containing a copy of the full contents of the file, or an empty optional if the file could not be opened.
Exceptions
File::Erroron failure to read the opened file's contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
readInputFile()

◆ readInputFileArrayList()

ArrayList< byte > grem::Filesystem::readInputFileArrayList ( CStringView filepath) const
inlinenodiscard

Open an input file in the virtual filesystem for reading and read its full contents into an array list of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an array list containing a copy of the full contents of the file.
Exceptions
File::Erroron failure to open the file for reading or read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
openInputFile()
tryReadInputFileArrayList()

◆ tryReadInputFileArrayList()

Optional< ArrayList< byte > > grem::Filesystem::tryReadInputFileArrayList ( CStringView filepath) const
inlinenodiscard

Try to open an input file in the virtual filesystem for reading and read its full contents into an array list of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an array list containing a copy of the full contents of the file, or an empty optional if the file could not be opened.
Exceptions
File::Erroron failure to read the opened file's contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
readInputFileArrayList()

◆ readInputFileBuffer()

Buffer< byte > grem::Filesystem::readInputFileBuffer ( CStringView filepath) const
inlinenodiscard

Open an input file in the virtual filesystem for reading and read its full contents into a buffer of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
a buffer containing a copy of the full contents of the file.
Exceptions
File::Erroron failure to open the file for reading or read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
openInputFile()
tryReadInputFileBuffer()

◆ tryReadInputFileBuffer()

Optional< Buffer< byte > > grem::Filesystem::tryReadInputFileBuffer ( CStringView filepath) const
inlinenodiscard

Try to open an input file in the virtual filesystem for reading and read its full contents into a buffer of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
a buffer containing a copy of the full contents of the file, or an empty optional if the file could not be opened.
Exceptions
File::Erroron failure to read the opened file's contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
readInputFileBuffer()

◆ readInputFileString()

String grem::Filesystem::readInputFileString ( CStringView filepath) const
inlinenodiscard

Open an input file in the virtual filesystem for reading and read its full contents into a string of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
a string containing a copy of the full contents of the file.
Exceptions
File::Erroron failure to open the file for reading or read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
openInputFile()
tryReadInputFileString()

◆ tryReadInputFileString()

Optional< String > grem::Filesystem::tryReadInputFileString ( CStringView filepath) const
inlinenodiscard

Try to open an input file in the virtual filesystem for reading and read its full contents into a string of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
a string containing a copy of the full contents of the file, or an empty optional if the file could not be opened.
Exceptions
File::Erroron failure to read the opened file's contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
readInputFileString()

◆ readInputFileCString()

Allocation< char > grem::Filesystem::readInputFileCString ( CStringView filepath) const
inlinenodiscard

Open an input file in the virtual filesystem for reading and read its full contents into an allocated null-terminated string of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an allocated null-terminated string containing a copy of the full contents of the file.
Exceptions
File::Erroron failure to open the file for reading or read the file contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
openInputFile()
tryReadInputFileCString()

◆ tryReadInputFileCString()

Allocation< char > grem::Filesystem::tryReadInputFileCString ( CStringView filepath) const
inlinenodiscard

Try to open an input file in the virtual filesystem for reading and read its full contents into an allocated null-terminated string of bytes.

Parameters
filepathvirtual filepath of the mounted input file to read.
Returns
an allocated null-terminated string containing a copy of the full contents of the file, or nullptr if the file could not be opened.
Exceptions
File::Erroron failure to read the opened file's contents.
std::length_errorif the maximum file size was exceeded.
std::bad_allocon allocation failure.
See also
readInputFileCString()

◆ openEmptyOutputFile()

virtual OutputFileHandle grem::Filesystem::openEmptyOutputFile ( CStringView filepath)
nodiscardpure virtual

Create a file relative to the current output directory and open it for writing, overwriting any existing file at the same filepath.

Parameters
filepathvirtual filepath of the new file to be created, relative to the current output directory.
Returns
a new file handle with an output stream set up to write to the new empty file that was opened.
Exceptions
File::Erroron failure to delete the existing file, create the new file, or open the new file for writing.
std::bad_allocon allocation failure.
Warning
If successful, any existing host file that corresponds to the given virtual filepath in the output directory on the host filesystem will be deleted on the host filesystem; not just its virtual file entry. All modifications made through the virtual file handle will also be reflected in the physical file on the host file system.
See also
openInputFile()
createEmptyOutputFile()
openOutputFileForAppending()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ createEmptyOutputFile()

virtual void grem::Filesystem::createEmptyOutputFile ( CStringView filepath)
pure virtual

Create an empty file relative to the current output directory, overwriting any existing file at the same filepath.

Parameters
filepathvirtual filepath of the new file to be created, relative to the current output directory.
Exceptions
File::Erroron failure to delete the existing file or create the new file.
std::bad_allocon allocation failure.
Warning
If successful, any existing host file that corresponds to the given virtual filepath in the output directory on the host filesystem will be deleted on the host filesystem; not just its virtual file entry. All modifications made through the virtual file handle will also be reflected in the physical file on the host file system.
See also
openEmptyOutputFile()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.

◆ openOutputFileForAppending()

virtual OutputFileHandle grem::Filesystem::openOutputFileForAppending ( CStringView filepath)
nodiscardpure virtual

Open a file relative to the current output directory for appended writing, or create an empty file and open it if one didn't already exist.

Parameters
filepathvirtual filepath of the file to be opened, relative to the current output directory.
Returns
a new file handle with an output stream set up to write to the end of the opened file.
Exceptions
File::Erroron failure to open the file for writing.
std::bad_allocon allocation failure.
Warning
If successful, the existing host file that corresponds to the given virtual filepath in the output directory on the host filesystem will receive all modifications made through the virtual file handle.
Note
A new, empty file will be created if the specified file doesn't already exist.
See also
openInputFile()
openEmptyOutputFile()

Implemented in grem::application::VirtualFilesystem, and grem::NativeFilesystem.


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