96template <
typename val
idator_type>
98 std::copyable<std::remove_cvref_t<validator_type>>
104 } -> std::same_as<void>;
107 } -> std::same_as<std::string>;
126template <arithmetic option_value_t>
146 if (!((cmp <=
max) && (cmp >=
min)))
156 template <std::ranges::forward_range range_type>
201template <
typename option_value_t>
223 template <std::ranges::forward_range range_type>
224 requires std::constructible_from<option_value_type, std::ranges::range_rvalue_reference_t<range_type>>
236 template <
typename... option_types>
237 requires ((std::constructible_from<option_value_type, option_types> && ...))
259 template <std::ranges::forward_range range_type>
260 requires std::convertible_to<std::ranges::range_value_t<range_type>,
option_value_type>
264 std::ranges::end(range),
287template <
typename option_type,
typename... option_types>
288 requires (std::constructible_from<std::string, std::decay_t<option_types>> && ...
289 && std::constructible_from<std::string, std::decay_t<option_type>>)
293template <
typename range_type>
294 requires (std::ranges::forward_range<std::decay_t<range_type>>
295 && std::constructible_from<std::string, std::ranges::range_value_t<range_type>>)
299template <
typename option_type,
typename... option_types>
303template <
typename range_type>
304 requires (std::ranges::forward_range<std::decay_t<range_type>>)
355 template <std::ranges::forward_range range_type>
357 && !std::convertible_to<range_type, std::filesystem::path const &>)
358 void operator()(range_type
const & v)
const
364 this->operator()(cmp);
384 " has no extension. Expected"
385 " one of the following valid extensions:",
392 if (file_path.front() ==
'.')
393 file_path.erase(0, 1);
399 auto case_insensitive_ends_with = [&](
std::string const & ext)
427 if (
static_cast<bool>(ec))
437 if (!file.is_open() || !file.good())
452 bool is_open = file.is_open();
453 bool is_good = file.good();
456 if (!is_good || !is_open)
480 size_t const suffix_length{suffix.
size()};
481 size_t const str_length{str.
size()};
482 return suffix_length > str_length ? false
483 : std::ranges::equal(str.
substr(str_length - suffix_length),
485 [](
char const chr1,
char const chr2)
487 return std::tolower(chr1) == std::tolower(chr2);
519template <
typename file_t =
void>
523 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
524 "Expected either a template type with a static member called valid_formats (a file type) or void.");
543 if constexpr (!std::same_as<file_t, void>)
562 requires std::same_as<file_t, void>
573 using file_validator_base::operator();
649template <
typename file_t =
void>
653 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
654 "Expected either a template type with a static member called valid_formats (a file type) or void.");
701 if constexpr (!std::same_as<file_t, void>)
702 return detail::valid_file_extensions<typename file_t::valid_formats>();
707 using file_validator_base::operator();
744 return "The output file must not exist already and write permissions must be granted."
790 using file_validator_base::operator();
866 using file_validator_base::operator();
880 if (
static_cast<bool>(ec))
889 dir_guard.remove_all();
963 template <std::ranges::forward_range range_type>
964 requires std::convertible_to<std::ranges::range_reference_t<range_type>,
option_value_type const &>
967 for (
auto && file_name : v)
1000template <
typename option_value_t>
1030template <val
idator val
idator1_type, val
idator val
idator2_type>
1031 requires std::common_with<typename validator1_type::option_value_type, typename validator2_type::option_value_type>
1069 template <
typename cmp_type>
1070 requires std::invocable<validator1_type, cmp_type const> && std::invocable<validator2_type, cmp_type const>
1121template <val
idator val
idator1_type, val
idator val
idator2_type>
1122 requires std::common_with<typename std::remove_reference_t<validator1_type>::option_value_type,
1124auto operator|(validator1_type && vali1, 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:128
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside [min, max].
Definition: validators.hpp:144
option_value_type max
Maximum of the range to test.
Definition: validators.hpp:179
option_value_t option_value_type
The type of value that this validator invoked upon.
Definition: validators.hpp:131
void operator()(range_type const &range) const
Tests whether every element in range lies inside [min, max].
Definition: validators.hpp:158
option_value_type min
Minimum of the range to test.
Definition: validators.hpp:176
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:169
arithmetic_range_validator(option_value_type const min_, option_value_type const max_)
The constructor.
Definition: validators.hpp:137
A safe guard to manage a filesystem entry, e.g. a file or a directory.
Definition: safe_filesystem_entry.hpp:38
A helper struct to chain validators recursively via the pipe operator.
Definition: validators.hpp:1033
validator_chain_adaptor(validator_chain_adaptor &&)=default
Defaulted.
validator_chain_adaptor & operator=(validator_chain_adaptor &&)=default
Defaulted.
validator_chain_adaptor(validator1_type vali1_, validator2_type vali2_)
Constructing from two validators.
Definition: validators.hpp:1052
validator2_type vali2
The second validator in the chain.
Definition: validators.hpp:1087
~validator_chain_adaptor()=default
The destructor.
validator_chain_adaptor & operator=(validator_chain_adaptor const &pf)=default
Defaulted.
validator_chain_adaptor(validator_chain_adaptor const &pf)=default
Defaulted.
validator_chain_adaptor()=delete
Deleted.
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:1078
validator1_type vali1
The first validator in the chain.
Definition: validators.hpp:1085
void operator()(cmp_type const &cmp) const
Calls the operator() of each validator on the value cmp.
Definition: validators.hpp:1071
An abstract base class for the file and directory validators.
Definition: validators.hpp:323
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:478
void validate_filename(std::filesystem::path const &path) const
Validates the given filename path based on the specified extensions.
Definition: validators.hpp:374
std::string valid_extensions_help_page_message() const
Returns the information of valid file extensions.
Definition: validators.hpp:463
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:326
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:420
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:492
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:447
A validator that checks if a given path is a valid output directory.
Definition: validators.hpp:846
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:873
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:909
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:651
static std::vector< std::string > default_extensions()
The default extensions of file_t.
Definition: validators.hpp:699
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:714
output_file_validator()
Default constructor.
Definition: validators.hpp:664
output_file_validator & operator=(output_file_validator const &)=default
Defaulted.
output_file_validator & operator=(output_file_validator &&)=default
Defaulted.
output_file_open_options mode
Stores the current mode of whether it is valid to overwrite the output file.
Definition: validators.hpp:750
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:739
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:679
A validator that checks if a matches a regular expression pattern.
Definition: validators.hpp:935
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:975
std::string pattern
The pattern to match.
Definition: validators.hpp:982
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:950
std::string option_value_type
Type of values that are tested by validator.
Definition: validators.hpp:938
void operator()(range_type const &v) const
Tests whether every filename in list v matches the pattern.
Definition: validators.hpp:965
regex_validator(std::string const &pattern_)
Constructing from a vector.
Definition: validators.hpp:943
Argument parser exception thrown when an argument could not be casted to the according type.
Definition: exceptions.hpp:131
A validator that checks whether a value is inside a list of valid values.
Definition: validators.hpp:203
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:248
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:206
void operator()(range_type const &range) const
Tests whether every element in range lies inside values.
Definition: validators.hpp:261
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:272
std::vector< option_value_type > values
Minimum of the range to test.
Definition: validators.hpp:279
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:225
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:238
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:1124
constexpr auto all
Returns a view that includes all elements of the range argument.
Definition: all_view.hpp:204
constexpr ptrdiff_t find_if
Get the index of the first type in a pack that satisfies the given predicate.
Definition: traits.hpp:205
constexpr auto join_with
A join view, please use std::views::join if you don't need a separator.
Definition: join_with.hpp:29
T has_extension(T... args)
A type that satisfies std::is_arithmetic_v<t>.
The concept for option validators passed to add_option/positional_option.
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Provides various utility functions.
T is_directory(T... args)
T is_regular_file(T... args)
Provides seqan3::views::join_with.
std::string to_string(value_type &&... values)
Streams all parameters via the seqan3::debug_stream and returns a concatenated string.
Definition: to_string.hpp:29
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:29
output_file_open_options
Mode of an output file: Determines whether an existing file can be (silently) overwritten.
Definition: validators.hpp:614
@ 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.
The <ranges> header from C++20's standard library.
T rethrow_exception(T... args)
Provides seqan3::detail::safe_filesystem_entry.
Validator that always returns true.
Definition: validators.hpp:1002
void operator()(option_value_t const &) const noexcept
Value cmp always passes validation because the operator never throws.
Definition: validators.hpp:1007
option_value_t option_value_type
Type of values that are tested by validator.
Definition: validators.hpp:1004
std::string get_help_page_message() const
Since no validation is happening the help message is empty.
Definition: validators.hpp:1011
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.