MoReFEM
|
Namespace that enclose filesystem utilities (check a folder do exist, remove a file, and so forth...) More...
Namespaces | |
namespace | DirectoryNS |
Placeholder namespace description needed for it to appear in Doxygen namespace list. | |
namespace | File |
Subnamespace to deal with files. | |
namespace | Folder |
Subnamespace to deal with folders. | |
Data Structures | |
class | Directory |
Class used to manage directories in MoReFEM. More... | |
class | File |
Class used in MoReFEM to represent files on the filesystem. More... | |
Enumerations | |
enum class | behaviour { overwrite , ask , quit , read , create , create_if_necessary , ignore } |
Enum class to determine how to handle the case. More... | |
enum class | add_rank { no , yes } |
Whether a subdirectory with 'Rank_' + * rank id * must be added to the directory or not. More... | |
enum class | autocopy { yes , no } |
Convenient enum class for copy. | |
enum class | fail_if_already_exist { yes , no } |
Convenient enum class for copy. | |
Functions | |
std::ostream & | operator<< (std::ostream &out, behaviour rhs) |
Overload of operator<< for user-defined class. | |
std::ostream & | operator<< (std::ostream &out, const Directory &rhs) |
Overload of operator<< for user-defined class. | |
bool | IsSameDirectory (const Directory &lhs, const Directory &rhs) |
Check whether two Directory refers to the same directory on the filesystem. | |
Directory | GetRankDirectory (const Directory &root_directory, std::size_t rank) |
Create a Directory which contains path related to rank - where rank is NOT necessarily the one held by mpi object. | |
bool | IsFirstSubfolderOfSecond (const Directory &possible_enclosed_directory, const Directory &possible_enclosing_directory) |
Check whether possible_enclosed_directory is a directory inside possible_enclosing_directory. | |
bool | IsSameFile (const File &lhs, const File &rhs) |
Check whether two File refers to the same file on the filesystem. | |
std::ostream & | operator<< (std::ostream &out, const File &rhs) |
Overload of operator<< for user-defined class. | |
void | Copy (const File &source, const File &target, fail_if_already_exist do_fail_if_already_exist, autocopy allow_autocopy, const std::source_location location=std::source_location::current()) |
Copy a file. | |
void | ConcatenateAsciiFiles (const std::vector< File > &file_list, const File &amalgamated_file, const std::source_location location=std::source_location::current()) |
Concatenate several files assumed to be in ascii format. | |
bool | AreEquals (const File &lhs, const File &rhs, const std::source_location location=std::source_location::current()) |
Check two files share exactly the same content. | |
Namespace that enclose filesystem utilities (check a folder do exist, remove a file, and so forth...)
|
strong |
Enum class to determine how to handle the case.
Remember that Directory constructor never acts directly on the filesystem; you need to call ActOnFilesystem method if you want an action on the filesystem (typically create a directory).
|
strong |
Whether a subdirectory with 'Rank_' + * rank id * must be added to the directory or not.
This should be the standard case for output directories, but it is obviously not relevant for most of the input ones...
std::ostream & MoReFEM::FilesystemNS::operator<< | ( | std::ostream & | out, |
behaviour | rhs ) |
Overload of operator<< for user-defined class.
[in,out] | out | Output stream. |
[in] | rhs | Object which content is to be written to output stream. |
std::ostream & MoReFEM::FilesystemNS::operator<< | ( | std::ostream & | out, |
const Directory & | rhs ) |
Overload of operator<< for user-defined class.
[in,out] | out | Output stream. |
[in] | rhs | Object which content is to be written to output stream. |
Check whether two Directory refers to the same directory on the filesystem.
std::filesystem::equivalent() is not used as one of its prerequisite is that both files exist on the filesystem.
Directory MoReFEM::FilesystemNS::GetRankDirectory | ( | const Directory & | root_directory, |
std::size_t | rank ) |
Create a Directory which contains path related to rank - where rank is NOT necessarily the one held by mpi object.
This is only for some specific functions and should be used with great care; behaviour is set to 'read' and should be changed with even greater care...
[in] | root_directory | The directory matching the root rank. |
[in] | rank | Rank for which the new directory is required. |
bool MoReFEM::FilesystemNS::IsFirstSubfolderOfSecond | ( | const Directory & | possible_enclosed_directory, |
const Directory & | possible_enclosing_directory ) |
Check whether possible_enclosed_directory is a directory inside possible_enclosing_directory.
This function use the canonical path so is assumed to handle properly the symbolic links or relative paths.
[in] | possible_enclosing_directory | The Directory that might be enclosed by the other. |
[in] | possible_enclosed_directory | The Directory that might be enclosing by the other. |
std::filesystem::path
iterator doesn't behave as I want, so I perform the std::mismatch
check upon the strings, not the folder parts. That is not very satisfactory and may prove to be brittle (even if of course I took all the precaution I could think of about the normalization of the path); see the implementation for more details put in a comment there.
Check whether two File refers to the same file on the filesystem.
Friendship.
This is not a check upon the content: you are looking for AreEqual if you want to check that.
std::filesystem::equivalent() is not used as one of its prerequisite is that both files exist on the filesystem.
std::ostream & MoReFEM::FilesystemNS::operator<< | ( | std::ostream & | out, |
const File & | rhs ) |
Overload of operator<< for user-defined class.
[in,out] | out | Output stream. |
[in] | rhs | Object which content is to be written to output stream. |
The underlying path of File class is written.
void MoReFEM::FilesystemNS::Copy | ( | const File & | source, |
const File & | target, | ||
fail_if_already_exist | do_fail_if_already_exist, | ||
autocopy | allow_autocopy, | ||
const std::source_location | location = std::source_location::current() ) |
Copy a file.
Friendship.
[in] | source | Path of the source file. |
[in] | target | Path of the target file. |
[in] | do_fail_if_already_exist | If yes, the target must not exist yet. |
[in] | allow_autocopy | If no, an exception is thrown is source is the same path as target. If yes, nothing is done. The reason for this is that I'm not sure underlying library Yuni can cope with this case. It will be replaced by future STL filesystem library that should be shipped along with C++17. |
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
void MoReFEM::FilesystemNS::ConcatenateAsciiFiles | ( | const std::vector< File > & | file_list, |
const File & | amalgamated_file, | ||
const std::source_location | location = std::source_location::current() ) |
Concatenate several files assumed to be in ascii format.
[in] | file_list | List of files to concatenate. |
[out] | amalgamated_file | File into which the amalgated files are written. |
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
All files must be valid (or in a valid path for output one); if not an exception is raised.
bool MoReFEM::FilesystemNS::AreEquals | ( | const File & | lhs, |
const File & | rhs, | ||
const std::source_location | location = std::source_location::current() ) |
Check two files share exactly the same content.
Friendship.
[in] | lhs | Left-hand side. |
[in] | rhs | Right-hand side. |
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
This function checks both files do exist first.
This code is lifted from https://stackoverflow.com/questions/6163611/compare-two-files with very small adaptation; http://www.cplusplus.com/forum/general/94032/ provides a Boost-dependent implementation which is seemingly more efficient.
Upcoming STL filesystem library doesn't seem to provide the functionality; currently it is used only for a test with very small files involved. So if this is deemed to be used more often and on much bigger file some profiling would be interesting here!