Chaste Release::3.1
|
#include <FileFinder.hpp>
Public Member Functions | |
FileFinder () | |
FileFinder (const std::string &rPath, RelativeTo::Value relativeTo) | |
FileFinder (const std::string &rLeafName, const FileFinder &rParentOrSibling) | |
FileFinder (const fs::path &rPath) | |
void | SetPath (const std::string &rPath, RelativeTo::Value relativeTo) |
bool | IsPathSet () const |
void | SetPath (const std::string &rLeafName, const FileFinder &rParentOrSibling) |
bool | Exists () const |
bool | IsFile () const |
bool | IsDir () const |
bool | IsEmpty () const |
std::string | GetAbsolutePath () const |
bool | IsNewerThan (const FileFinder &rOtherEntity) const |
std::string | GetLeafName () const |
std::string | GetLeafNameNoExtension () const |
std::string | GetExtension () const |
FileFinder | GetParent () const |
std::string | GetRelativePath (const FileFinder &rBasePath) const |
FileFinder | CopyTo (const FileFinder &rDest) const |
void | Remove (bool force=false) const |
std::vector< FileFinder > | FindMatches (const std::string &rPattern) const |
Static Public Member Functions | |
static bool | IsAbsolutePath (const std::string &rPath) |
static void | ReplaceSpacesWithUnderscores (std::string &rPath) |
static void | ReplaceUnderscoresWithSpaces (std::string &rPath) |
static void | FakePath (RelativeTo::Value fakeWhat, const std::string &rFakePath) |
static void | StopFaking () |
Private Attributes | |
std::string | mAbsPath |
Static Private Attributes | |
static bool | msFaking = false |
static RelativeTo::Value | msFakeWhat = RelativeTo::Absolute |
static std::string | msFakePath = "" |
A helper class for finding files or directories, given paths which can be relative to various locations (e.g. the Chaste source tree root, the current directory, the Chaste test output directory, or an absolute path).
Definition at line 68 of file FileFinder.hpp.
FileFinder::FileFinder | ( | ) |
Default constructor for subclasses to use. They must call SetPath() in their constructor.
This also allows classes to store a FileFinder instance that hasn't been properly set up yet, and assign to it later using operator=.
Definition at line 56 of file FileFinder.cpp.
Referenced by CopyTo(), FindMatches(), and GetParent().
FileFinder::FileFinder | ( | const std::string & | rPath, |
RelativeTo::Value | relativeTo | ||
) |
Main constructor.
rPath | the path to the file/dir to find |
relativeTo | how to interpret this path |
Definition at line 61 of file FileFinder.cpp.
References SetPath().
FileFinder::FileFinder | ( | const std::string & | rLeafName, |
const FileFinder & | rParentOrSibling | ||
) |
Find a file (or folder) relative to some file or directory. If the second argument is a directory, we look for the given leaf name within it. If the second argument is a file, then we look for a sibling. An exception is raised if rParentOrSibling does not exist.
rLeafName | the leaf name of the file/dir to find |
rParentOrSibling | where to look for it |
Definition at line 66 of file FileFinder.cpp.
References SetPath().
FileFinder::FileFinder | ( | const fs::path & | rPath | ) |
Conversion constructor from a Boost Filesystem path object. Note that since fs::path has a conversion constructor from std::string, this allows us to be initialised with a string or character constant, too. The path will be interpreted as relative to the current working directory, unless it is an absolute path.
rPath | the path to the file/dir to find |
Definition at line 71 of file FileFinder.cpp.
References RelativeTo::Absolute, and SetPath().
FileFinder FileFinder::CopyTo | ( | const FileFinder & | rDest | ) | const |
Copy this file to the given destination. The destination may be a folder, or destination file name. Only single files may be copied, not whole folders.
rDest | where to copy to |
Definition at line 245 of file FileFinder.cpp.
References EXCEPTION, Exists(), FileFinder(), IsDir(), IsFile(), and mAbsPath.
Referenced by AbstractTetrahedralMesh< SPACE_DIM, SPACE_DIM >::save().
bool FileFinder::Exists | ( | ) | const |
Test whether we exist.
Definition at line 152 of file FileFinder.cpp.
References mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), OutputFileHandler::CommonConstructor(), CellMLToSharedLibraryConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), HeartConfig::CopySchema(), CopyTo(), BidomainTissue< SPACE_DIM >::CreateExtracellularConductivityTensors(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::CreateIntracellularConductivityTensor(), Hdf5DataWriter::Hdf5DataWriter(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::InitialiseWriter(), IsNewerThan(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), Remove(), AbstractCardiacTissue< SPACE_DIM >::save(), and SetPath().
void FileFinder::FakePath | ( | RelativeTo::Value | fakeWhat, |
const std::string & | rFakePath | ||
) | [static] |
For testing purposes, fake the value of one of the normally fixed paths, e.g. ChasteSourceRoot.
fakeWhat | which path to fake |
rFakePath | its fake value |
Definition at line 448 of file FileFinder.cpp.
References msFakePath, msFakeWhat, and msFaking.
std::vector< FileFinder > FileFinder::FindMatches | ( | const std::string & | rPattern | ) | const |
Find files in this folder matching a simple glob pattern. This method must be called on a FileFinder that points at a folder, and the pattern will be matched against file (or folder) names in that folder. The pattern can use a subset of shell-style glob syntax. A '?' anywhere in the string matches any single character at that position. A '*' may be used at the start or end of the string to match any number of leading or trailing characters, respectively. Hidden files (names starting with a '.') will never be matched.
rPattern | the pattern to match names against |
Definition at line 327 of file FileFinder.cpp.
References EXCEPTION, FileFinder(), IsDir(), and mAbsPath.
Referenced by CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), HoneycombMeshGenerator::HoneycombMeshGenerator(), and AbstractTetrahedralMesh< SPACE_DIM, SPACE_DIM >::save().
std::string FileFinder::GetAbsolutePath | ( | ) | const |
Get the absolute path to this file/dir.
If this is a directory that exists (at the instant of this call), the absolute path is guaranteed to end in a '/'. Otherwise, the path is guaranteed not to end in a '/'.
Definition at line 193 of file FileFinder.cpp.
References IsDir(), and mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), OutputFileHandler::CopyFileTo(), HeartConfig::CopySchema(), FibreReader< DIM >::FibreReader(), OutputFileHandler::GetChasteTestOutputDirectory(), ElectroMechanicsProblemDefinition< DIM >::GetFibreSheetDirectionsFile(), DynamicModelLoaderRegistry::GetLoader(), GetRelativePath(), AbstractCardiacProblem< ELEMENT_DIM, SPACE_DIM, PROBLEM_DIM >::InitialiseWriter(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), OutputFileHandler::OutputFileHandler(), Remove(), AbstractCardiacTissue< SPACE_DIM >::save(), ArchiveLocationInfo::SetArchiveDirectory(), SetPath(), AbstractCardiacMechanicsSolver< ELASTICITY_SOLVER, DIM >::SetVariableFibreSheetDirections(), and AbstractTetrahedralMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteNclFile().
std::string FileFinder::GetExtension | ( | ) | const |
Get the extension of the leaf name of this file or directory, if any. The '.' will be included in the extension if an extension exists.
Definition at line 219 of file FileFinder.cpp.
References mAbsPath.
Referenced by AbstractTetrahedralMesh< SPACE_DIM, SPACE_DIM >::save().
std::string FileFinder::GetLeafName | ( | ) | const |
Get the leaf name of this file or directory.
i.e. the individual file or directory name and none of the preceeding folders on its path.
Definition at line 209 of file FileFinder.cpp.
References mAbsPath.
Referenced by CellMLLoader::LoadCellMLFile().
std::string FileFinder::GetLeafNameNoExtension | ( | ) | const |
Get the leaf name of this file or directory, with any file extension removed.
i.e. the individual file or directory name and none of the preceeding folders on its path.
Definition at line 214 of file FileFinder.cpp.
References mAbsPath.
Referenced by CellMLLoader::LoadCellMLFile(), and AbstractTetrahedralMesh< SPACE_DIM, SPACE_DIM >::save().
FileFinder FileFinder::GetParent | ( | ) | const |
Get a finder for the folder containing this file or directory.
Definition at line 224 of file FileFinder.cpp.
References RelativeTo::Absolute, EXCEPT_IF_NOT, FileFinder(), and mAbsPath.
Referenced by AbstractTetrahedralMesh< SPACE_DIM, SPACE_DIM >::save(), and SetPath().
std::string FileFinder::GetRelativePath | ( | const FileFinder & | rBasePath | ) | const |
Get the relative path to this finder from another. Throws if this is not found under rBasePath.
rBasePath | where the returned path should be relative to |
Definition at line 233 of file FileFinder.cpp.
References EXCEPTION, and GetAbsolutePath().
Referenced by OutputFileHandler::OutputFileHandler().
bool FileFinder::IsAbsolutePath | ( | const std::string & | rPath | ) | [static] |
Test whether a path is absolute.
rPath | the path to test |
Definition at line 421 of file FileFinder.cpp.
Referenced by OutputFileHandler::CommonConstructor(), ExtendedBidomainProblem< DIM >::load(), AbstractCardiacProblem< DIM, DIM, 1 >::load(), ArchiveLocationInfo::SetMeshPathname(), ExecutableSupport::SetOutputDirectory(), and SetPath().
bool FileFinder::IsDir | ( | ) | const |
Are we pointing at a directory?
Definition at line 162 of file FileFinder.cpp.
References mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), CopyTo(), FindMatches(), GetAbsolutePath(), IsEmpty(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), and SetPath().
bool FileFinder::IsEmpty | ( | ) | const |
bool FileFinder::IsFile | ( | ) | const |
Are we pointing at a file?
Definition at line 157 of file FileFinder.cpp.
References mAbsPath.
Referenced by OutputFileHandler::CopyFileTo(), CopyTo(), IsEmpty(), and Remove().
bool FileFinder::IsNewerThan | ( | const FileFinder & | rOtherEntity | ) | const |
Test whether this file/dir is newer than another file/dir. Compares modification times.
rOtherEntity | the entity to test against. |
Definition at line 202 of file FileFinder.cpp.
References Exists(), and mAbsPath.
Referenced by CellMLToSharedLibraryConverter::Convert().
bool FileFinder::IsPathSet | ( | ) | const |
Test whether this FileFinder has been given a path.
Definition at line 131 of file FileFinder.cpp.
References mAbsPath.
Referenced by ExecutableSupport::InitializePetsc(), ExecutableSupport::PrintError(), ExecutableSupport::WriteMachineInfoFile(), and ExecutableSupport::WriteProvenanceInfoFile().
void FileFinder::Remove | ( | bool | force = false | ) | const |
Recursively remove this file or folder. Since this is a potentially very dangerous operation, only locations under the Chaste test output folder may be removed. In addition, unless the optional parameter is true, only folders created by an OutputFileHandler, or the contents of such a folder, may be deleted.
force | whether to allow deletion of content not created by an OutputFileHandler |
Definition at line 289 of file FileFinder.cpp.
References EXCEPTION, Exists(), GetAbsolutePath(), OutputFileHandler::GetChasteTestOutputDirectory(), IsFile(), mAbsPath, and OutputFileHandler::SIG_FILE_NAME.
Referenced by CylindricalHoneycombMeshGenerator::CylindricalHoneycombMeshGenerator(), and HoneycombMeshGenerator::HoneycombMeshGenerator().
void FileFinder::ReplaceSpacesWithUnderscores | ( | std::string & | rPath | ) | [static] |
Replace any spaces in a path or filename with underscores.
rPath | a path or file name |
Definition at line 426 of file FileFinder.cpp.
void FileFinder::ReplaceUnderscoresWithSpaces | ( | std::string & | rPath | ) | [static] |
Replace any underscores in a path or filename with spaces (for making titles etc.).
rPath | a path or file name |
Definition at line 437 of file FileFinder.cpp.
void FileFinder::SetPath | ( | const std::string & | rPath, |
RelativeTo::Value | relativeTo | ||
) |
Change this FileFinder to point at a new location.
rPath | the path to the file/dir to find |
relativeTo | how to interpret this path |
Definition at line 76 of file FileFinder.cpp.
References RelativeTo::Absolute, RelativeTo::AbsoluteOrCwd, ChasteBuildRootDir(), RelativeTo::ChasteSourceRoot, RelativeTo::ChasteTestOutput, RelativeTo::CWD, OutputFileHandler::GetChasteTestOutputDirectory(), IsAbsolutePath(), mAbsPath, msFakePath, msFakeWhat, msFaking, and NEVER_REACHED.
Referenced by HeartConfig::CopySchema(), FileFinder(), OutputFileHandler::GetChasteTestOutputDirectory(), HeartFileFinder::HeartFileFinder(), ExecutableSupport::InitializePetsc(), HeartConfig::LoadFromCheckpoint(), ExecutableSupport::PrintError(), ExecutableSupport::SetOutputDirectory(), HeartConfig::SetParametersFile(), SetPath(), ExecutableSupport::WriteMachineInfoFile(), and ExecutableSupport::WriteProvenanceInfoFile().
void FileFinder::SetPath | ( | const std::string & | rLeafName, |
const FileFinder & | rParentOrSibling | ||
) |
Change this FileFinder to point at a new location, relative to some file or directory.
rLeafName | the leaf name of the file/dir to find |
rParentOrSibling | where to look for it |
Definition at line 136 of file FileFinder.cpp.
References RelativeTo::Absolute, EXCEPTION, Exists(), GetAbsolutePath(), GetParent(), IsDir(), and SetPath().
void FileFinder::StopFaking | ( | ) | [static] |
Stop faking one of the fixed paths.
Definition at line 455 of file FileFinder.cpp.
References msFaking.
std::string FileFinder::mAbsPath [private] |
The absolute path to our file.
Definition at line 271 of file FileFinder.hpp.
Referenced by CopyTo(), Exists(), FindMatches(), GetAbsolutePath(), GetExtension(), GetLeafName(), GetLeafNameNoExtension(), GetParent(), IsDir(), IsEmpty(), IsFile(), IsNewerThan(), IsPathSet(), Remove(), and SetPath().
std::string FileFinder::msFakePath = "" [static, private] |
The fake value of the faked path.
Definition at line 280 of file FileFinder.hpp.
Referenced by FakePath(), and SetPath().
RelativeTo::Value FileFinder::msFakeWhat = RelativeTo::Absolute [static, private] |
Which path to fake.
Definition at line 277 of file FileFinder.hpp.
Referenced by FakePath(), and SetPath().
bool FileFinder::msFaking = false [static, private] |
Whether to fake one of the fixed paths, e.g. ChasteSourceRoot.
Definition at line 274 of file FileFinder.hpp.
Referenced by FakePath(), SetPath(), and StopFaking().