SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
seqan3::value_list_validator< option_value_t > Class Template Reference

A validator that checks whether a value is inside a list of valid values. More...

#include <seqan3/argument_parser/validators.hpp>

+ Inheritance diagram for seqan3::value_list_validator< option_value_t >:

Public Types

using option_value_type = option_value_t
 Type of values that are tested by validator.
 

Public Member Functions

std::string get_help_page_message () const
 Returns a message that can be appended to the (positional) options help page info.
 
void operator() (option_value_type const &cmp) const
 Tests whether cmp lies inside values. More...
 
template<std::ranges::forward_range range_type>
void operator() (range_type const &range) const
 Tests whether every element in range lies inside values. More...
 
Constructors, destructor and assignment
 value_list_validator ()=default
 Defaulted.
 
 value_list_validator (value_list_validator const &)=default
 Defaulted.
 
 value_list_validator (value_list_validator &&)=default
 Defaulted.
 
value_list_validatoroperator= (value_list_validator const &)=default
 Defaulted.
 
value_list_validatoroperator= (value_list_validator &&)=default
 Defaulted.
 
 ~value_list_validator ()=default
 Defaulted.
 
template<std::ranges::forward_range range_type>
 value_list_validator (range_type rng)
 Constructing from a range. More...
 
template<typename ... option_types>
 value_list_validator (option_types &&...opts)
 Constructing from a parameter pack. More...
 

Related Functions

(Note that these are not member functions.)

template<arithmetic ... option_types>
 value_list_validator (option_types...) -> value_list_validator< double >
 Type deduction guides. More...
 
template<std::ranges::forward_range range_type>
 value_list_validator (range_type &&rng) -> value_list_validator< double >
 Deduction guide for ranges over an arithmetic type.
 
template<typename ... option_types>
 value_list_validator (option_types...) -> value_list_validator< std::string >
 Given a parameter pack of types that are convertible to std::string, delegate to value type std::string.
 
template<std::ranges::forward_range range_type>
 value_list_validator (range_type &&rng) -> value_list_validator< std::string >
 Deduction guide for ranges over a value type convertible to std::string.
 
template<typename ... option_types>
 value_list_validator (option_types...) -> value_list_validator< seqan3::pack_traits::front< option_types... >>
 Deduction guide for a parameter pack.
 
template<std::ranges::forward_range range_type>
 value_list_validator (range_type &&rng) -> value_list_validator< std::ranges::range_value_t< range_type >>
 Deduction guide for ranges.
 
Requirements for seqan3::validator

You can expect these (meta-)functions on all types that implement seqan3::validator.

void operator() (option_value_type const &cmp) const
 Validates the value 'cmp' and throws a seqan3::validation_failed on failure. More...
 

Detailed Description

template<typename option_value_t>
class seqan3::value_list_validator< option_value_t >

A validator that checks whether a value is inside a list of valid values.

Template Parameters
option_value_tMust be a (container of) arithmetic type(s).

On construction, the validator must receive a range or parameter pack of valid values. The struct than acts as a functor, that throws a seqan3::parser_invalid_argument exception whenever a given value is not in the given list.

Note
In order to simplify the chaining of validators, the option value type is deduced to double for ranges whose value type models seqan3::arithmetic, and to std::string if the ranges value type is convertible to it. Otherwise, the option value type is deduced to the value type of the range.
int main(int argc, const char ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
int myint;
seqan3::value_list_validator my_validator{2, 4, 6, 8, 10};
myparser.add_option(myint,'i',"integer","Give me a number.",
// an exception will be thrown if the user specifies an integer
// that is not one of [2,4,6,8,10] (e.g. "./test_app -i 3")
try
{
myparser.parse();
}
catch (seqan3::parser_invalid_argument const & ext) // the user did something wrong
{
std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message
return -1;
}
seqan3::debug_stream << "integer given by user passed validation: " << myint << "\n";
return 0;
}

Constructor & Destructor Documentation

◆ value_list_validator() [1/2]

template<typename option_value_t >
template<std::ranges::forward_range range_type>
seqan3::value_list_validator< option_value_t >::value_list_validator ( range_type  rng)
inline

Constructing from a range.

Template Parameters
range_typeThe type of range; must model std::ranges::forward_range and value_list_validator::option_value_type must be constructible from the rvalue reference type of the given range.
Parameters
[in]rngThe range of valid values to test.

◆ value_list_validator() [2/2]

template<typename option_value_t >
template<typename ... option_types>
seqan3::value_list_validator< option_value_t >::value_list_validator ( option_types &&...  opts)
inline

Constructing from a parameter pack.

Template Parameters
option_typesThe type of option values in the parameter pack; The value_list_validator::option_value_type must be constructible from each type in the parameter pack.
Parameters
[in]optsThe parameter pack values.

Member Function Documentation

◆ operator()() [1/2]

template<typename option_value_t >
void seqan3::value_list_validator< option_value_t >::operator() ( option_value_type const &  cmp) const
inline

Tests whether cmp lies inside values.

Parameters
cmpThe input value to check.
Exceptions
parser_invalid_argument

◆ operator()() [2/2]

template<typename option_value_t >
template<std::ranges::forward_range range_type>
void seqan3::value_list_validator< option_value_t >::operator() ( range_type const &  range) const
inline

Tests whether every element in range lies inside values.

Template Parameters
range_typeThe type of range to check; must model std::ranges::forward_range.
Parameters
rangeThe input range to iterate over and check every element.
Exceptions
parser_invalid_argument

Friends And Related Function Documentation

◆ operator()()

void operator() ( option_value_type const &  cmp) const
related

Validates the value 'cmp' and throws a seqan3::validation_failed on failure.

Template Parameters
option_value_typeThe type of the value to be validated.
Parameters
[in,out]cmpThe value to be validated.
Exceptions
seqan3::validation_failedif value 'cmp' does not pass validation.
Attention
This is a concept requirement, not an actual function (however types satisfying this concept will provide an implementation).

◆ value_list_validator()

template<arithmetic ... option_types>
value_list_validator ( option_types...  ) -> value_list_validator< double >
related

Type deduction guides.

Deduction guide for a parameter pack over an arithmetic type.


The documentation for this class was generated from the following file: