97 template <
typename val
idator_type>
101 requires(validator_type validator,
102 typename std::remove_reference_t<validator_type>::value_type value)
104 typename std::remove_reference_t<validator_type>::value_type;
106 { validator(value) } -> void;
107 { validator.get_help_page_message() } -> std::string;
112 template <
typename option_value_type>
113 class integral_range_validator;
130 template <std::Integral option_value_type>
131 class integral_range_validator<option_value_type>
151 if (!((cmp <= max) && (cmp >= min)))
153 " is not in range [", min,
",", max,
"]."));
159 return detail::to_string(
"Value must be in range [", min,
",", max,
"].");
171 template <container_concept option_value_type>
173 class integral_range_validator<option_value_type>
179 using inner_value_type =
typename value_type::value_type;
185 integral_range_validator(inner_value_type
const min_,
186 inner_value_type
const max_) :
196 std::for_each(cmp.begin(), cmp.end(), [&] (
auto cmp_v)
198 if (!((cmp_v <= max) && (cmp_v >= min)))
200 " is not in range [", min,
",", max,
"]."));
205 std::string get_help_page_message()
const 207 return detail::to_string(
"Value must be in range [", min,
",", max,
"].");
212 inner_value_type min{};
215 inner_value_type max{};
231 template <
typename option_value_type>
258 if (!(std::find(values.begin(), values.end(), cmp) != values.end()))
265 return detail::to_string(
"Value must be one of ",
view::all(values),
".");
271 std::vector<option_value_type> values;
281 template <container_concept option_value_type>
283 requires !std::is_same_v<option_value_type, std::string>
313 std::for_each(cmp.begin(), cmp.end(), [&] (
auto cmp_v)
315 if (!(std::find(values.begin(), values.end(), cmp_v) != values.end()))
324 return detail::to_string(
"Value must be one of ",
view::all(values),
".");
330 std::vector<inner_value_type> values;
371 std::string ext{path.extension().string()};
372 ext = ext.substr(std::min(1, static_cast<int>(ext.size())));
373 if (!(std::find(extensions.begin(), extensions.end(), ext) != extensions.end()))
381 std::for_each(v.begin(), v.end(), [&] (
auto cmp) { (*this)(cmp); });
387 return detail::to_string(
"File name extension must be one of ",
view::all(extensions),
".");
392 std::vector<std::string> extensions;
417 if (!(filesystem::exists(path)))
422 void operator()(std::vector<filesystem::path>
const & v)
const 424 std::for_each(v.begin(), v.end(), [&] (
auto cmp) { (*this)(cmp); });
430 return detail::to_string(
"The file is checked for existence.");
435 template <
typename option_value_type>
436 class regex_validator;
456 class regex_validator<
std::string>
475 std::regex rgx(pattern);
476 if (!std::regex_match(cmp, rgx))
483 return detail::to_string(
"Value must match the pattern '", pattern,
"'.");
497 class regex_validator<
std::vector<std::string>>
515 std::regex rgx(pattern);
516 for (
auto const & cmp_v : cmp)
517 if (!std::regex_match(cmp_v, rgx))
518 throw parser_invalid_argument(detail::to_string(
"Value ", cmp_v,
" did not match the pattern ", pattern,
"."));
524 return detail::to_string(
"Value must match the pattern '", pattern,
"'.");
551 template <
typename option_value_type>
552 struct default_validator
558 void operator()(option_value_type
const & )
const noexcept
562 std::string get_help_page_message()
const 579 template <val
idator_concept val
idator1_type, val
idator_concept val
idator2_type>
583 class validator_chain_adaptor
587 using value_type =
typename validator1_type::value_type;
592 validator_chain_adaptor() =
delete;
594 validator_chain_adaptor(validator_chain_adaptor
const & pf) =
default;
595 validator_chain_adaptor & operator=(validator_chain_adaptor
const & pf) =
default;
596 validator_chain_adaptor(validator_chain_adaptor &&) =
default;
597 validator_chain_adaptor & operator=(validator_chain_adaptor &&) =
default;
603 validator_chain_adaptor(validator1_type vali1_, validator2_type vali2_) :
604 vali1{std::move(vali1_)}, vali2{std::move(vali2_)}
608 ~validator_chain_adaptor() =
default;
625 std::string get_help_page_message()
const 627 return detail::to_string(vali1.get_help_page_message(),
" ", vali2.get_help_page_message());
632 validator1_type vali1;
634 validator2_type vali2;
666 template <val
idator_concept val
idator1_type, val
idator_concept val
idator2_type>
669 typename std::remove_reference_t<validator2_type>::value_type>
671 auto operator|(validator1_type && vali1, validator2_type && vali2)
673 return detail::validator_chain_adaptor{std::forward<validator1_type>(vali1),
674 std::forward<validator2_type>(vali2)};
A validator that checks if a matches a regular expression pattern.
Definition: validators.hpp:456
option_value_type value_type
The type of value that this validator invoked upon.
Definition: validators.hpp:135
regex_validator(std::string const &pattern_)
Constructing from a vector.
Definition: validators.hpp:465
void operator()(value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:513
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:322
Contains parser related exceptions.
SeqAn specific customisations in the standard namespace.
Definition: align_result.hpp:221
std::string value_type
Type of values that are tested by validator.
Definition: validators.hpp:460
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:522
The main SeqAn3 namespace.
Definition: aligned_sequence_concept.hpp:58
regex_validator(std::string const &pattern_)
Constructing from a vector.
Definition: validators.hpp:505
void operator()(std::vector< std::string > const &v) const
Tests whether every value of v lies inside extensions.
Definition: validators.hpp:379
The concept Integral is satisfied if and only if T is an integral type.
value_list_validator(std::initializer_list< option_value_type > const &v)
Constructing from an initializer_list.
Definition: validators.hpp:248
std::vector< std::string > value_type
Type of values that are tested by validator.
Definition: validators.hpp:501
std::string value_type
Type of values that are tested by validator.
Definition: validators.hpp:349
void operator()(option_value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:256
value_list_validator(std::initializer_list< inner_value_type > const &v)
Constructing from an initializer_list.
Definition: validators.hpp:303
file_ext_validator(std::vector< std::string > const &v)
Constructing from a vector.
Definition: validators.hpp:354
A validator that checks if a filenames has one of the valid extensions.
Definition: validators.hpp:345
void operator()(value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:473
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:385
integral_range_validator(value_type const min_, value_type const max_)
The constructor.
Definition: validators.hpp:141
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:263
Provides seqan3::view::all.
option_value_type value_type
Type of values that are tested by validator.
Definition: validators.hpp:236
The concept std::Same<T, U> is satisfied if and only if T and U denote the same type.
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition: exceptions.hpp:64
void operator()(value_type const &cmp) const
Tests whether cmp lies inside values.
Definition: validators.hpp:311
value_list_validator(std::vector< inner_value_type > const &v)
Constructing from a vector.
Definition: validators.hpp:296
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...
Provides various metafunctions on generic types.
auto operator|(validator1_type &&vali1, validator2_type &&vali2)
Enables the chaining of validators. !
Definition: validators.hpp:671
A validator that checks if a file exists.
Definition: validators.hpp:405
file_ext_validator(std::initializer_list< std::string > const &v)
Constructing from an initializer_list.
Definition: validators.hpp:361
void operator()(filesystem::path const &path) const
Tests whether path exists.
Definition: validators.hpp:415
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:481
A validator that checks whether a value is inside a list of valid values.
Definition: validators.hpp:232
constexpr auto all
A view that safely wraps a container (you will likely not need to use this unless defining a new view...
Definition: view_all.hpp:95
filesystem::path value_type
Type of values that are tested by validator.
Definition: validators.hpp:409
value_list_validator(std::vector< option_value_type > const &v)
Constructing from a vector.
Definition: validators.hpp:241
Subsumes std::Movable, std::CopyConstructible, and requires that the type be std::Assignable bool fro...
void operator()(value_type const &cmp) const
Tests whether cmp lies inside [min,max].
Definition: validators.hpp:149
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:157
Adaptations of concepts from the standard library.
std::string get_help_page_message() const
Returns a message that can be appended to the (positional) options help page info.
Definition: validators.hpp:428
typename value_type::value_type inner_value_type
Underlying type of the container.
Definition: validators.hpp:291
void operator()(filesystem::path const &path) const
Tests whether the filepath path ends with a valid extension.
Definition: validators.hpp:369
Contains auxiliary information.
void operator()(std::vector< filesystem::path > const &v) const
Tests whether every filename in list v exists.
Definition: validators.hpp:422