#include <FileFinder.hpp>
Inherited by HeartFileFinder.
Public Member Functions | |
FileFinder () | |
FileFinder (const std::string &rPath, RelativeTo::Value relativeTo) | |
FileFinder (const std::string &rLeafName, const FileFinder &rParentOrSibling) | |
void | SetPath (const std::string &rPath, RelativeTo::Value relativeTo) |
void | SetPath (const std::string &rLeafName, const FileFinder &rParentOrSibling) |
bool | Exists () const |
bool | IsFile () const |
bool | IsDir () const |
std::string | GetAbsolutePath () const |
bool | IsNewerThan (const FileFinder &rOtherEntity) const |
std::string | GetLeafName () const |
FileFinder | GetParent () const |
Static Public Member Functions | |
static bool | IsAbsolutePath (const 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 59 of file FileFinder.hpp.
FileFinder::FileFinder | ( | ) |
Default constructor for subclasses to use. They must call SetAbsolutePath() 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 45 of file FileFinder.cpp.
Referenced by 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 50 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 55 of file FileFinder.cpp.
References SetPath().
bool FileFinder::Exists | ( | ) | const |
Test whether we exist.
Definition at line 128 of file FileFinder.cpp.
References GetAbsolutePath().
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::Convert(), HeartConfig::CopySchema(), BidomainTissue< SPACE_DIM >::CreateExtracellularConductivityTensors(), AbstractCardiacTissue< ELEMENT_DIM, SPACE_DIM >::CreateIntracellularConductivityTensor(), IsNewerThan(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), 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 206 of file FileFinder.cpp.
References msFakePath, msFakeWhat, and msFaking.
std::string FileFinder::GetAbsolutePath | ( | ) | const |
Get the absolute path to this file/dir.
If this is a directory that exists, the absolute path is guaranteed to end in a '/'. If the directory doesn't exist, it will depend on what was supplied to the constructor.
Definition at line 169 of file FileFinder.cpp.
References mAbsPath.
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::Convert(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), OutputFileHandler::CopyFileTo(), HeartConfig::CopySchema(), Exists(), FibreReader< DIM >::FibreReader(), GetLeafName(), DynamicModelLoaderRegistry::GetLoader(), GetParent(), IsDir(), IsFile(), IsNewerThan(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), AbstractCardiacTissue< SPACE_DIM >::save(), ArchiveLocationInfo::SetArchiveDirectory(), SetPath(), and AbstractTetrahedralMeshWriter< ELEMENT_DIM, SPACE_DIM >::WriteNclFile().
std::string FileFinder::GetLeafName | ( | ) | const |
Get the leaf name of this file or directory.
Definition at line 184 of file FileFinder.cpp.
References EXCEPT_IF_NOT, and GetAbsolutePath().
Referenced by OutputFileHandler::CopyFileTo().
FileFinder FileFinder::GetParent | ( | ) | const |
Get a finder for the folder containing this file or directory.
Definition at line 192 of file FileFinder.cpp.
References RelativeTo::Absolute, EXCEPT_IF_NOT, FileFinder(), and GetAbsolutePath().
Referenced by SetPath().
bool FileFinder::IsAbsolutePath | ( | const std::string & | rPath | ) | [static] |
Test whether a path is absolute. Currently just checks whether the first character is '/'.
rPath | The path to test |
Definition at line 201 of file FileFinder.cpp.
Referenced by ExtendedBidomainProblem< DIM >::load(), AbstractCardiacProblem< ELEMENT_DIM, ELEMENT_DIM, 1 >::load(), ArchiveLocationInfo::SetMeshPathname(), and SetPath().
bool FileFinder::IsDir | ( | ) | const |
Are we pointing at a directory?
Definition at line 152 of file FileFinder.cpp.
References GetAbsolutePath().
Referenced by ColumnDataReader::ColumnDataReader(), Hdf5DataReader::CommonConstructor(), CellMLToSharedLibraryConverter::ConvertCellmlToSo(), CardiacSimulationArchiver< PROBLEM_CLASS >::Migrate(), and SetPath().
bool FileFinder::IsFile | ( | ) | const |
Are we pointing at a file?
Definition at line 135 of file FileFinder.cpp.
References GetAbsolutePath().
Referenced by OutputFileHandler::CopyFileTo().
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 174 of file FileFinder.cpp.
References Exists(), and GetAbsolutePath().
Referenced by CellMLToSharedLibraryConverter::Convert().
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 112 of file FileFinder.cpp.
References RelativeTo::Absolute, EXCEPTION, Exists(), GetAbsolutePath(), GetParent(), IsDir(), and SetPath().
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 60 of file FileFinder.cpp.
References RelativeTo::Absolute, RelativeTo::AbsoluteOrCwd, ChasteBuildRootDir(), RelativeTo::ChasteSourceRoot, RelativeTo::ChasteTestOutput, RelativeTo::CWD, OutputFileHandler::GetChasteTestOutputDirectory(), IsAbsolutePath(), IsDir(), mAbsPath, msFakePath, msFakeWhat, msFaking, and NEVER_REACHED.
Referenced by HeartConfig::CopySchema(), FileFinder(), HeartFileFinder::HeartFileFinder(), HeartConfig::SetParametersFile(), and SetPath().
void FileFinder::StopFaking | ( | ) | [static] |
Stop faking one of the fixed paths.
Definition at line 213 of file FileFinder.cpp.
References msFaking.
std::string FileFinder::mAbsPath [private] |
The absolute path to our file.
Definition at line 64 of file FileFinder.hpp.
Referenced by GetAbsolutePath(), and SetPath().
std::string FileFinder::msFakePath = "" [static, private] |
The fake value of the faked path.
Definition at line 73 of file FileFinder.hpp.
Referenced by FakePath(), and SetPath().
RelativeTo::Value FileFinder::msFakeWhat = RelativeTo::Absolute [static, private] |
Which path to fake.
Definition at line 70 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 67 of file FileFinder.hpp.
Referenced by FakePath(), SetPath(), and StopFaking().