A validator that checks if a given path is a valid output file. More...
#include <seqan3/argument_parser/validators.hpp>
Public Types | |
using | option_value_type = std::string |
Type of values that are tested by validator. | |
Public Member Functions | |
std::string | get_help_page_message () const |
Returns a message that can be appended to the (positional) options help page info. | |
template<std::ranges::forward_range range_type> | |
void | operator() (range_type const &v) const |
Tests whether every path in list v passes validation. See operator()(option_value_type const & value) for further information. More... | |
virtual void | operator() (std::filesystem::path const &file) const override |
Tests whether path is does not already exists and is writable. More... | |
Constructors, destructor and assignment | |
output_file_validator () | |
Default constructor. More... | |
output_file_validator (output_file_validator const &)=default | |
Defaulted. | |
output_file_validator (output_file_validator &&)=default | |
Defaulted. | |
output_file_validator & | operator= (output_file_validator const &)=default |
Defaulted. | |
output_file_validator & | operator= (output_file_validator &&)=default |
Defaulted. | |
virtual | ~output_file_validator ()=default |
Virtual Destructor. | |
output_file_validator (output_file_open_options const mode, std::vector< std::string > extensions=default_extensions()) | |
Constructs from a given overwrite mode and a list of valid extensions. More... | |
file_validator_base ()=default | |
Defaulted. | |
file_validator_base (file_validator_base const &)=default | |
Defaulted. | |
file_validator_base (file_validator_base &&)=default | |
Defaulted. | |
Static Public Member Functions | |
static std::vector< std::string > | default_extensions () |
The default extensions of file_t . More... | |
Protected Member Functions | |
bool | case_insensitive_string_ends_with (std::string_view str, std::string_view suffix) const |
Helper function that checks if a string is a suffix of another string. Case insensitive. More... | |
std::string | valid_extensions_help_page_message () const |
Returns the information of valid file extensions. | |
void | validate_filename (std::filesystem::path const &path) const |
Validates the given filename path based on the specified extensions. More... | |
void | validate_readability (std::filesystem::path const &path) const |
Checks if the given path is readable. More... | |
void | validate_writeability (std::filesystem::path const &path) const |
Checks if the given path is writable. More... | |
Protected Attributes | |
std::vector< std::string > | extensions {} |
Stores the extensions. | |
Related Functions | |
(Note that these are not member functions.) | |
Requirements for seqan3::validator | |
You can expect these (meta-)functions on all types that implement seqan3::validator. | |
void | operator() (option_value_type const &cmp) const |
Validates the value 'cmp' and throws a seqan3::validation_error on failure. More... | |
A validator that checks if a given path is a valid output file.
file_t | The type of the file to get the valid extensions for; void on default. |
On construction, the validator can receive a list (std::vector over std::string) of valid file extensions. The class acts as a functor that throws a seqan3::validation_error exception whenever a given filename's extension (std::string) is not in the given list of valid file extensions, or if the parent path does not have the proper writer permissions. In addition, the validator receives a seqan3::output_file_open_options which allows you to specify what to do if your output file already exists. seqan3::output_file_open_options::create_new will throw a seqan3::validation_error exception if it already exists and seqan3::output_file_open_options::open_or_create will skip this check (that means you are allowed to overwrite the existing file).
The valid extensions can also be obtained from a seqan3 formatted file type, e.g. seqan3::sequence_input_file, if it is given as template argument to this class. The following snippet demonstrates the different ways to instantiate the seqan3::output_file_validator.
|
inline |
Default constructor.
If the class' template argument file_t
names a valid seqan3 file type that contains a static member valid_formats
, e.g. seqan3::sequence_input_file::valid_formats, then it generates the list of valid extensions from this file. Otherwise the extensions list is empty.
|
inlineexplicit |
Constructs from a given overwrite mode and a list of valid extensions.
[in] | mode | A seqan3::output_file_open_options indicating whether the validator throws if a file already exists. |
[in] | extensions | The valid extensions to validate for. Defaults to seqan3::output_file_validator::default_extensions. |
|
inlineprotectedinherited |
Helper function that checks if a string is a suffix of another string. Case insensitive.
str | The string to be searched. |
suffix | The suffix to be searched for. |
true
if suffix
is a suffix of str
, otherwise false
.
|
inlinestatic |
The default extensions of file_t
.
file_t
, will be empty if file_t
is void
.If file_t
does name a valid seqan3 file type that contains a static member valid_formats
returns the extensions of that file_t
type. Otherwise returns an empty list.
|
inlineinherited |
Tests whether every path in list v
passes validation. See operator()(option_value_type const & value) for further information.
range_type | The type of range to check; must model std::ranges::forward_range and the value type must be convertible to std::filesystem::path. |
v | The input range to iterate over and check every element. |
seqan3::validation_error |
|
inlineoverridevirtual |
Tests whether path is does not already exists and is writable.
file | The input value to check. |
seqan3::validation_error | if the validation process failed. Might be nested with std::filesystem::filesystem_error on unhandled OS API errors. |
Implements seqan3::file_validator_base.
|
inlineprotectedinherited |
Validates the given filename path based on the specified extensions.
path | The filename path. |
seqan3::validation_error | if the specified extensions don't match the given path, or std::filesystem::filesystem_error on underlying OS API errors. |
|
inlineprotectedinherited |
Checks if the given path is readable.
path | The path to check. |
true
if readable, otherwise false
. seqan3::validation_error | if the path is not readable, or std::filesystem::filesystem_error on underlying OS API errors. |
|
inlineprotectedinherited |
Checks if the given path is writable.
path | The path to check. |
true
if writable, otherwise false
. seqan3::validation_error | if the file could not be opened for writing, or std::filesystem::filesystem_error on underlying OS API errors. |
|
related |
Validates the value 'cmp' and throws a seqan3::validation_error on failure.
option_value_type | The type of the value to be validated. |
[in,out] | cmp | The value to be validated. |
seqan3::validation_error | if value 'cmp' does not pass validation. |