VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Static Public Member Functions
makVrv::DtVrvFilesystem Class Reference

The DtVrvFilesystem is a wrapper around boost functions that are know to throw exceptions. More...

Static Public Member Functions

static bool createAllDirectories (const std::string &dirPath)
 Creates all the directories from parent to child.
static std::string absolutePath (const std::string &path)
 Get an absolute path from a relative path.
static DtUnicode absolutePath (const DtUnicode &path)
 Get an absolute path from a relative path.
static std::string cleanPath (const std::string &path)
 Clean a path by resolving embedded relative parts and correcting for inconsistent slashes.
static DtUnicode cleanPath (const DtUnicode &path)
 Clean a path by resolving embedded relative parts and correcting for inconsistent slashes.
static bool getFilePathsWithExtension (const std::string &rootDir, const std::string &ext, std::vector< std::string > &ret)
 Given a path and an extension, return a vector of file paths ex.
static bool getFilePathsWithExtension (const std::vector< std::string > &fileOrDirVec, const std::string &ext, std::vector< std::string > &ret)
 Given a vector of paths (file or dir) and an extension, return a vector of file paths ex.
static bool getFilePathsInDir (const std::string &rootDir, std::vector< std::string > &ret)
 Given a path return a vector of files paths underneath a directory ex.
static bool dirExistsNotEmpty (const std::string &rootDir)
 Given a directory return if the directory exists and is not empty.
static bool isAbsolutePath (const std::string &path)
 Check if the given path is an absolute path.
static bool exists (const std::string &path)
 Check if the given path is exists.
static std::string fileName (const std::string &path)
static bool exists (const boost::filesystem::path &path)
 Check if the given path is exists.
static bool equivalent (const std::string &path1, const std::string &path2)
 Check if the two given paths are equivalent.
static std::string makeRelative (const std::string &root, const std::string &path)
 Resolve a given path into a relative path based on a specific root.
static std::string setExtension (std::string file, std::string ext)
 Set a new extension to a file name.
static std::string addExtension (std::string file, std::string ext)
 Append a new extension to a file name.
static std::string extension (const std::string &file, bool withDot=false)
 Get the extension from a file path.
static std::string extensionCaseSensitive (std::string file, bool withDot=false)
 Get the extension from a file path.
static std::string baseName (const std::string &file)
 Get the base name of a file, excluding the file path and extension.
static std::string directoryOfFile (const std::string &file)
 Get the directory path containing the existing file.
static std::string directoryOfPath (const std::string &file)
 Get the directory path of a file.
static std::string rootDirectoryOfPath (const std::string &file)
 Get the root of the given directory.
static std::string nativePath (const std::string &path)
 Convert the path to the native format of the platform.
static DtUnicode nativePath (const DtUnicode &path)
 Convert the path to the native format of the platform.
static bool is_directory (const std::string &path)
 Test whether the path is a directory or not.
static bool is_directory (const boost::filesystem::path &path)
 Test whether the path is a directory or not.
static bool deleteFile (const std::string &file)
 Delete the given file.
static bool deleteDirectory (const std::string &dir)
 Delete the given directory.
template<typename PathCollection >
static bool findFile (const std::string &filePathIn, const PathCollection &paths, std::string &actualFilePathOut)
 Find a file in a list of paths.
static bool findFileInPath (const std::string &filePathIn, const std::string &path, std::string &actualFilePathOut)
 Find the file in a path.
static unsigned int makeAndXorHash (const std::string &filePath)
 utility function

Detailed Description

The DtVrvFilesystem is a wrapper around boost functions that are know to throw exceptions.

These functions are all reentrent* however the working directory should not be changed.

Member Function Documentation

static bool makVrv::DtVrvFilesystem::createAllDirectories ( const std::string &  dirPath)
static

Creates all the directories from parent to child.

Parameters
[in]dirPathis the directory path to create.
Return values
trueif the directory path was successfully constructed.
falseotherwise.
static std::string makVrv::DtVrvFilesystem::absolutePath ( const std::string &  path)
static

