cpplocate  1.0.0.a8d87a94e3ab
C++ Locator Library
Namespaces | Classes | Functions
cpplocate Namespace Reference

Namespaces

 utils
 

Classes

class  ModuleInfo
 

Functions

CPPLOCATE_API const std::string & getExecutablePath ()
 
CPPLOCATE_API const std::string & getBundlePath ()
 
CPPLOCATE_API const std::string & getModulePath ()
 
CPPLOCATE_API std::string getLibraryPath (void *symbol)
 
CPPLOCATE_API std::string locatePath (const std::string &relPath, const std::string &systemDir="", void *symbol=nullptr)
 
CPPLOCATE_API ModuleInfo findModule (const std::string &name)
 
std::ostream & operator<< (std::ostream &stream, const ModuleInfo &info)
 

Function Documentation

CPPLOCATE_API const std::string& cpplocate::getExecutablePath ( )

Get path to the current executable.

Returns
Path to executable (including filename)
Remarks
The path is returned in native format, e.g., backslashes on Windows.

It is assumed the executable path is static throughout the process.

CPPLOCATE_API const std::string& cpplocate::getBundlePath ( )

Get path to the current application bundle.

Returns
Path to bundle (including filename)
Remarks
The path is returned in unified format (forward slashes). If the current executable is part of a macOS application bundle, this function returns the part to the bundle. Otherwise, an empty string is returned.

It is assumed the bundle path is static throughout the process.

CPPLOCATE_API const std::string& cpplocate::getModulePath ( )

Get path to the current module.

Returns
Path to module (directory in which the executable is located)
Remarks
The path is returned in unified format (forward slashes).

It is assumed the executable name is static throughout the process.

CPPLOCATE_API std::string cpplocate::getLibraryPath ( void *  symbol)

Get path to dynamic library.

Parameters
[in]symbolA symbol from the library, e.g., a function or variable pointer
Returns
Path to library (including filename)
Remarks
The path is returned in unified format (forward slashes). If symbol is nullptr, an empty string is returned.
CPPLOCATE_API std::string cpplocate::locatePath ( const std::string &  relPath,
const std::string &  systemDir = "",
void *  symbol = nullptr 
)

Locate path to a file or directory.

Parameters
[in]relPathRelative path to a file or directory (e.g., 'data/logo.png')
[in]systemDirSubdirectory for system installs (e.g., 'share/myappname')
[in]symbolA symbol from the library, e.g., a function or variable pointer
Returns
Path to file or directory
Remarks
This function tries to locate the named file or directory based on the location of the current executable or library. If the file or directory could be found, the base path from which the relative path can be resolved is returned. Otherwise, an empty string is returned.

The path is returned in unified format (forward slashes).

CPPLOCATE_API ModuleInfo cpplocate::findModule ( const std::string &  name)

Tries to locate a module.

Parameters
[in]nameModule name (e.g., "mymodule")
Returns
Module information, empty on error
Remarks
It is assumed the 'CPPLOCATE_PATH' environment variable is static throughout the process.

This functions looks for the filename "<name>.modinfo". It searches the following locations:

  1. The current module path
  2. All pathes contained in the enironment variable CPPLOCATE_PATH 2.a <path>/<name>.modinfo 2.b <path>/<name>/<name>.modinfo
  3. Standard locations: 3.a C: Files<name><name>.modinfo 3.b /usr/share/<name>/<name>.modinfo 3.c /usr/local/share/<name>/<name>.modinfo
std::ostream& cpplocate::operator<< ( std::ostream &  stream,
const ModuleInfo info 
)

Stream output operator for a ModuleInfo.

Parameters
[in]streamThe stream to print to
[in]infoThe module info
Returns
The stream to fulfill the expected fluid interface