wPlot2D version: 0.1.0
A lightweight C++ library for clear and customizable 2D scientific plots.
Loading...
Searching...
No Matches
wEngine::PathUtils Class Reference

Utility class providing static functions for managing executable and resource paths across platforms. More...

#include <wPathUtils.hpp>

Static Public Member Functions

static std::string getExecutablePath ()
 Returns the absolute path to the current executable.
static std::string getExecutableDir ()
 Returns the directory containing the current executable.

Detailed Description

Utility class providing static functions for managing executable and resource paths across platforms.

This class retrieves the absolute path of the current executable or its parent directory, in a portable way (macOS, Windows, Linux). It is particularly useful for locating resources such as fonts, images, or configuration files relative to the application binary.

All methods are static and do not require instantiation.

Note
If the path cannot be determined, a std::runtime_error is thrown.

Notes on unusual headers:

  • <mach-o/dyld.h> (macOS): provides _NSGetExecutablePath, part of the Mach-O dynamic loader API. Documentation: see Apple Developer docs (man page: man 3 dyld).
  • <windows.h> (Windows): provides GetModuleFileNameA, part of the Win32 API. Documentation: see Microsoft Learn (GetModuleFileName function).
  • <unistd.h> + /proc/self/exe (Linux): /proc/self/exe is a symbolic link exposing the running executable, documented in man 5 proc.

These APIs are not C++ standard and must be used with care, as they are platform-dependent.

See also
std::filesystem for path manipulations.
Author
Wilfried Koch

Member Function Documentation

◆ getExecutablePath()

std::string wEngine::PathUtils::getExecutablePath ( )
staticnodiscard

Returns the absolute path to the current executable.

Platform-specific APIs are used:

  • macOS: _NSGetExecutablePath
  • Windows: GetModuleFileNameA
  • Linux: /proc/self/exe
Returns
Absolute path to the binary (e.g., "/path/to/MyApp.app/Contents/MacOS/MyApp").
Exceptions
std::runtime_errorif the path cannot be resolved.

◆ getExecutableDir()

std::string wEngine::PathUtils::getExecutableDir ( )
staticnodiscard

Returns the directory containing the current executable.

This is often used as a base path to resolve relative resource paths.

Returns
Directory containing the binary (e.g., "/path/to/MyApp.app/Contents/MacOS").
Exceptions
std::runtime_errorif the path cannot be resolved.

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