Lysa  0.0
Lysa 3D Engine
VirtualFS Class Reference

Detailed Description

Virtual file system helper used to resolve portable paths.

  • Provide a consistent way to query files/directories and open streams across platforms and packaging schemes.
  • Support a simple URI scheme (app://) to reference assets relative to the application install or data directory.
  • Offer convenience helpers for loading whole files and images.

Notes:

  • All methods are static; there is no instance to create.
  • Thread‑safety: methods are stateless and may be called from any thread.

Static Public Member Functions

static bool dirExists (const std::string &filepath)
 
static bool fileExists (const std::string &filepath)
 
static std::ifstream openReadStream (const std::string &filepath)
 
static std::ofstream openWriteStream (const std::string &filepath)
 
static std::string parentPath (const std::string &filepath)
 
static void loadBinaryData (const std::string &filepath, std::vector< char > &out)
 
static std::byte * loadRGBAImage (const std::string &filepath, uint32 &width, uint32 &height, uint64 &size)
 
static void destroyImage (std::byte *image)
 
static std::string getPath (const std::string &filepath)
 

Static Public Attributes

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

Member Function Documentation

static void destroyImage ( std::byte *  image)
static

Frees an image buffer allocated by loadRGBAImage().

Parameters
imagePointer previously returned by loadRGBAImage() (may be nullptr).
static bool dirExists ( const std::string &  filepath)
static

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

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

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

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

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.

Parameters
filepathURI.
Returns
Resolved OS path suitable for file I/O APIs.
static void loadBinaryData ( const std::string &  filepath,
std::vector< char > &  out 
)
static

Loads the entire file contents into a byte buffer.

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

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.
static std::ifstream openReadStream ( const std::string &  filepath)
static

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.
static std::ofstream openWriteStream ( const std::string &  filepath)
static

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.
static std::string parentPath ( const std::string &  filepath)
static

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.