MIRA
Typedefs | Functions
Path


For detailed information see Path. More...

Collaboration diagram for Path:

Typedefs

typedef boost::filesystem::path Path
 Typedef of a Path (shorter version for boost::filesystem::path) More...
 
typedef std::vector< PathPathVector
 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...
 

Detailed Description


For detailed information see Path.

Typedef Documentation

◆ Path

typedef boost::filesystem::path Path

Typedef of a Path (shorter version for boost::filesystem::path)

◆ PathVector

typedef std::vector<Path> PathVector

Typedef for vector of Paths.

Function Documentation

◆ extractPaths()

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.

Parameters
[in]envThe environmental variable e.g. PATH (without variable token like $ or %)
Returns
All the existing paths contained in the env variable

◆ normalizePath()

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.

normalizePath("../my/path");

will return "../my/path" since it can not determine the parent path.

Note
This replaces boost::filesystem::path::normalize() because it is deprecated and also does not take symbolic links into account!
Parameters
[in]pathThe path to be normalized
Returns
The normalized path

◆ resolvePath()

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.

Parameters
[in]pathThe path to be resolved
[in]makeAbsoluteIf path is relative and this flag is set the path will be made absolute.
Returns
The resolved, absolute and normalized path

Note: for an empty input path, the relative result is empty, the absolute result is the same as for '.' (current working directory).

◆ isRootOfPath()

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.

Parameters
[in]rootpath
[in]pathto check

◆ getExecutableDirectory()

MIRA_BASE_EXPORT Path mira::getExecutableDirectory ( )

Get the path of the current running application binary.

Returns
The base of the current executable

◆ getHomeDirectory()

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:

  • the path specified in USERPROFILE
  • the path specified by HOMEDRIVE / HOMEPATH (concatenation!)
  • the path specified in HOME
Exceptions
XRuntimeif no home directory can be found
Returns
The path of the current user's home directory

◆ getAppDataDirectory()

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}

Exceptions
XRuntimeIf the application data path does not exist or cannot be created.
Returns
The absolute path for application-specific data.

◆ getTempDirectory()

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:

  • If TMPDIR is set its value is returned
  • If macro P_tmpdir is defined its value is returned
  • If /tmp exists it is returned

Under Windows the following checks are performed in the given order:

  • If TEMP is set its value is returned
  • If TMP is set its value is returned
  • Check path returned by GetTempPath - if it exists return it
  • If macro P_tmpdir is defined its value is returned
Exceptions
XRuntimeif none of the above checks yields a result (meaning: no temporary directory can be found)
Returns
The path of the temporary directory

◆ relativizePath()

MIRA_BASE_EXPORT Path mira::relativizePath ( const Path path,
const Path base 
)

Returns relative path from base to path.

E.g.:

relativizePath("/home/user/mira/toolboxes", "/home/user/mira")
// returns toolboxes

◆ checkForMIRAPath()

MIRA_BASE_EXPORT void mira::checkForMIRAPath ( )

Checks if environment variable(s) for MIRA is/are defined.

Exceptions
Exceptionif variables is/are not set

◆ getMIRAPaths()

MIRA_BASE_EXPORT PathVector mira::getMIRAPaths ( )

Returns vector of all MIRA project paths.

◆ findFile()

MIRA_BASE_EXPORT Path mira::findFile ( const PathVector paths,
const Path file 
)

Find a file in a vector of paths.

Parameters
[in]pathsThe list of paths to search in.
[in]fileThe 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.

findFile(paths, "resource/MyResourceFolder/Image.png")
Exceptions
XIOif no file was found
Returns
The path to the found file.

◆ findFiles() [1/2]

MIRA_BASE_EXPORT PathVector mira::findFiles ( const PathVector paths,
const Path file,
bool  recursive = false 
)

Finds all files in a vector of paths.

Parameters
[in]pathsThe list of paths to search in.
[in]fileThe file (can also contain wildcards like * and ?)
[in]recursiveFlag for recursive search.

A sub directory structure can be given within file e.g.

findFiles(paths, "resource/MyResourceFolder/Image*.png").

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

Returns
All the found file paths.

◆ findFiles() [2/2]

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.

◆ findProjectFiles()

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.

◆ findDirectory()

MIRA_BASE_EXPORT Path mira::findDirectory ( const PathVector paths,
const Path path 
)

Find a sub directory in a vector of paths.

Parameters
[in]pathsThe list of paths to search in.
[in]pathThe sub path to find.

A sub directory structure can be given e.g.

findDirectory(paths, "resource/MyResourceFolder/")
Exceptions
XIOif no directory was found
Returns
The path to the found sub directory.

◆ findProjectDirectory()

MIRA_BASE_EXPORT Path mira::findProjectDirectory ( const Path path)

Same as findDirectory above, but using all of the paths contained in $MIRA_PATH variable.

◆ findContainingMIRAPath()

MIRA_BASE_EXPORT Path mira::findContainingMIRAPath ( const Path path)

Returns the MIRA path that contains the given path.

Parameters
[in]paththe path to be processed
Returns
the mira path that contains the given path
Exceptions
XLogicalif path is not located in one of the MIRA paths

◆ chopMIRAPath()

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.:

chopMIRAPath('/home/user/mira/some/sub/folder')

will return 'some/sub/folder' if '/home/user/mira' is set as MIRA path.

Parameters
[in]paththe path to be processed
Returns
the relative path from the containing mira folder to the given path
Exceptions
XLogicalif path is not located in one of the MIRA paths

◆ findDirectories() [1/2]

MIRA_BASE_EXPORT PathVector mira::findDirectories ( const PathVector paths,
const Path path,
bool  recursive = false 
)

Finds all sub directories in a vector of paths.

Parameters
[in]pathsThe list of paths to search in.
[in]pathThe sub path to find.
[in]recursiveFlag for recursive search.

A sub directory structure can be given e.g.

findDirectories(paths, "resource/MyResourceFolder/").

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.

  • if recursive = true it will also search for all occurrences of resource/MyResourceFolder/ in all sub directories of /usr/local/MyProject and /usr/local/AnotherProject i.e. it will also find /usr/local/MyProject/AnotherFolder/SubFolder/resource/MyResourceFolder/
  • if recursive = false it will only find all directories that match the combination of paths[X]/path e.g. in the above example it would find exactly 2 directories /usr/local/MyProject/resource/MyResourceFolder/ and /usr/local/AnotherProject/resource/MyResourceFolder/
Returns
All the found directories.

◆ findDirectories() [2/2]

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.

◆ findProjectDirectories()

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.

◆ findProjectPath()

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:

  • 1. findProjectFile, if no file found
  • 2. findProjectDirectory, if no directory found
  • 3. findProjectFiles recursively in all subdirs, if no file found
  • 4. findProjectDirectories recursively in all subdirs
    Exceptions
    XIOIf no file or directory is found or multiple matches are found
    Parameters
    pathThe path to be found
    Returns
    The found file or directory