Simple utility class for testing things about one or more files.
More...
#include <FileChecker.h>
|
| static bool | directory_exists (const std::string &path) |
| | Check whether a directory already exists.
|
| |
| static bool | file_can_be_written (std::string path) |
| | Get whether a write to a file at the given path is permitted.
|
| |
| static bool | file_is_empty (const std::string &path) |
| | Checks whether a file is empty.
|
| |
| static bool | file_is_readable (std::string path) |
| | Check whether the path provided points to an existing, readable file.
|
| |
| static bool | file_is_readable (const std::string &path, const std::string &description) |
| | Check whether the path provided points to an existing, readable file, printing a message when it does not.
|
| |
| static std::string | find_first_accessible (std::string mode, std::vector< std::string > paths) |
| | Find the first file path in a provided collection that points to an existing file accessible as specified, proceeding through the collection in indexed order.
|
| |
| static std::string | find_first_readable (std::vector< std::string > paths) |
| | Find the first file path in a provided collection that points to an existing, readable file, proceeding through the collection in indexed order.
|
| |
Simple utility class for testing things about one or more files.
◆ directory_exists()
| static bool utils::FileChecker::directory_exists |
( |
const std::string & | path | ) |
|
|
inlinestatic |
Check whether a directory already exists.
- Parameters
-
| path | The path of interest. |
- Returns
- Whether there is a directory existing at the given path.
◆ file_can_be_written()
| static bool utils::FileChecker::file_can_be_written |
( |
std::string | path | ) |
|
|
inlinestatic |
Get whether a write to a file at the given path is permitted.
Get whether the given file can be written to. To be true, the file must either already exist and have permissions that allow it to be written to, or the file must not exist and the parent directory permissions must allow for a new file to be created and written to.
- Parameters
-
| path | The relative or absolute filesystem path of interest, as a string. |
- Returns
- True if writes to this new or existing file are allowed, or False otherwise.
References file_is_empty(), and file_is_readable().
◆ file_is_empty()
| static bool utils::FileChecker::file_is_empty |
( |
const std::string & | path | ) |
|
|
inlinestatic |
Checks whether a file is empty.
Function assumes the given file exists and will return false if it cannot open the file.
- Parameters
-
| path | The relative or absolute filesystem path of interest, as a string. |
- Returns
- Whether the file is determined to be empty.
Referenced by file_can_be_written().
◆ file_is_readable() [1/2]
| static bool utils::FileChecker::file_is_readable |
( |
const std::string & | path, |
|
|
const std::string & | description ) |
|
inlinestatic |
Check whether the path provided points to an existing, readable file, printing a message when it does not.
The only difference between this and the overloaded function of the same name with a single parameter is this function may also print a message. When a file is found to not be readable, a message indicating this is sent to stdout, with its format being: <description> path <path> not readable
For example, if description is 'Configuration file' and path is '/home/user/file.txt', then the text 'Configuration file path /home/user/file.txt not readable' is sent to stdout.
- Parameters
-
| path | The relative or absolute filesystem path of interest, as a string. |
| description | A name or description of file to make a printed message more informative. |
- Returns
- True if a file exists at the provided path and is readable, or False otherwise.
- See also
- file_is_readable(std::string)
References file_is_readable().
◆ file_is_readable() [2/2]
| static bool utils::FileChecker::file_is_readable |
( |
std::string | path | ) |
|
|
inlinestatic |
◆ find_first_accessible()
| static std::string utils::FileChecker::find_first_accessible |
( |
std::string | mode, |
|
|
std::vector< std::string > | paths ) |
|
inlinestatic |
Find the first file path in a provided collection that points to an existing file accessible as specified, proceeding through the collection in indexed order.
- Parameters
-
| mode | The accessibility mode that the file must be accessible with, as used with fopen. |
| paths | A vector of potential file paths, as strings. |
- Returns
- The first encountered path string of an accessible file, or empty string if no such path was seen.
Referenced by find_first_readable().
◆ find_first_readable()
| static std::string utils::FileChecker::find_first_readable |
( |
std::vector< std::string > | paths | ) |
|
|
inlinestatic |
Find the first file path in a provided collection that points to an existing, readable file, proceeding through the collection in indexed order.
- Parameters
-
| paths | A vector of potential file paths, as strings. |
- Returns
- The first encountered path string of a readable file, or empty string if no such path was seen.
References find_first_accessible().
Referenced by MultiLayerParserTest::find_file().
The documentation for this class was generated from the following file: