32SEQAN3_DEPRECATED_HEADER(
"This header and its functionality is deprecated and will be removed in a future version of SeqAn. Please use the sharg-parser (url: https://github.com/seqan/sharg-parser) instead.");
96template <
typename val
idator_type>
98 std::copyable<std::remove_cvref_t<validator_type>>
102 {
validator(value) } -> std::same_as<void>;
122template <arithmetic option_value_t>
142 if (!((
cmp <= max) && (
cmp >= min)))
143 throw validation_error{detail::to_string(
"Value ",
cmp,
" is not in range [", min,
",", max,
"].")};
152 template <std::ranges::forward_range range_type>
167 return detail::to_string(
"Value must be in range [", min,
",", max,
"].");
197template <
typename option_value_t>
219 template <std::ranges::forward_range range_type>
220 requires std::constructible_from<option_value_type, std::ranges::range_rvalue_reference_t<range_type>>
233 requires ((std::constructible_from<option_value_type, option_types> && ...))
247 throw validation_error{detail::to_string(
"Value ",
cmp,
" is not one of ", std::views::all(values),
".")};
255 template <std::ranges::forward_range range_type>
256 requires std::convertible_to<std::ranges::range_value_t<range_type>,
option_value_type>
260 std::ranges::end(
range),
270 return detail::to_string(
"Value must be one of ", std::views::all(values),
".");
283template <
typename option_type,
typename... option_types>
284 requires (std::constructible_from<std::string, std::decay_t<option_types>> && ...
285 && std::constructible_from<std::string, std::decay_t<option_type>>)
289template <
typename range_type>
290 requires (std::ranges::forward_range<std::decay_t<range_type>>
291 && std::constructible_from<std::string, std::ranges::range_value_t<range_type>>)
299template <
typename range_type>
300 requires (std::ranges::forward_range<std::decay_t<range_type>>)
351 template <std::ranges::forward_range range_type>
353 && !std::convertible_to<range_type, std::filesystem::path const &>)
360 this->operator()(cmp);
380 " has no extension. Expected"
381 " one of the following valid extensions:",
403 throw validation_error{detail::to_string(
"Expected one of the following valid extensions: ",
423 if (
static_cast<bool>(
ec))
424 throw validation_error{detail::to_string(
"Cannot read the directory ", path,
"!")};
430 throw validation_error{detail::to_string(
"Expected a regular file ", path,
"!")};
433 if (!
file.is_open() || !
file.good())
434 throw validation_error{detail::to_string(
"Cannot read the file ", path,
"!")};
446 detail::safe_filesystem_entry
file_guard{path};
448 bool is_open =
file.is_open();
464 return detail::to_string(
" Valid file extensions are: [",
481 [](
char const chr1,
char const chr2)
483 return std::tolower(chr1) == std::tolower(chr2);
515template <
typename file_t =
void>
519 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
520 "Expected either a template type with a static member called valid_formats (a file type) or void.");
539 if constexpr (!std::same_as<file_t, void>)
558 requires std::same_as<file_t, void>
569 using file_validator_base::operator();
645template <
typename file_t =
void>
649 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
650 "Expected either a template type with a static member called valid_formats (a file type) or void.");
697 if constexpr (!std::same_as<file_t, void>)
698 return detail::valid_file_extensions<typename file_t::valid_formats>();
703 using file_validator_base::operator();
740 return "The output file must not exist already and write permissions must be granted."
786 using file_validator_base::operator();
821 return detail::to_string(
"An existing, readable path for the input directory.");
862 using file_validator_base::operator();
876 if (
static_cast<bool>(
ec))
907 return detail::to_string(
"A valid path for the output directory.");
950 throw validation_error{detail::to_string(
"Value ",
cmp,
" did not match the pattern ", pattern,
".")};
959 template <std::ranges::forward_range range_type>
960 requires std::convertible_to<std::ranges::range_reference_t<range_type>,
option_value_type const &>
963 for (
auto && file_name :
v)
973 return detail::to_string(
"Value must match the pattern '", pattern,
"'.");
996template <
typename option_value_t>
997struct default_validator
1000 using option_value_type = option_value_t;
1003 void operator()(option_value_t
const & )
const noexcept
1026template <val
idator val
idator1_type, val
idator val
idator2_type>
1027 requires std::common_with<typename validator1_type::option_value_type, typename validator2_type::option_value_type>
1028class validator_chain_adaptor
1038 validator_chain_adaptor() =
delete;
1039 validator_chain_adaptor(validator_chain_adaptor
const & pf) =
default;
1040 validator_chain_adaptor & operator=(validator_chain_adaptor
const & pf) =
default;
1041 validator_chain_adaptor(validator_chain_adaptor &&) =
default;
1042 validator_chain_adaptor & operator=(validator_chain_adaptor &&) =
default;
1048 validator_chain_adaptor(validator1_type vali1_, validator2_type vali2_) :
1054 ~validator_chain_adaptor() =
default;
1065 template <
typename cmp_type>
1066 requires std::invocable<validator1_type, cmp_type const> && std::invocable<validator2_type, cmp_type const>
1076 return detail::to_string(vali1.get_help_page_message(),
" ", vali2.get_help_page_message());
1081 validator1_type vali1;
1083 validator2_type vali2;
1117template <val
idator val
idator1_type, val
idator val
idator2_type>
1118 requires std::common_with<typename std::remove_reference_t<validator1_type>::option_value_type,
1122 return detail::validator_chain_adaptor{std::forward<validator1_type>(vali1), std::forward<validator2_type>(vali2)};
T back_inserter(T... args)
Provides various type traits on generic types.
A validator that checks whether a number is inside a given range.
Definition validators.hpp:124
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside [min, max].
Definition validators.hpp:140
option_value_t option_value_type
The type of value that this validator invoked upon.
Definition validators.hpp:127
void operator()(range_type const &range) const
Tests whether every element in range lies inside [min, max].
Definition validators.hpp:154
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:165
arithmetic_range_validator(option_value_type const min_, option_value_type const max_)
The constructor.
Definition validators.hpp:133
A "pretty printer" for most SeqAn data structures and related types.
Definition debug_stream_type.hpp:79
An abstract base class for the file and directory validators.
Definition validators.hpp:319
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.
Definition validators.hpp:474
void validate_filename(std::filesystem::path const &path) const
Validates the given filename path based on the specified extensions.
Definition validators.hpp:370
std::string valid_extensions_help_page_message() const
Returns the information of valid file extensions.
Definition validators.hpp:459
virtual void operator()(std::filesystem::path const &path) const =0
Tests if the given path is a valid input, respectively output, file or directory.
std::string option_value_type
Type of values that are tested by validator.
Definition validators.hpp:322
file_validator_base(file_validator_base &&)=default
Defaulted.
file_validator_base & operator=(file_validator_base &&)=default
Defaulted.
void validate_readability(std::filesystem::path const &path) const
Checks if the given path is readable.
Definition validators.hpp:416
file_validator_base()=default
Defaulted.
file_validator_base(file_validator_base const &)=default
Defaulted.
std::vector< std::string > extensions
Stores the extensions.
Definition validators.hpp:488
virtual ~file_validator_base()=default
file_validator_base & operator=(file_validator_base const &)=default
Defaulted.
void validate_writeability(std::filesystem::path const &path) const
Checks if the given path is writable.
Definition validators.hpp:443
A validator that checks if a given path is a valid output directory.
Definition validators.hpp:842
output_directory_validator()=default
Defaulted.
output_directory_validator & operator=(output_directory_validator const &)=default
Defaulted.
virtual ~output_directory_validator()=default
Virtual Destructor.
output_directory_validator(output_directory_validator &&)=default
Defaulted.
output_directory_validator(output_directory_validator const &)=default
Defaulted.
virtual void operator()(std::filesystem::path const &dir) const override
Tests whether path is writable.
Definition validators.hpp:869
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:905
output_directory_validator & operator=(output_directory_validator &&)=default
Defaulted.
A validator that checks if a given path is a valid output file.
Definition validators.hpp:647
static std::vector< std::string > default_extensions()
The default extensions of file_t.
Definition validators.hpp:695
output_file_validator(output_file_validator &&)=default
Defaulted.
output_file_validator(output_file_validator const &)=default
Defaulted.
virtual void operator()(std::filesystem::path const &file) const override
Tests whether path is does not already exists and is writable.
Definition validators.hpp:710
output_file_validator()
Default constructor.
Definition validators.hpp:660
output_file_validator & operator=(output_file_validator const &)=default
Defaulted.
output_file_validator & operator=(output_file_validator &&)=default
Defaulted.
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:735
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.
Definition validators.hpp:675
A validator that checks if a matches a regular expression pattern.
Definition validators.hpp:931
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:971
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition validators.hpp:946
std::string option_value_type
Type of values that are tested by validator.
Definition validators.hpp:934
void operator()(range_type const &v) const
Tests whether every filename in list v matches the pattern.
Definition validators.hpp:961
regex_validator(std::string const &pattern_)
Constructing from a vector.
Definition validators.hpp:939
Argument parser exception thrown when an argument could not be casted to the according type.
Definition exceptions.hpp:130
A validator that checks whether a value is inside a list of valid values.
Definition validators.hpp:199
value_list_validator(option_type, option_types...) -> value_list_validator< option_type >
Deduction guide for a parameter pack.
value_list_validator()=default
Defaulted.
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition validators.hpp:244
value_list_validator(value_list_validator const &)=default
Defaulted.
value_list_validator & operator=(value_list_validator const &)=default
Defaulted.
option_value_t option_value_type
Type of values that are tested by validator.
Definition validators.hpp:202
void operator()(range_type const &range) const
Tests whether every element in range lies inside values.
Definition validators.hpp:257
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition validators.hpp:268
value_list_validator(value_list_validator &&)=default
Defaulted.
~value_list_validator()=default
Defaulted.
value_list_validator(range_type &&rng) -> value_list_validator< std::string >
Deduction guide for ranges over a value type convertible to std::string.
value_list_validator(option_type, option_types...) -> value_list_validator< std::string >
Type deduction guides.
value_list_validator & operator=(value_list_validator &&)=default
Defaulted.
value_list_validator(range_type rng)
Constructing from a range.
Definition validators.hpp:221
value_list_validator(range_type &&rng) -> value_list_validator< std::ranges::range_value_t< range_type > >
Deduction guide for ranges.
value_list_validator(option_types &&... opts)
Constructing from a parameter pack.
Definition validators.hpp:234
T create_directory(T... args)
T current_exception(T... args)
T emplace_back(T... args)
Provides parser related exceptions.
auto operator|(validator1_type &&vali1, validator2_type &&vali2)
Enables the chaining of validators.
Definition validators.hpp:1120
seqan::stl::views::join_with join_with
A view adaptor that represents view consisting of the sequence obtained from flattening a view of ran...
Definition join_with.hpp:25
T has_extension(T... args)
The concept for option validators passed to add_option/positional_option.
void operator()(option_value_type const &cmp) const
Validates the value 'cmp' and throws a seqan3::validation_error on failure.
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
using option_value_type
The type of value on which the validator is called on.
Provides various utility functions.
T is_directory(T... args)
T is_regular_file(T... args)
Provides seqan3::views::join_with.
The main SeqAn3 namespace.
Definition aligned_sequence_concept.hpp:26
output_file_open_options
Mode of an output file: Determines whether an existing file can be (silently) overwritten.
Definition validators.hpp:610
@ create_new
Forbid overwriting the output file.
@ open_or_create
Allow to overwrite the output file.
SeqAn specific customisations in the standard namespace.
Provides seqan3::debug_stream and related types.
T rethrow_exception(T... args)
Provides seqan3::detail::safe_filesystem_entry.
T throw_with_nested(T... args)
Auxiliary for pretty printing of exception messages.
Provides traits for seqan3::type_list.
Provides various traits for template packs.
Provides concepts that do not have equivalents in C++20.