Functions to handle getting system paths, keeps track of: More...
#include <gz/common/SystemPaths.hh>
Public Member Functions | |
SystemPaths () | |
Constructor for SystemPaths. | |
void | AddFilePaths (const std::string &_path) |
Add colon (semicolon on windows) delimited paths to find files. These paths will be used with the FindFile function. | |
void | AddFindFileCallback (std::function< std::string(const std::string &)> _cb) |
Add a callback to use when FindFile() can't find a file. The callback should return a full local path to the requested file, or and empty string if the file was not found in the callback. The path should use platform-specific directory separators. Callbacks will be called in the order they were added until a path is found (if a callback is set using SetFindFileCallback(), that one is called first). | |
void | AddFindFileURICallback (std::function< std::string(const common::URI &)> _cb) |
Add a callback to use when FindFileURI() can't find a file. The callback should return a full local path to the requested file, or and empty string if the file was not found in the callback. The path should use platform-specific directory separators. Callbacks will be called in the order they were added until a path is found (if a callback is set using SetFindFileURICallback(), that one is called first). | |
void | AddPluginPaths (const std::string &_path) |
Add colon (semicolon on windows) delimited paths to plugins. | |
void | AddSearchPathSuffix (const std::string &_suffix) |
add _suffix to the list of path search suffixes | |
void | ClearFilePaths () |
clear out SystemPaths::filePaths | |
void | ClearPluginPaths () |
clear out SystemPaths::pluginPaths | |
std::string | FilePathEnv () const |
Get the file path environment variable in use. The environment variable contains a set of colon (semicolon on windows) delimited paths. These paths are used with the FindFile functions. | |
const std::list< std::string > & | FilePaths () |
Get the file paths. | |
std::string | FindFile (const std::string &_filename, const bool _searchLocalPath=true, const bool _verbose=true) const |
Find a file in the set search paths (not recursive) | |
std::string | FindFileURI (const common::URI &_uri) const |
Find a file or path using a URI. If URI is not an absolute path, the URI's path will be matched against all added paths and environment variables (including URI authority as needed). | |
std::string | FindFileURI (const std::string &_uri) const |
Find a file or path using a URI. | |
std::string | FindSharedLibrary (const std::string &_libName) |
Find a shared library by name in the plugin paths. | |
std::string | LogPath () const |
Get the log path. If GZ_LOG_PATH environment variable is set, then this path is used. If not, the path is $HOME/.gz, and in case even HOME is not set, /tmp/gz is used. If the directory does not exist, it is created in the constructor of SystemPaths. | |
const std::list< std::string > & | PluginPaths () |
Get the plugin paths. | |
void | SetFilePathEnv (const std::string &_env) |
Set the file path environment variable to use, and clears any previously set file paths. The default environment variable is GZ_FILE_PATH. The environment variable should be a set of colon (semicolon on windows) delimited paths. These paths will be used with the FindFile function. | |
void | SetPluginPathEnv (const std::string &_env) |
Set the plugin path environment variable to use. | |
Static Public Member Functions | |
static char | Delimiter () |
Get the delimiter that the current operating system uses to separate different paths from each other. | |
static std::string | LocateLocalFile (const std::string &_filename, const std::vector< std::string > &_paths) |
look for a file in a set of search paths (not recursive) \description This method checks if a file exists in given directories. It does so by joining each path with the filename and checking if the file exists. If the file exists in multiple paths the first one is found. | |
static std::string | NormalizeDirectoryPath (const std::string &_path) |
Format the directory path to use "/" as a separator with "/" at the end. | |
static std::list< std::string > | PathsFromEnv (const std::string &_env) |
Return all paths given by an environment variable. | |
Detailed Description
Functions to handle getting system paths, keeps track of:
- SystemPaths::pluginPaths - plugin library paths for common::WorldPlugin
Constructor & Destructor Documentation
◆ SystemPaths()
SystemPaths | ( | ) |
Constructor for SystemPaths.
Member Function Documentation
◆ AddFilePaths()
void AddFilePaths | ( | const std::string & | _path | ) |
Add colon (semicolon on windows) delimited paths to find files. These paths will be used with the FindFile function.
- Parameters
-
[in] _path A colon (semicolon on windows) delimited string of paths. The path can have either forward slashes or platform- specific directory separators, both are okay.
◆ AddFindFileCallback()
void AddFindFileCallback | ( | std::function< std::string(const std::string &)> | _cb | ) |
Add a callback to use when FindFile() can't find a file. The callback should return a full local path to the requested file, or and empty string if the file was not found in the callback. The path should use platform-specific directory separators. Callbacks will be called in the order they were added until a path is found (if a callback is set using SetFindFileCallback(), that one is called first).
- Parameters
-
[in] _cb The callback function, which takes a file path or URI and returns the full local path.
◆ AddFindFileURICallback()
void AddFindFileURICallback | ( | std::function< std::string(const common::URI &)> | _cb | ) |
Add a callback to use when FindFileURI() can't find a file. The callback should return a full local path to the requested file, or and empty string if the file was not found in the callback. The path should use platform-specific directory separators. Callbacks will be called in the order they were added until a path is found (if a callback is set using SetFindFileURICallback(), that one is called first).
- Parameters
-
[in] _cb The callback function, which takes a file path or URI and returns the full local path.
◆ AddPluginPaths()
void AddPluginPaths | ( | const std::string & | _path | ) |
Add colon (semicolon on windows) delimited paths to plugins.
- Parameters
-
[in] _path the directory to add
◆ AddSearchPathSuffix()
void AddSearchPathSuffix | ( | const std::string & | _suffix | ) |
add _suffix to the list of path search suffixes
- Parameters
-
[in] _suffix The suffix to add
◆ ClearFilePaths()
void ClearFilePaths | ( | ) |
clear out SystemPaths::filePaths
◆ ClearPluginPaths()
void ClearPluginPaths | ( | ) |
clear out SystemPaths::pluginPaths
◆ Delimiter()
|
static |
Get the delimiter that the current operating system uses to separate different paths from each other.
◆ FilePathEnv()
std::string FilePathEnv | ( | ) | const |
Get the file path environment variable in use. The environment variable contains a set of colon (semicolon on windows) delimited paths. These paths are used with the FindFile functions.
- Returns
- Name of the environment variable
- See also
- SetFilePathEnv
◆ FilePaths()
const std::list< std::string > & FilePaths | ( | ) |
Get the file paths.
- Returns
- a list of paths (with forward slashes as directory separators)
◆ FindFile()
std::string FindFile | ( | const std::string & | _filename, |
const bool | _searchLocalPath = true , |
||
const bool | _verbose = true |
||
) | const |
Find a file in the set search paths (not recursive)
- Parameters
-
[in] _filename Name of the file to find. [in] _searchLocalPath True to search in the current working directory. [in] _verbose False to omit console messages.
- Returns
- Returns full path name to file with platform-specific directory separators, or empty string on error.
◆ FindFileURI() [1/2]
std::string FindFileURI | ( | const common::URI & | _uri | ) | const |
Find a file or path using a URI. If URI is not an absolute path, the URI's path will be matched against all added paths and environment variables (including URI authority as needed).
- Parameters
-
[in] _uri the uniform resource identifier
- Returns
- Returns full path name to file with platform-specific directory separators, or an empty string if URI couldn't be found.
◆ FindFileURI() [2/2]
std::string FindFileURI | ( | const std::string & | _uri | ) | const |
◆ FindSharedLibrary()
std::string FindSharedLibrary | ( | const std::string & | _libName | ) |
Find a shared library by name in the plugin paths.
This will try different combinations of library names on different platforms. For example searching for "MyLibName" may try finding "MyLibName", "libMyLibName.so", "MyLibName.dll", etc...
- Parameters
-
[in] _libName Name of shared libary to look for
- Returns
- Path to file with platform-specific directory separators, or empty string on error.
◆ LocateLocalFile()
|
static |
look for a file in a set of search paths (not recursive) \description This method checks if a file exists in given directories. It does so by joining each path with the filename and checking if the file exists. If the file exists in multiple paths the first one is found.
- Parameters
-
[in] _filename Name of the file to find [in] _paths paths to look for the file
- Returns
- Returns a path that will work from the current directory or an empty string if the file was not found. The returned path will be normalized, i.e. backslashes will be substituted with forward slashes.
◆ LogPath()
std::string LogPath | ( | ) | const |
Get the log path. If GZ_LOG_PATH environment variable is set, then this path is used. If not, the path is $HOME/.gz, and in case even HOME is not set, /tmp/gz is used. If the directory does not exist, it is created in the constructor of SystemPaths.
- Returns
- the path
◆ NormalizeDirectoryPath()
|
static |
Format the directory path to use "/" as a separator with "/" at the end.
- Parameters
-
[in] _path Path to normalize
- Returns
- Normalized path
◆ PathsFromEnv()
|
static |
Return all paths given by an environment variable.
- Parameters
-
[in] _env Environment variable.
- Returns
- A list of paths listed by the environment variable.
◆ PluginPaths()
const std::list< std::string > & PluginPaths | ( | ) |
Get the plugin paths.
- Returns
- a list of paths (with forward slashes as directory separators)
◆ SetFilePathEnv()
void SetFilePathEnv | ( | const std::string & | _env | ) |
Set the file path environment variable to use, and clears any previously set file paths. The default environment variable is GZ_FILE_PATH. The environment variable should be a set of colon (semicolon on windows) delimited paths. These paths will be used with the FindFile function.
- Parameters
-
[in] _env name of the environment variable
- See also
- FilePathEnv
◆ SetPluginPathEnv()
void SetPluginPathEnv | ( | const std::string & | _env | ) |
Set the plugin path environment variable to use.
- Parameters
-
[in] _env name of the environment variable
The documentation for this class was generated from the following file: