Lysa  0.0
Lysa 3D Engine
VirtualFS Class Reference

Detailed Description

Virtual file system helper used to resolve portable paths.

Public Member Functions

 VirtualFS (const VirtualFSConfiguration &config, const std::shared_ptr< vireo::Vireo > &vireo)
 
bool fileExists (const std::string &filepath) const
 
bool directoryExists (const std::string &dirPath) const
 
std::ifstream openReadStream (const std::string &filepath) const
 
std::ofstream openWriteStream (const std::string &filepath) const
 
std::string parentPath (const std::string &filepath) const
 
void loadBinaryData (const std::string &filepath, std::vector< char > &out) const
 
void loadBinaryData (std::ifstream &input, std::vector< char > &out) const
 
std::byte * loadImage (const std::string &filepath, uint32 &width, uint32 &height, uint64 &size) const
 
void loadScript (const std::string &scriptName, std::vector< char > &out) const
 
void loadShader (const std::string &shaderName, std::vector< char > &out) const
 
void destroyImage (std::byte *image) const
 
std::string getPath (const std::string &filepath) const
 
constexpr const std::string & getScriptsDirectory () const
 
constexpr std::string getScriptsURI () const
 

Static Public Attributes

static constexpr auto APP_URI {"app://"}
 

Constructor & Destructor Documentation

VirtualFS ( const VirtualFSConfiguration config,
const std::shared_ptr< vireo::Vireo > &  vireo 
)
inline

Member Function Documentation

void destroyImage ( std::byte *  image) const

Frees an image buffer allocated by loadImage().

Parameters
imagePointer previously returned by loadImage()
bool directoryExists ( const std::string &  dirPath) const

Tests whether a directory exists at the given path or URI.

Parameters
dirPathURI.
Returns
True if the file exists; false otherwise.
bool fileExists ( const std::string &  filepath) const

Tests whether a directory exists at the given path or URI.

Parameters
filepathURI.
Returns
True if the directory exists; false otherwise.

Tests whether a regular file exists at the given path or URI.

Parameters
filepathURI.
Returns
True if the file exists; false otherwise.
std::string getPath ( const std::string &  filepath) const

Resolves a path or app:// URI to a concrete OS path.

Implementations may expand environment variables, normalize separators, and map app:// to the application data/assets directory.

constexpr const std::string& getScriptsDirectory ( ) const
inlineconstexpr
constexpr std::string getScriptsURI ( ) const
inlineconstexpr
void loadBinaryData ( const std::string &  filepath,
std::vector< char > &  out 
) const

Loads the entire file contents into a byte buffer.

Parameters
filepathURI.
outDestination buffer; its contents are replaced by the file bytes.
void loadBinaryData ( std::ifstream &  input,
std::vector< char > &  out 
) const

Loads the entire file contents into a byte buffer.

Parameters
inputInput stream.
outDestination buffer; its contents are replaced by the file bytes.
std::byte* loadImage ( const std::string &  filepath,
uint32 width,
uint32 height,
uint64 size 
) const

Loads an image and returns an allocated RGBA (8‑bit per channel) buffer.

The caller owns the returned memory and must release it with destroyImage().

Parameters
filepathURI.
widthOutput image width in pixels.
heightOutput image height in pixels.
sizeOutput total buffer size in bytes (width*height*4).
Returns
Pointer to the newly allocated pixel buffer in RGBA8888 format, or nullptr on failure.
void loadScript ( const std::string &  scriptName,
std::vector< char > &  out 
) const
void loadShader ( const std::string &  shaderName,
std::vector< char > &  out 
) const
std::ifstream openReadStream ( const std::string &  filepath) const

Opens an input stream for reading the file at path or URI.

The returned stream is opened in binary mode unless the implementation states otherwise. Callers should check stream.is_open() (or its state) to ensure the file was successfully opened.

Parameters
filepathURI.
Returns
std::ifstream positioned at the start of the file.
std::ofstream openWriteStream ( const std::string &  filepath) const

Opens an output stream for writing the file at path or URI.

The returned stream is typically opened in binary mode and may create intermediate directories depending on platform support. Callers should check stream.is_open() (or its state) to ensure the file was successfully opened.

Parameters
filepathURI.
Returns
std::ofstream positioned at the start of the file.
std::string parentPath ( const std::string &  filepath) const

Returns the parent directory of the provided path or URI.

For app:// URIs, the parent is computed after resolution. Trailing separators are ignored.

Parameters
filepathURI.
Returns
Parent directory path, or an empty string if none.

Member Data Documentation

constexpr auto APP_URI {"app://"}
staticconstexpr

URI scheme used to reference files relative to the application root.