SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
seqan3::arithmetic_range_validator Class Reference

A validator that checks whether a number is inside a given range. More...

#include <seqan3/argument_parser/validators.hpp>

+ Inheritance diagram for seqan3::arithmetic_range_validator:

Public Types

using option_value_type = double
 The type of value that this validator invoked upon.
 

Public Member Functions

 arithmetic_range_validator (option_value_type const min_, option_value_type const max_)
 The constructor. More...
 
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 [min, max]. More...
 
template<std::ranges::forward_range range_type>
void operator() (range_type const &range) const
 Tests whether every element in range lies inside [min, max]. More...
 

Related Functions

(Note that these are not member functions.)

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

A validator that checks whether a number is inside a given range.

On construction, the validator must receive a maximum and a minimum number. The struct than acts as a functor, that throws a seqan3::parser_invalid_argument exception whenever a given value does not lie inside the given min/max range.

int main(int argc, const char ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
int myint;
myparser.add_option(myint,'i',"integer","Give me a number.",
// an exception will be thrown if the user specifies an integer
// that is not in range [2,10] (e.g. "./test_app -i 15")
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

◆ arithmetic_range_validator()

seqan3::arithmetic_range_validator::arithmetic_range_validator ( option_value_type const  min_,
option_value_type const  max_ 
)
inline

The constructor.

Parameters
[in]min_Minimum set for the range to test.
[in]max_Maximum set for the range to test.

Member Function Documentation

◆ operator()() [1/2]

void seqan3::arithmetic_range_validator::operator() ( option_value_type const &  cmp) const
inline

Tests whether cmp lies inside [min, max].

Parameters
cmpThe input value to check.
Exceptions
parser_invalid_argument

◆ operator()() [2/2]

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

Tests whether every element in range lies inside [min, max].

Template Parameters
range_typeThe type of range to check; must model std::ranges::forward_range. The value type must model seqan3::arithmetic.
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).

The documentation for this class was generated from the following file:
debug_stream.hpp
Provides seqan3::debug_stream and related types.
seqan3::argument_parser
The SeqAn command line parser.
Definition: argument_parser.hpp:153
seqan3::DEFAULT
The default were no checking or special displaying is happening.
Definition: auxiliary.hpp:233
std::cerr
seqan3::arithmetic_range_validator
A validator that checks whether a number is inside a given range.
Definition: validators.hpp:108
all.hpp
Meta-Header for the argument parser module.
seqan3::parser_invalid_argument
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition: exceptions.hpp:37
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:39
std::invalid_argument::what
T what(T... args)