Get an absolute path from a relative path.

This function resolves a relative path to an absolute path and converts inconsistent slashes to the native format.

Parameters
[in]pathis the relative path to convert.
Returns
The absolute path resolved from a relative path, or an empty string if the absolute path could not be found.
Note
This function does not test existence of the path.
This function is not thread safe.
See Also
cleanPath(const std::string& path)
static DtUnicode makVrv::DtVrvFilesystem::absolutePath ( const DtUnicode path)
static

Get an absolute path from a relative path.

This function resolves a relative path to an absolute path and converts inconsistent slashes to the native format.

Parameters
[in]pathis the relative path to convert.
Returns
The absolute path resolved from a relative path, or an empty string if the absolute path could not be found.
Note
This function does not test existence of the path.
This function is not thread safe.
See Also
cleanPath(const DtUnicode& path)
static std::string makVrv::DtVrvFilesystem::cleanPath ( const std::string &  path)
static

Clean a path by resolving embedded relative parts and correcting for inconsistent slashes.

Parameters
[in]pathis the relative or absolute path to clean.
Returns
The corrected relative or absolute path, or an empty string on failure.
Note
This function does not test existence of the path.
This function is not thread safe.
See Also
absolutePath(const std::string& path)
static DtUnicode makVrv::DtVrvFilesystem::cleanPath ( const DtUnicode path)
static

Clean a path by resolving embedded relative parts and correcting for inconsistent slashes.

Parameters
[in]pathis the relative or absolute path to clean.
Returns
The corrected relative or absolute path, or an empty string on failure.
Note
This function does not test existence of the path.
This function is not thread safe.
See Also
absolutePath(const DtUnicode& path)
static bool makVrv::DtVrvFilesystem::getFilePathsWithExtension ( const std::string &  rootDir,
const std::string &  ext,
std::vector< std::string > &  ret 
)
static

Given a path and an extension, return a vector of file paths ex.

c:*.jpg -> "c:\adir\a.jpg", "c:\adir\b.jpg" ... for files that match that extension

Parameters
[in]diris the relative or absolute dir
[in]extis the file extension to look for (ex. 'jpg')
[out]retis a list of file paths that have the extension
Return values
trueif at least one file was found
falseit no files were found
Note
This function is not thread safe.
if the path is not a directory, return false
ext should be 'jpg' and not '.jpg', the . is added in the function
static bool makVrv::DtVrvFilesystem::getFilePathsWithExtension ( const std::vector< std::string > &  fileOrDirVec,
const std::string &  ext,
std::vector< std::string > &  ret 
)
static

Given a vector of paths (file or dir) and an extension, return a vector of file paths ex.

ext="jpg" 'c:\','c:.bmp','c:.jpg' -> "c:\adir\a.jpg", "c:\b.jpg" ... for files that match that extension

Parameters
[in]vectorof files or dirs (relative or absolute dirs)
[in]extis the file extension to look for (ex. 'jpg')
[out]retis a list of file paths that have the extension
Return values
trueif at least one file was found
falseit no files were found
Note
This function is not thread safe.
ext should be 'jpg' and not '.jpg', the . is added in the function
static bool makVrv::DtVrvFilesystem::getFilePathsInDir ( const std::string &  rootDir,
std::vector< std::string > &  ret 
)
static

Given a path return a vector of files paths underneath a directory ex.

c:\ -> "c:\adir\a.jpg", "c:\adir\b.jpg" ...

Parameters
[in]pathis the relative or absolute path
[out]retis a list of file paths found
Return values
trueif at least one file was found
falseit no files were found
Note
if the path is not a directory, return false
This function is not thread safe.
static bool makVrv::DtVrvFilesystem::dirExistsNotEmpty ( const std::string &  rootDir)
static

Given a directory return if the directory exists and is not empty.

