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 | |
PathVector | extractPaths (const std::string &env) |
Extracts and resolves all paths contained in an environment variable. More... | |
Path | normalizePath (const Path &path) |
Normalizes a path: it resolves all ".." in a path. More... | |
Path | resolvePath (const Path &path, bool makeAbsolute=true) |
Resolves a path. More... | |
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... | |
Path | getExecutableDirectory () |
Get the path of the current running application binary. More... | |
Path | getHomeDirectory () |
Get the absolute path of the current user's home directory. More... | |
Path | getAppDataDirectory (const std::string &appName="mira") |
Returns the absolute path for application-specific data. More... | |
Path | getTempDirectory () |
Get the absolute path of the temporary directory. More... | |
Path | relativizePath (const Path &path, const Path &base) |
Returns relative path from base to path. More... | |
void | checkForMIRAPath () |
Checks if environment variable(s) for MIRA is/are defined. More... | |
PathVector | getMIRAPaths () |
Returns vector of all MIRA project paths. More... | |
Path | findFile (const PathVector &paths, const Path &file) |
Find a file in a vector of paths. More... | |
PathVector | findFiles (const PathVector &paths, const Path &file, bool recursive=false) |
Finds all files in a vector of paths. More... | |
PathVector | findFiles (const Path &path, const Path &file, bool recursive=false) |
Same as findFiles above, but using only one search path. More... | |
PathVector | findProjectFiles (const Path &file, bool recursive=false) |
Same as findFiles above, but using all of the paths contained in $MIRA_PATH variable. More... | |
Path | findDirectory (const PathVector &paths, const Path &path) |
Find a sub directory in a vector of paths. More... | |
Path | findProjectDirectory (const Path &path) |
Same as findDirectory above, but using all of the paths contained in $MIRA_PATH variable. More... | |
Path | findContainingMIRAPath (const Path &path) |
Returns the MIRA path that contains the given path. More... | |
Path | chopMIRAPath (const Path &path) |
Removes the root part of the given path that belongs to one of MIRA paths. More... | |
PathVector | findDirectories (const PathVector &paths, const Path &path, bool recursive=false) |
Finds all sub directories in a vector of paths. More... | |
PathVector | findDirectories (const Path &basePath, const Path &path, bool recursive=false) |
Same as findDirectories above, but searching only in one path. More... | |
PathVector | findProjectDirectories (const Path &path, bool recursive=false) |
Same as findDirectories above, but using all of the paths contained in $MIRA_PATH variable. More... | |
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.
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 %) |
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 |
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).
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 |
Path mira::getExecutableDirectory | ( | ) |
Get the path of the current running application binary.
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.
XRuntime | if no home directory can be found |
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}
XRuntime | If the application data path does not exist or cannot be created. |
Path mira::getTempDirectory | ( | ) |
Get the absolute path of the temporary directory.
Under Linux 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) |
Returns relative path from base to path.
E.g.:
void mira::checkForMIRAPath | ( | ) |
Checks if environment variable(s) for MIRA is/are defined.
Exception | if variables is/are not set |
PathVector mira::getMIRAPaths | ( | ) |
Returns vector of all MIRA project paths.
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 |
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
PathVector mira::findFiles | ( | const Path & | path, |
const Path & | file, | ||
bool | recursive = false |
||
) |
Same as findFiles above, but using only one search path.
PathVector mira::findProjectFiles | ( | const Path & | file, |
bool | recursive = false |
||
) |
Same as findFiles above, but using all of the paths contained in $MIRA_PATH variable.
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 |
Same as findDirectory above, but using all of the paths contained in $MIRA_PATH variable.
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 |
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 |
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.
PathVector mira::findDirectories | ( | const Path & | basePath, |
const Path & | path, | ||
bool | recursive = false |
||
) |
Same as findDirectories above, but searching only in one path.
PathVector mira::findProjectDirectories | ( | const Path & | path, |
bool | recursive = false |
||
) |
Same as findDirectories above, but using all of the paths contained in $MIRA_PATH variable.
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*