G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsFileManager Class Reference

Detailed Description

File-system related functionality.

Input paths to the fuctions of this class can be given using any valid path seperator, this is in Unix only "/" and in Windows both "/" and "\\".

Return values only contain the preferred native path separator, which is in Unix "/" and in Windows "\\".

Output Paths always end with path separator, files without.

Does not check for special system cases, like AUX under Windows. (see https://en.wikipedia.org/wiki/Filename)

Static Public Member Functions

static bool addSearchPaths (const std::string &paths)
 Add more search paths Returns true iff paths exist.
 
static bool fileExists (const std::string &name)
 Checks if the file exists. More...
 
static bool fileExistsInDataDir (const std::string &name)
 Checks if the file exists in GISMO_DATA_DIR.
 
static std::string find (std::string fn)
 Find a file. More...
 
static std::string findInDataDir (std::string fn)
 Find a file in GISMO_DATA_DIR. More...
 
static std::string getBasename (std::string const &fn)
 Returns the base name without path and extension of the filename fn.
 
static std::string getCanonicRepresentation (const std::string &fn, bool asPath=false)
 Returns the canonic representation of the path fn. More...
 
static std::string getCurrentPath ()
 Get current directory.
 
static std::string getExePath ()
 Get path of executable (without filename)
 
static std::string getExtension (std::string const &fn)
 Returns the extension of the filename fn.
 
static std::string getFilename (std::string const &fn)
 Returns the filename without the path of fn.
 
static std::string getHomePath ()
 Get path to home directory.
 
static const std::string & getInvalidCharacters ()
 Get system-dependent invalid characters for paths and filenames.
 
static char getNativePathSeparator ()
 Get preferred native path seperator.
 
static std::string getPath (std::string const &fn, bool resolve=false)
 
static std::string getSearchPaths ()
 Get the defined search paths.
 
static std::string getTempPath ()
 Auto-detect temp directory.
 
static const std::string & getValidPathSeparators ()
 Get valid path seperators.
 
static bool isExplicitlyRelative (const std::string &fn)
 Checks if the path is a relative path Under Unix, if a name starts with "./" or "../", it is considered relative. Under Windows, if a name starts with "./", ".\\", "../" or "..\\", it is considered relative.
 
static bool isFullyQualified (const std::string &fn)
 Checks if the path is fully qualified, also known as "absolute path" Under Unix, if a name starts with "/", it is considered fully qualified. Under Windows, it starts with the drive-letter followed by the path or with a "/" or a "\\" (refers to the current drive).
 
static std::string makeRelative (const std::string &from, const std::string &to)
 
static bool mkdir (std::string fn)
 Make directory. More...
 
static void open (const std::string &fn)
 Opens the file fn using the preferred application of the OS.
 
static bool pathEqual (const std::string &p1, const std::string &p2)
 Checks paths for equality of paths. More...
 
static bool setSearchPaths (const std::string &paths)
 Set the search paths Returns true iff all paths exist.
 

Member Function Documentation

bool fileExists ( const std::string &  name)
static

Checks if the file exists.

If the fn isFullyQulaified (like "/foo/bar.txt"), or if the fn isExplicitlyRelative (like "../foo/bar.txt"), then only this path is considered.

If the fn has the form "bar.txt" or "foo/bar.txt", the file is searched in the current directory and all search paths (cf. getSearchPaths).

See Also
find
std::string find ( std::string  fn)
static

Find a file.

Parameters
fnThe filename
Returns
The full path or empty string

If the fn isFullyQualified (like "/foo/bar.txt"), or if the fn isExplicitlyRelative (like "../foo/bar.txt"), the name is returned unchanged* if the file can be found. Otherwise, an empty string is returned.

If the fn has the form "bar.txt" or "foo/bar.txt", the file is searched in the current directory and all search paths (cf. getSearchPaths). If the file can be found, the full path is returned. Otherwise, an empty string is returned.

*: In any case, slashes are replaced by the native path separator.

std::string findInDataDir ( std::string  fn)
static

Find a file in GISMO_DATA_DIR.

Parameters
fnThe filename
Returns
The full path or empty string

If the file can be found, returns the full path. Otherwise, returns empty string.

In any case, slashes are replaced by the native path separator.

std::string getCanonicRepresentation ( const std::string &  fn,
bool  asPath = false 
)
static

Returns the canonic representation of the path fn.

This reduces foo/baz/../bar or foo/./bar to foo/bar. Moreover, the non-preferred path separators are replaced by the preferred ones.

This does not access the file system, the current directory, or the search paths. Therefore, leading .. can't be replaced. Leading ./././ will be reduced to ./

Parameters
fninput path as std::string
asPathIf true, make sure the last character of the output is the native-path-separator. Else, let is as it was.
Returns
canonical representation of fn as std::string
std::string getPath ( std::string const &  fn,
bool  resolve = false 
)
static

Returns the path without filename fn. If resolve is set, it will resolve relative paths to absolute ones with use of find.

std::string makeRelative ( const std::string &  from,
const std::string &  to 
)
static

Calculates the relative path from absolute path from to path to. Example: from : /a/b/cd/ to : /a/b/c/d result: ../c/d Return an empty string, if from isn't absolute. Expands to with getCurrentPath if not absolute.

bool mkdir ( std::string  fn)
static

Make directory.

Return true iff directory is available after calling this function. (This also holds if the directory has existed already.) If a relative path is given as fn, it will be expanded with getCurrentDirectory.

bool pathEqual ( const std::string &  p1,
const std::string &  p2 
)
static

Checks paths for equality of paths.

If the path is not isFullyQualified, creates an absolute path using getCurrentPath. Then getCanonicRepresentation is called to get canonical representations which are compared.