Parameters
[in]diris the relative or absolute path
Return values
trueif at least one file was found
falseit no files were found
Note
if the path is not a directory, return false
This function is not thread safe.
static bool makVrv::DtVrvFilesystem::isAbsolutePath ( const std::string &  path)
static

Check if the given path is an absolute path.

Parameters
[in]pathis the path to check.
Return values
trueif the given path is already absolute.
falseotherwise or failure to check.
Note
This function does not test existence of the path.
This function is not thread safe.
static bool makVrv::DtVrvFilesystem::exists ( const std::string &  path)
static

Check if the given path is exists.

Parameters
[in]pathis the path to check.
Return values
trueif the given path exists in the filesystem.
falseotherwise or failure to check.

Referenced by makVrv::DtManagerBackup< Manager >::backupDirExists(), makVrv::DtManagerBackup< Manager >::backupFileExists(), makVrv::DtManagerBackup< Manager >::factoryDirExists(), makVrv::DtManagerBackup< Manager >::factoryFileExists(), and findFile().

static std::string makVrv::DtVrvFilesystem::fileName ( const std::string &  path)
static
Parameters
[in]pathis the (possibly) full/relative path with file name
Return values
filename including extension
static bool makVrv::DtVrvFilesystem::exists ( const boost::filesystem::path &  path)
static

Check if the given path is exists.

Parameters
[in]pathis the path to check.
Return values
trueif the given path exists in the filesystem.
falseotherwise or failure to check.
static bool makVrv::DtVrvFilesystem::equivalent ( const std::string &  path1,
const std::string &  path2 
)
static

Check if the two given paths are equivalent.

This checks that two given paths, whether relative or absolute, both resolve to the same directory or file location.

Parameters
[in]path1is the first path to check.
[in]path2is the second path to check.
Return values
trueif both paths resolve to the same location.
falseotherwise or failure to check.
Note
This function does not test existence of either path.
static std::string makVrv::DtVrvFilesystem::makeRelative ( const std::string &  root,
const std::string &  path 
)
static

Resolve a given path into a relative path based on a specific root.

Using a root path location, a given path is converted to a new path relative to that root location.

For example: if the root is "C:\test" and path is "C:\temp\file.txt", the resulting path returned would be "..\file.txt".

The given root and given path values can be relative or absolute file or directory paths. If relative paths are given they are first converted to absolute paths from the current working directory.

Parameters
[in]rootis the root path to base the relative path from.
[in]pathis the path to convert to a relative path.
Returns
The given path converted to a relative path from the root.
Note
If the given root and path are on different devices, such as on different Windows disk drives, an absolute path is returned.
This function does not test existence of either path.
static std::string makVrv::DtVrvFilesystem::setExtension ( std::string  file,
std::string  ext 
)
static

Set a new extension to a file name.

If an extension already exists, it is changed to the new extension. If the file does not have an extension the new extension is appended.

Parameters
[in]fileis the path or name of the file.
[in]extis the extension to set on the filename.
Returns
The filename with the given extension.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::addExtension ( std::string  file,
std::string  ext 
)
static

Append a new extension to a file name.

If an existing extension to the file is the same as the given extension, the file is returned unchanged. If the given file or extension are invalid values, the file is returned unchanged.

Parameters
[in]fileis the path or name of the file.
[in]extis the extension to append to the filename.
Returns
The filename appended with the given extension.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::extension ( const std::string &  file,
bool  withDot = false 
)
static

Get the extension from a file path.

The case of the returned extension is converted to lowercase.

Parameters
[in]fileis the path or name of the file.
[in]withDotis a flag indicating the extension should or should not include the leading dot character.
Returns
The extension of the filename.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::extensionCaseSensitive ( std::string  file,
bool  withDot = false 
)
static

Get the extension from a file path.

The case of the returned extension is preserved.

Parameters
[in]fileis the path or name of the file.
[in]withDotis a flag indicating the extension should or should not include the leading dot character.
Returns
The extension of the filename.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::baseName ( const std::string &  file)
static

