MIRA
|
For detailed information see Path.
More...
Typedefs | |
typedef boost::filesystem::path | Path |
Typedef of a Path (shorter version for boost::filesystem::path) More... | |
typedef std::vector< Path > | PathVector |
Typedef for vector of Paths. More... | |
Functions | |
MIRA_BASE_EXPORT PathVector | extractPaths (const std::string &env) |
Extracts and resolves all paths contained in an environment variable. More... | |
MIRA_BASE_EXPORT Path | normalizePath (const Path &path) |
Normalizes a path: it resolves all ".." in a path. More... | |
MIRA_BASE_EXPORT Path | resolvePath (const Path &path, bool makeAbsolute=true) |
Resolves a path. More... | |
MIRA_BASE_EXPORT bool | isRootOfPath (const Path &root, const Path &path) |
The function takes two absolute paths and returns true if the given root path is part of the path given in the path argument. More... | |
MIRA_BASE_EXPORT Path | getExecutableDirectory () |
Get the path of the current running application binary. More... | |
MIRA_BASE_EXPORT Path | getHomeDirectory () |
Get the absolute path of the current user's home directory. More... | |
MIRA_BASE_EXPORT Path | getAppDataDirectory (const std::string &appName="mira") |
Returns the absolute path for application-specific data. More... | |
MIRA_BASE_EXPORT Path | getTempDirectory () |
Get the absolute path of the temporary directory. More... | |
MIRA_BASE_EXPORT Path | relativizePath (const Path &path, const Path &base) |
Returns relative path from base to path. More... | |
MIRA_BASE_EXPORT void | checkForMIRAPath () |
Checks if environment variable(s) for MIRA is/are defined. More... | |
MIRA_BASE_EXPORT PathVector | getMIRAPaths () |
Returns vector of all MIRA project paths. More... | |
MIRA_BASE_EXPORT Path | findFile (const PathVector &paths, const Path &file) |
Find a file in a vector of paths. More... | |
MIRA_BASE_EXPORT PathVector | findFiles (const PathVector &paths, const Path &file, bool recursive=false) |
Finds all files in a vector of paths. More... | |
MIRA_BASE_EXPORT PathVector | findFiles (const Path &path, const Path &file, bool recursive=false) |
Same as findFiles above, but using only one search path. More... | |
MIRA_BASE_EXPORT PathVector | findProjectFiles (const Path &file, bool recursive=false) |
Same as findFiles above, but using all of the paths contained in $MIRA_PATH variable. More... | |
MIRA_BASE_EXPORT Path | findDirectory (const PathVector &paths, const Path &path) |
Find a sub directory in a vector of paths. More... | |
MIRA_BASE_EXPORT Path | findProjectDirectory (const Path &path) |
Same as findDirectory above, but using all of the paths contained in $MIRA_PATH variable. More... | |
MIRA_BASE_EXPORT Path | findContainingMIRAPath (const Path &path) |
Returns the MIRA path that contains the given path. More... | |
MIRA_BASE_EXPORT Path | chopMIRAPath (const Path &path) |
Removes the root part of the given path that belongs to one of MIRA paths. More... | |
MIRA_BASE_EXPORT PathVector | findDirectories (const PathVector &paths, const Path &path, bool recursive=false) |
Finds all sub directories in a vector of paths. More... | |
MIRA_BASE_EXPORT PathVector | findDirectories (const Path &basePath, const Path &path, bool recursive=false) |
Same as findDirectories above, but searching only in one path. More... | |
MIRA_BASE_EXPORT PathVector | findProjectDirectories (const Path &path, bool recursive=false) |
Same as findDirectories above, but using all of the paths contained in $MIRA_PATH variable. More... | |
MIRA_BASE_EXPORT std::string | findProjectPath (const std::string &path) |
Finds a file or directory searching in all paths contained in $MIRA_PATH. More... | |
constexpr std::string_view | findContainingMIRAPath (const std::string_view &path, const std::string_view &miraPaths) |
Returns the MIRA path that contains the given path. More... | |
constexpr std::string_view | findContainingMIRAPath (const char *path, const char *miraPaths) |
As above, overload for const char* path. More... | |
constexpr std::string_view | findContainingMIRAPath (const char *path) |
With this overload the MIRA paths are not provided as argument, they are expected to be defined as a compiler definition MIRA_PATHS. More... | |
constexpr std::string_view | chopMIRAPath (const std::string_view &path, const std::string_view &miraPaths) |
Removes the root part of the given path that belongs to one of MIRA paths. More... | |
constexpr const char * | chopMIRAPath (const char *path, const char *miraPaths) |
As above, overload for const char* path. More... | |
constexpr const char * | chopMIRAPath (const char *path) |
With this overload the MIRA paths are not provided as argument, they are expected to be defined as a compiler definition MIRA_PATHS. More... | |
For detailed information see Path.
typedef boost::filesystem::path Path |
Typedef of a Path (shorter version for boost::filesystem::path)
typedef std::vector<Path> PathVector |
Typedef for vector of Paths.
MIRA_BASE_EXPORT PathVector mira::extractPaths | ( | const std::string & | env | ) |
Extracts and resolves all paths contained in an environment variable.
If the path is found and exists it will be added to the returned path list.
[in] | env | The environmental variable e.g. PATH (without variable token like $ or %) |
MIRA_BASE_EXPORT Path mira::normalizePath | ( | const Path & | path | ) |
Normalizes a path: it resolves all ".." in a path.
For optimal results the path should be made absolute before calling this function. Otherwise it is not guaranteed that all ".." are resolved e.g.
will return "../my/path" since it can not determine the parent path.
[in] | path | The path to be normalized |
MIRA_BASE_EXPORT Path mira::resolvePath | ( | const Path & | path, |
bool | makeAbsolute = true |
||
) |
Resolves a path.
It will resolve environment variables, (optionally) make the path absolute and finally normalized.
[in] | path | The path to be resolved |
[in] | makeAbsolute | If path is relative and this flag is set the path will be made absolute. |
Note: for an empty input path, the relative result is empty, the absolute result is the same as for '.' (current working directory).
MIRA_BASE_EXPORT bool mira::isRootOfPath | ( | const Path & | root, |
const Path & | path | ||
) |
The function takes two absolute paths and returns true if the given root path is part of the path given in the path argument.
[in] | root | path |
[in] | path | to check |
MIRA_BASE_EXPORT Path mira::getExecutableDirectory | ( | ) |
Get the path of the current running application binary.
MIRA_BASE_EXPORT Path mira::getHomeDirectory | ( | ) |
Get the absolute path of the current user's home directory.
Under Linux this will be the content of the HOME environment variable.
Under Windows it will return the path of the current user's profile: e.g. C:/Documents and Settings/UserXYZ If that directory can not be retrieved, the following alternatives are used:
XRuntime | if no home directory can be found |
MIRA_BASE_EXPORT Path mira::getAppDataDirectory | ( | const std::string & | appName = "mira" | ) |
Returns the absolute path for application-specific data.
A sub-directory with the specified appName will be created automatically.
Under Linux the following directory will be returned: ${USER HOME}/.config/${appName}
Under Windows the typical path will be as follows: C:\Documents and Settings\${USER}\Application Data\${appName}
XRuntime | If the application data path does not exist or cannot be created. |
MIRA_BASE_EXPORT Path mira::getTempDirectory | ( | ) |
Get the absolute path of the temporary directory.
Under Linux the following checks are performed in the given order:
Under Windows the following checks are performed in the given order:
XRuntime | if none of the above checks yields a result (meaning: no temporary directory can be found) |
MIRA_BASE_EXPORT Path mira::relativizePath | ( | const Path & | path, |
const Path & | base | ||
) |
Returns relative path from base to path.
E.g.:
MIRA_BASE_EXPORT void mira::checkForMIRAPath | ( | ) |
Checks if environment variable(s) for MIRA is/are defined.
Exception | if variables is/are not set |
MIRA_BASE_EXPORT PathVector mira::getMIRAPaths | ( | ) |
Returns vector of all MIRA project paths.
MIRA_BASE_EXPORT Path mira::findFile | ( | const PathVector & | paths, |
const Path & | file | ||
) |
Find a file in a vector of paths.
[in] | paths | The list of paths to search in. |
[in] | file | The file to find. |
If the file exists in different paths, the first occurrence will be returned. A sub directory structure can be given e.g.
XIO | if no file was found |
MIRA_BASE_EXPORT PathVector mira::findFiles | ( | const PathVector & | paths, |
const Path & | file, | ||
bool | recursive = false |
||
) |
Finds all files in a vector of paths.
[in] | paths | The list of paths to search in. |
[in] | file | The file (can also contain wildcards like * and ?) |
[in] | recursive | Flag for recursive search. |
A sub directory structure can be given within file e.g.
e.g. If paths=/usr/local/MIRA it will look for all files matching /usr/local/MIRA/resource/MyResourceFolder/Image*.png.
If recursive=true it will search (in the above example) for all occurrences of resource/MyResourceFolder/Image*.png in all sub directories of /usr/local/MIRA i.e. it will also find /usr/local/MIRA/AnotherFolder/SubFolder/resource/MyResourceFolder/Image1.png
MIRA_BASE_EXPORT PathVector mira::findFiles | ( | const Path & | path, |
const Path & | file, | ||
bool | recursive = false |
||
) |
Same as findFiles above, but using only one search path.
MIRA_BASE_EXPORT PathVector mira::findProjectFiles | ( | const Path & | file, |
bool | recursive = false |
||
) |
Same as findFiles above, but using all of the paths contained in $MIRA_PATH variable.
MIRA_BASE_EXPORT Path mira::findDirectory | ( | const PathVector & | paths, |
const Path & | path | ||
) |
Find a sub directory in a vector of paths.
[in] | paths | The list of paths to search in. |
[in] | path | The sub path to find. |
A sub directory structure can be given e.g.
XIO | if no directory was found |
MIRA_BASE_EXPORT Path mira::findProjectDirectory | ( | const Path & | path | ) |
Same as findDirectory above, but using all of the paths contained in $MIRA_PATH variable.
MIRA_BASE_EXPORT Path mira::findContainingMIRAPath | ( | const Path & | path | ) |
Returns the MIRA path that contains the given path.
[in] | path | the path to be processed |
XLogical | if path is not located in one of the MIRA paths |
MIRA_BASE_EXPORT Path mira::chopMIRAPath | ( | const Path & | path | ) |
Removes the root part of the given path that belongs to one of MIRA paths.
E.g.:
will return 'some/sub/folder' if '/home/user/mira' is set as MIRA path.
[in] | path | the path to be processed |
XLogical | if path is not located in one of the MIRA paths |
MIRA_BASE_EXPORT PathVector mira::findDirectories | ( | const PathVector & | paths, |
const Path & | path, | ||
bool | recursive = false |
||
) |
Finds all sub directories in a vector of paths.
[in] | paths | The list of paths to search in. |
[in] | path | The sub path to find. |
[in] | recursive | Flag for recursive search. |
A sub directory structure can be given e.g.
e.g. If paths=[/usr/local/MyProject, /usr/local/AnotherProject] it will look for all occurrences of resource/MyResourceFolder/ in /usr/local/MyProject/ and /usr/local/AnotherProject.
MIRA_BASE_EXPORT PathVector mira::findDirectories | ( | const Path & | basePath, |
const Path & | path, | ||
bool | recursive = false |
||
) |
Same as findDirectories above, but searching only in one path.
MIRA_BASE_EXPORT PathVector mira::findProjectDirectories | ( | const Path & | path, |
bool | recursive = false |
||
) |
Same as findDirectories above, but using all of the paths contained in $MIRA_PATH variable.
MIRA_BASE_EXPORT std::string mira::findProjectPath | ( | const std::string & | path | ) |
Finds a file or directory searching in all paths contained in $MIRA_PATH.
Tries to find the file or directory by calling:
XIO | If no file or directory is found or multiple matches are found |
path | The path to be found |
constexpr std::string_view mira::findContainingMIRAPath | ( | const std::string_view & | path, |
const std::string_view & | miraPaths | ||
) |
Returns the MIRA path that contains the given path.
[in] | path | the path to be processed |
[in] | miraPaths | the MIRA paths |
The option to provide MIRA paths as argument is useful for testing. See below for an overload that does not require this.
constexpr std::string_view mira::findContainingMIRAPath | ( | const char * | path, |
const char * | miraPaths | ||
) |
As above, overload for const char* path.
Note that you cannot just convert the result to a const char*, as the size is needed in addition to the data pointer (matching null-termination can not be assumed)!
constexpr std::string_view mira::findContainingMIRAPath | ( | const char * | path | ) |
With this overload the MIRA paths are not provided as argument, they are expected to be defined as a compiler definition MIRA_PATHS.
Otherwise this will return an empty string literal "".
Note that you cannot just convert the result to a const char*, as the size is needed in addition to the data pointer (matching null-termination can not be assumed)!
constexpr std::string_view mira::chopMIRAPath | ( | const std::string_view & | path, |
const std::string_view & | miraPaths | ||
) |
Removes the root part of the given path that belongs to one of MIRA paths.
E.g.:
will return 'some/sub/folder' if '/home/user/mira' is set as MIRA path.
[in] | path | the path to be processed |
[in] | miraPaths | the MIRA paths |
The option to provide MIRA paths as argument is useful for testing. See below for an overload that does not require this.
constexpr const char* mira::chopMIRAPath | ( | const char * | path, |
const char * | miraPaths | ||
) |
As above, overload for const char* path.
As this only removes prefixes from path, null-termination persists and it is safe to return a const char*
constexpr const char* mira::chopMIRAPath | ( | const char * | path | ) |
With this overload the MIRA paths are not provided as argument, they are expected to be defined as a compiler definition MIRA_PATHS.
Otherwise this will return the unchanged argument path.
As this only removes prefixes from path, null-termination persists and it is safe to return a const char*