|
Sharg 1.2.3-rc.1
The argument parser for bio-c++ tools.
|
A validator that checks if a given path is a valid output file. More...
#include <sharg/validators.hpp>
Inheritance diagram for sharg::output_file_validator:Public Types | |
| using | option_value_type |
| Type of values that are tested by validator. | |
Public Types inherited from sharg::file_validator_base | |
| using | option_value_type = std::string |
| Type of values that are tested by validator. | |
Public Member Functions | |
| virtual void | operator() (std::filesystem::path const &file) const override |
| Tests whether path is does not already exists and is writable. | |
| std::string | get_help_page_message () const |
| Returns a message that can be appended to the (positional) options help page info. | |
Constructors, destructor and assignment | |
| output_file_validator ()=default | |
| Defaulted. | |
| 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) | |
| Constructs from a given overwrite mode and a list of valid extensions. | |
| output_file_validator (output_file_open_options const mode, auto &&... extensions) | |
| Constructs from a given overwrite mode and a parameter pack of valid extensions. | |
| output_file_validator (std::vector< std::string > const &extensions) | |
| Constructs from a list of valid extensions. | |
| output_file_validator (auto &&... extensions) | |
| Constructs from a parameter pack of valid extensions. | |
| file_validator_base ()=default | |
| Defaulted. | |
| file_validator_base (file_validator_base const &)=default | |
| Defaulted. | |
| file_validator_base (file_validator_base &&)=default | |
| Defaulted. | |
Public Member Functions inherited from sharg::file_validator_base | |
| template<std::ranges::forward_range range_type> requires (std::convertible_to<std::ranges::range_value_t<range_type>, std::filesystem::path const &> && !std::convertible_to<range_type, std::filesystem::path const &>) | |
| 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. | |
| file_validator_base ()=default | |
| Defaulted. | |
| file_validator_base (file_validator_base const &)=default | |
| Defaulted. | |
| file_validator_base (file_validator_base &&)=default | |
| Defaulted. | |
| file_validator_base & | operator= (file_validator_base const &)=default |
| Defaulted. | |
| file_validator_base & | operator= (file_validator_base &&)=default |
| Defaulted. | |
| virtual | ~file_validator_base ()=default |
Additional Inherited Members | |
Protected Member Functions inherited from sharg::file_validator_base | |
| void | validate_filename (std::filesystem::path const &path) const |
| Validates the given filename path based on the specified extensions. | |
| void | validate_readability (std::filesystem::path const &path) const |
| Checks if the given path is readable. | |
| void | validate_writeability (std::filesystem::path const &path) const |
| Checks if the given path is writable. | |
| std::string | valid_extensions_help_page_message () const |
| Returns the information of valid file extensions. | |
| 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. | |
Protected Attributes inherited from sharg::file_validator_base | |
| std::vector< std::string > | extensions {} |
| Stores the extensions. | |
| std::string | extensions_str {} |
| The extension range as a std:;string for pretty printing. | |
A validator that checks if a given path is a valid output file.
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 sharg::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 sharg::output_file_open_options which allows you to specify what to do if your output file already exists. sharg::output_file_open_options::create_new will throw a sharg::validation_error exception if it already exists and sharg::output_file_open_options::open_or_create will skip this check (that means you are allowed to overwrite the existing file). The validator itself does not modify an existing file.
The following snippet demonstrates the different ways to instantiate the sharg::output_file_validator.
|
inlineexplicit |
Constructs from a given overwrite mode and a list of valid extensions.
| [in] | mode | A sharg::output_file_open_options indicating whether the validator throws if a file already exists. |
| [in] | extensions | The valid extensions to validate for. |
|
inlineexplicit |
Constructs from a given overwrite mode and a parameter pack of valid extensions.
| [in] | mode | A sharg::output_file_open_options indicating whether the validator throws if a file already exists. |
| [in] | extensions | Parameter pack representing valid extensions. std::string must be constructible from each argument. The pack may be empty ( → all extensions are valid). |
|
inlineexplicit |
Constructs from a list of valid extensions.
| [in] | extensions | The valid extensions to validate for. |
|
inlineexplicit |
Constructs from a parameter pack of valid extensions.
| [in] | extensions | Parameter pack representing valid extensions. std::string must be constructible from each argument. The pack may be empty ( → all extensions are valid). |
|
inline |
Returns a message that can be appended to the (positional) options help page info.
|
inlineoverridevirtual |
Tests whether path is does not already exists and is writable.
| file | The input value to check. |
| sharg::validation_error | if the validation process failed. Might be nested with std::filesystem::filesystem_error on unhandled OS API errors. |
Implements sharg::file_validator_base.