Get the base name of a file, excluding the file path and extension.

For example: ...txt -> test

Parameters
[in]fileis the path or name of the file.
Returns
The base name of the file.
static std::string makVrv::DtVrvFilesystem::directoryOfFile ( const std::string &  file)
static

Get the directory path containing the existing file.

For example: ...txt -> ..

Parameters
[in]fileis the path and name of the file.
Returns
The parent directory path to the file or an empty string if the file does not exist.
static std::string makVrv::DtVrvFilesystem::directoryOfPath ( const std::string &  file)
static

Get the directory path of a file.

For example: ...txt -> ..

Parameters
[in]fileis the path and name of the file.
Returns
The parent directory path to the file.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::rootDirectoryOfPath ( const std::string &  file)
static

Get the root of the given directory.

For example: data\file\test.text -> data

Parameters
[in]fileis the file path to get the root directory from
Returns
The root directory from the file path.
Note
This function does not test existence of the file.
static std::string makVrv::DtVrvFilesystem::nativePath ( const std::string &  path)
static

Convert the path to the native format of the platform.

Parameters
[in]pathis the path to be converted.
Returns
The path converted into the native format.
Note
This function does not test existence of the path.
static DtUnicode makVrv::DtVrvFilesystem::nativePath ( const DtUnicode path)
static

Convert the path to the native format of the platform.

Parameters
[in]pathis the path to be converted.
Returns
The path converted into the native format.
Note
This function does not test existence of the path.
static bool makVrv::DtVrvFilesystem::is_directory ( const std::string &  path)
static

Test whether the path is a directory or not.

Parameters
[in]pathis the path to be tested.
Return values
trueif the path is a directory and exists.
falseotherwise.
static bool makVrv::DtVrvFilesystem::is_directory ( const boost::filesystem::path &  path)
static

Test whether the path is a directory or not.

Parameters
[in]pathis the path to be tested.
Return values
trueif the path is a directory and exists.
falseotherwise.
static bool makVrv::DtVrvFilesystem::deleteFile ( const std::string &  file)
static

Delete the given file.

Parameters
[in]fileis the file to be deleted.
Return values
trueif the file was successfully deleted.
falseotherwise.

Referenced by makVrv::DtManagerBackup< Manager >::deleteBackup().

static bool makVrv::DtVrvFilesystem::deleteDirectory ( const std::string &  dir)
static

Delete the given directory.

Parameters
[in]diris the directory to be deleted.
Return values
trueif the file was successfully deleted.
falseotherwise.
template<typename PathCollection >
static bool makVrv::DtVrvFilesystem::findFile ( const std::string &  filePathIn,
const PathCollection &  paths,
std::string &  actualFilePathOut 
)
inlinestatic

Find a file in a list of paths.

Iterate through a list of paths and attempt to find a file within one of the paths. The first location found in the iteration is returned.

Parameters
[in]filePathInis a file or filepath to find.
[in]pathsis a list of paths to check for the file.
[out]actualFilePathOutis the filepath where the file was found.
Return values
trueif the file exists and was found in one of the paths.
falseotherwise.

References exists().

static bool makVrv::DtVrvFilesystem::findFileInPath ( const std::string &  filePathIn,
const std::string &  path,
std::string &  actualFilePathOut 
)
static

Find the file in a path.

This test tries to find an existing file in a given path. The given filepath is first tested as is within the given path, and on failure, the the filename (stripped of any file path) is then tested within the given path.

Parameters
[in]filePathInis a file or filepath to find.
[in]pathis the path to check for the file or filepath.
[out]actualFilePathOutis the filepath where the file was found.
Return values
trueif the file exists and was found.
falseotherwise.
static unsigned int makVrv::DtVrvFilesystem::makeAndXorHash ( const std::string &  filePath)
static

utility function


The documentation for this class was generated from the following file:

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)