Mēnsūra
|
Allows to resolve a (possibly) relative file path w.r.t. to several possible locations. More...
#include <FileInPath.hpp>
Public Member Functions | |
FileInPath (FileInPath const &)=delete | |
Copy constructor is distabled because this is a singleton. | |
FileInPath & | operator= (FileInPath const &)=delete |
Assignment operator is disabled because this is a singleton. | |
Static Public Member Functions | |
static void | AddLocation (std::string path) |
Adds a new location in which files with be searched. More... | |
static std::string | Resolve (std::string subDir, std::string const &path) |
Resolves a path, allowing for an optional subdirectory. More... | |
static std::string | Resolve (std::string const &path) |
Resolves a path. More... | |
Allows to resolve a (possibly) relative file path w.r.t. to several possible locations.
One location, $MENSURA_INSTALL/data/, is included by default. User can add other locations if needed.
This class is a singleton, and thus user cannot constract an instance of it. Instead, all functionality is implemented in static methods.
|
static |
Adds a new location in which files with be searched.
The new location takes preference over all paths added previously. This method is not guaranteed to be thread-safe.
|
static |
Resolves a path, allowing for an optional subdirectory.
If the path starts with "/", "./", or "../", it is treated as an absolute or explicit relative path and returned unchanched after verifying that such file exists. Otherwise the method tries to resolve it with respect to all defined locations, in a reversed order of their definition. For each location, provided subdirectory is first added to it, and the resolution is attempted. If such file is not found, the subdirectory is omitted, and the resolution is attempted again. Finally, the file is searched for in the current working directory (the one in which the executable is being run), with and without the subdirectory. If all attempts to find the file fail, an exception is thrown.
|
static |
Resolves a path.
Works in the same way as the above version but does not include the additional subdirectory.