MIRA
|
A Path is mainly a typedef for to the boost::filesystem::path class. However, the path headers provide additional functionality to the boost classes.
Whenever one of your methods expects a file or a path as a parameter, you should use the Path class. Furthermore, you should always call resolvePath() before accessing or opening the file. This has the following advantages
MIRA uses project directories to store executables, libraries and installed config files. Since the environment variable MIRA_PATH should normally hold all paths that point to installation directories of different projects built with MIRA, it can be used to search for files (e.g. config files). There are multiple functions that can be used to search for files and directories in all installed MIRA projects (assuming MIRA_PATH is set correctly).
For the next examples assume the following directory structure:
Additionally assume MIRA_PATH=/root/mira1:/root/mira2.
findProjectFile
findProjectFile(filename) will search for the first match of filename in the given subdirectory structure of all paths in MIRA_PATH. Therefore it concatenates each path contained in the MIRA_PATH with the filename and returns the first file found that matches the concatenated filename.
The above example will search for:
findProjectFiles
Like findProjectFile() findProjectFiles(filename) will concatenate filename with each path in the MIRA_PATH variable but will return all found files in the given subdirectory structure.
findProjectDirectory
findProjectDirectory(dirname) works like findProjectFile but for directories. It concatenates dirname with all paths contained in MIRA_PATH and returns the first existing folder matching the name.
The above example will search for:
findProjectDirectories
Like findProjectDirectory() findProjectDirectory(dirname) will concatenate dirname with each path in the MIRA_PATH variable but will return all found directories in the given subdirectory structure.
Find files or paths recursively in subdirectories
The findProjectFiles and findProjectDirectories functions allow to find files/directories that not only match the concatenation of the file-/dirname with all paths contained in the MIRA_PATH variable. This means that one can search for a file or directory structure recursively in any subpath of each MIRA_PATHs path.
The above examples will look for file1.xml / robot in every subfolder of /root/mira1 and root/mira2.
resolvePath() automatically resolves a find placeholder. This placeholder can be used to search for files in the MIRA project dirs contained in the MIRA_PATH. The syntax is like the one of an environment variable:
A find placeholder is resolved by calling findProjectPath(). findProjectPath() tries to first find a file using findProjectFile(). If no file is found, it uses findProjectDirectory() to look for a directory. If no directory is found, it will call findProjectFiles() with recursive mode set to true to look for files also in subdirectories. If no file is found, it finally calls findProjectDirectories() with recursive mode set to true. If no directory is found in subdirectories, an exception is thrown. If multiple matches (files or directories) are found it will also throw an exception.
resolvePath() automatically resolves a findkg placeholder. This placeholder can be used to search for installed packages in the MIRA project dirs contained in the MIRA_PATH. The syntax is like the one of an environment variable:
A findpkg placeholder is resolved by calling findPackage(). The placeholder is replaced by the root directory of the package. If no package is found an exception is thrown.