SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::arithmetic_range_validator< option_value_t > Class Template 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< option_value_t >:

Public Types

using option_value_type = option_value_t
 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.
 
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].
 
template<std::ranges::forward_range range_type>
requires arithmetic<std::ranges::range_value_t<range_type>>
void operator() (range_type const &range) const
 Tests whether every element in range lies inside [min, max].
 

Private Attributes

option_value_type max {}
 Maximum of the range to test.
 
option_value_type min {}
 Minimum of the range to test.
 

Additional Inherited Members

Detailed Description

template<arithmetic option_value_t>
class seqan3::arithmetic_range_validator< option_value_t >

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

Template Parameters
option_value_tThe value type of the range; must model seqan3::arithmetic .

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

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
int myint;
myparser.add_option(myint, 'i', "integer", "Give me a number.", seqan3::option_spec::standard, my_validator);
// 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::argument_parser_error 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;
}
Meta-header for the Argument Parser module .
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition exceptions.hpp:37
The SeqAn command line parser.
Definition argument_parser.hpp:145
A validator that checks whether a number is inside a given range.
Definition validators.hpp:125
Provides seqan3::debug_stream and related types.
@ standard
The default were no checking or special displaying is happening.
Definition auxiliary.hpp:246
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
T what(T... args)
Remarks
For a complete overview, take a look at Argument Parser

Constructor & Destructor Documentation

◆ arithmetic_range_validator()

template<arithmetic option_value_t>
seqan3::arithmetic_range_validator< option_value_t >::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

◆ get_help_page_message()

template<arithmetic option_value_t>
std::string seqan3::arithmetic_range_validator< option_value_t >::get_help_page_message ( ) const
inline

Returns a message that can be appended to the (positional) options help page info.

Implements validator.

◆ operator()() [1/2]

template<arithmetic option_value_t>
void seqan3::arithmetic_range_validator< option_value_t >::operator() ( option_value_type const &  cmp) const
inline

Tests whether cmp lies inside [min, max].

Parameters
cmpThe input value to check.
Exceptions
seqan3::validation_error

◆ operator()() [2/2]

template<arithmetic option_value_t>
template<std::ranges::forward_range range_type>
requires arithmetic<std::ranges::range_value_t<range_type>>
void seqan3::arithmetic_range_validator< option_value_t >::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
seqan3::validation_error

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