95 template <
typename val
idator_type>
96 SEQAN3_CONCEPT
validator = std::copyable<std::remove_cvref_t<validator_type>> &&
139 if (!((cmp <=
max) && (cmp >=
min)))
149 template <std::ranges::forward_range range_type>
155 std::for_each(range.begin(), range.end(), [&] (
auto cmp) { (*this)(cmp); });
189 template <
typename option_value_t>
211 template <std::ranges::forward_range range_type>
213 requires std::constructible_from<option_value_type, std::ranges::range_rvalue_reference_t<range_type>>
226 template <
typename ...option_types>
228 requires ((std::constructible_from<option_value_type, option_types> && ...))
251 template <std::ranges::forward_range range_type>
253 requires std::convertible_to<std::ranges::range_value_t<range_type>,
option_value_type>
257 std::for_each(std::ranges::begin(range), std::ranges::end(range), [&] (
auto cmp) { (*this)(cmp); });
277 template <
typename option_type,
typename ...option_types>
285 template <typename range_type>
287 requires (
std::ranges::forward_range<
std::decay_t<range_type>> &&
288 std::constructible_from<
std::
string,
std::ranges::range_value_t<range_type>>)
293 template <typename option_type, typename ...option_types>
297 template <typename range_type>
299 requires (
std::ranges::forward_range<
std::decay_t<range_type>>)
350 template <std::ranges::forward_range range_type>
356 std::for_each(v.begin(), v.end(), [&] (
auto cmp) { this->operator()(cmp); });
368 if (extensions.empty())
374 " one of the following valid extensions:", extensions,
"!")};
379 if (file_path.front() ==
'.')
380 file_path.erase(0, 1);
386 auto case_insensitive_ends_with = [&] (
std::string const & ext)
388 return case_insensitive_string_ends_with(file_path, ext);
395 "! Got ", all_extensions,
" instead!")};
412 if (
static_cast<bool>(ec))
422 if (!file.is_open() || !file.good())
438 bool is_open = file.is_open();
439 bool is_good = file.good();
442 if (!is_good || !is_open)
451 if (extensions.empty())
464 size_t const suffix_length{suffix.
size()};
465 size_t const str_length{str.
size()};
466 return suffix_length > str_length ?
468 std::ranges::equal(str.
substr(str_length - suffix_length), suffix, [] (
char const chr1,
char const chr2)
470 return std::tolower(chr1) == std::tolower(chr2);
500 template <
typename file_t =
void>
505 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
506 "Expected either a template type with a static member called valid_formats (a file type) or void.");
525 if constexpr (!std::same_as<file_t, void>)
545 requires std::same_as<file_t, void>
557 using file_validator_base::operator();
590 return "The input file must exist and read permissions must be granted." +
630 template <
typename file_t =
void>
634 static_assert(std::same_as<file_t, void> || detail::has_type_valid_formats<file_t>,
635 "Expected either a template type with a static member called valid_formats (a file type) or void.");
681 if constexpr (!std::same_as<file_t, void>)
682 return detail::valid_file_extensions<typename file_t::valid_formats>();
687 using file_validator_base::operator();
722 return "The output file must not exist already and write permissions must be granted." +
766 using file_validator_base::operator();
838 using file_validator_base::operator();
852 if (
static_cast<bool>(ec))
861 dir_guard.remove_all();
932 template <std::ranges::forward_range range_type>
934 requires std::convertible_to<std::ranges::range_value_t<range_type>,
option_value_type const &>
966 template <
typename option_value_t>
994 template <val
idator val
idator1_type, val
idator val
idator2_type>
996 requires std::common_with<typename validator1_type::option_value_type, typename validator2_type::option_value_type>
1003 typename validator2_type::option_value_type>;
1034 template <
typename cmp_type>
1036 requires std::invocable<validator1_type, cmp_type const> && std::invocable<validator2_type, cmp_type const>
1086 template <val
idator val
idator1_type, val
idator val
idator2_type>
1088 requires std::common_with<typename std::remove_reference_t<validator1_type>::option_value_type,
1091 auto operator|(validator1_type && vali1, validator2_type && vali2)
1094 std::forward<validator2_type>(vali2)};
Adaptations of algorithms from the Ranges TS.
A validator that checks whether a number is inside a given range.
Definition: validators.hpp:120
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:159
arithmetic_range_validator(option_value_type const min_, option_value_type const max_)
The constructor.
Definition: validators.hpp:129
double option_value_type
The type of value that this validator invoked upon.
Definition: validators.hpp:123
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside [min, max].
Definition: validators.hpp:137
void operator()(range_type const &range) const
Tests whether every element in range lies inside [min, max].
Definition: validators.hpp:153
option_value_type max
Maximum of the range to test.
Definition: validators.hpp:169
option_value_type min
Minimum of the range to test.
Definition: validators.hpp:166
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:999
validator_chain_adaptor(validator_chain_adaptor &&)=default
Defaulted.
validator_chain_adaptor & operator=(validator_chain_adaptor &&)=default
Defaulted.
void operator()(cmp_type const &cmp) const
Calls the operator() of each validator on the value cmp.
Definition: validators.hpp:1038
validator_chain_adaptor(validator1_type vali1_, validator2_type vali2_)
Constructing from two validators.
Definition: validators.hpp:1018
validator2_type vali2
The second validator in the chain.
Definition: validators.hpp:1054
~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:1045
validator1_type vali1
The first validator in the chain.
Definition: validators.hpp:1052
An abstract base class for the file and directory validators.
Definition: validators.hpp:317
file_validator_base & operator=(file_validator_base &&)=default
Defaulted.
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:462
void validate_filename(std::filesystem::path const &path) const
Validates the given filename path based on the specified extensions.
Definition: validators.hpp:365
file_validator_base & operator=(file_validator_base const &)=default
Defaulted.
std::string valid_extensions_help_page_message() const
Returns the information of valid file extensions.
Definition: validators.hpp:449
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:321
void operator()(range_type const &v) const
Tests whether every path in list v passes validation. See operator()(option_value_type const & value)...
Definition: validators.hpp:354
file_validator_base(file_validator_base &&)=default
Defaulted.
void validate_readability(std::filesystem::path const &path) const
Checks if the given path is readable.
Definition: validators.hpp:405
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:475
virtual ~file_validator_base()=default
void validate_writeability(std::filesystem::path const &path) const
Checks if the given path is writable.
Definition: validators.hpp:433
A validator that checks if a given path is a valid output directory.
Definition: validators.hpp:818
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:845
output_directory_validator & operator=(output_directory_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:879
A validator that checks if a given path is a valid output file.
Definition: validators.hpp:632
output_file_validator(output_file_validator &&)=default
Defaulted.
output_file_validator(output_file_validator const &)=default
Defaulted.
output_file_validator & operator=(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:694
static std::vector< std::string > default_extensions()
The default extensions of file_t.
Definition: validators.hpp:679
output_file_validator()
Default constructor.
Definition: validators.hpp:645
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:728
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:717
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:660
A validator that checks if a matches a regular expression pattern.
Definition: validators.hpp:903
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:943
std::string pattern
The pattern to match.
Definition: validators.hpp:950
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:919
void operator()(range_type const &v) const
Tests whether every filename in list v matches the pattern.
Definition: validators.hpp:936
std::string option_value_type
Type of values that are tested by validator.
Definition: validators.hpp:906
regex_validator(std::string const &pattern_)
Constructing from a vector.
Definition: validators.hpp:911
Argument parser exception thrown when an argument could not be casted to the according type.
Definition: exceptions.hpp:141
A validator that checks whether a value is inside a list of valid values.
Definition: validators.hpp:191
value_list_validator()=default
Defaulted.
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:240
value_list_validator(value_list_validator const &)=default
Defaulted.
option_value_t option_value_type
Type of values that are tested by validator.
Definition: validators.hpp:194
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:261
std::vector< option_value_type > values
Minimum of the range to test.
Definition: validators.hpp:269
value_list_validator & operator=(value_list_validator &&)=default
Defaulted.
void operator()(range_type const &range) const
Tests whether every element in range lies inside values.
Definition: validators.hpp:255
value_list_validator(value_list_validator &&)=default
Defaulted.
~value_list_validator()=default
Defaulted.
value_list_validator & operator=(value_list_validator const &)=default
Defaulted.
value_list_validator(range_type rng)
Constructing from a range.
Definition: validators.hpp:215
T create_directory(T... args)
T current_exception(T... args)
Auxiliary for pretty printing of exception messages.
Provides seqan3::debug_stream and related types.
T emplace_back(T... args)
Provides parser related exceptions.
Provides concepts for core language types and relations that don't have concepts in C++20 (yet).
This header includes C++17 filesystem support and imports it into namespace std::filesystem (independ...
auto operator|(validator1_type &&vali1, validator2_type &&vali2)
Enables the chaining of validators.
Definition: validators.hpp:1091
constexpr ptrdiff_t find_if
Get the index of the first type in a pack that satisfies the given predicate.
Definition: traits.hpp:209
auto const move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:70
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.
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:597
@ create_new
Forbid overwriting the output file.
@ open_or_create
Allow to overwrite the output file.
SeqAn specific customisations in the standard namespace.
Adaptations of concepts from the standard library.
Adaptations of concepts from the Ranges TS.
T rethrow_exception(T... args)
Provides seqan3::detail::safe_filesystem_entry.
Validator that always returns true.
Definition: validators.hpp:968
void operator()(option_value_t const &) const noexcept
Value cmp always passes validation because the operator never throws.
Definition: validators.hpp:973
option_value_t option_value_type
Type of values that are tested by validator.
Definition: validators.hpp:970
std::string get_help_page_message() const
Since no validation is happening the help message is empty.
Definition: validators.hpp:977
T throw_with_nested(T... args)
Provides traits for seqan3::type_list.
Provides various traits for template packs.
Provides various type traits on generic types.