SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
validator Interface Reference

The concept for option validators passed to add_option/positional_option. More...

#include <seqan3/argument_parser/validators.hpp>

+ Inheritance diagram for validator:

Related Symbols

(Note that these are not member symbols.)

Requirements for seqan3::validator

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

using option_value_type
 The type of value on which the validator is called on.
 
void operator() (option_value_type const &cmp) const
 Validates the value 'cmp' and throws a seqan3::validation_error on failure.
 
std::string get_help_page_message () const
 Returns a message that can be appended to the (positional) options help page info.
 

Detailed Description

The concept for option validators passed to add_option/positional_option.

When adding (positional) options to the seqan3::argument_parser you may pass a function object that models seqan3::validator which checks the option value provided by the user for some constraint.

SeqAn provides several common-use-case validators, e.g. the seqan3::arithmetic_range_validator.

// 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;
seqan3::value_list_validator my_validator{2, 4, 6, 8, 10};
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 one of [2,4,6,8,10] (e.g. "./test_app -i 3")
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 value is inside a list of valid values.
Definition validators.hpp:200
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)

You can learn more about SeqAn validators in our tutorial.

To implement your own validator please refer to the detailed concept description below.

Concepts and doxygen

The requirements for this concept are given as related functions and type traits. Types that satisfy this concept are shown as "implementing this interface".

Friends And Related Symbol Documentation

◆ get_help_page_message()

std::string get_help_page_message ( ) const
related

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

Returns
A string that contains information on the performed validation.
Attention
This is a concept requirement, not an actual function (however types satisfying this concept will provide an implementation).
Remarks
For a complete overview, take a look at Argument Parser

Implemented in seqan3::arithmetic_range_validator< option_value_t >, seqan3::value_list_validator< option_value_t >, seqan3::input_file_validator< file_t >, seqan3::output_file_validator< file_t >, seqan3::input_directory_validator, seqan3::output_directory_validator, and seqan3::regex_validator.

◆ operator()()

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

Validates the value 'cmp' and throws a seqan3::validation_error 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_errorif 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).

◆ option_value_type()

using option_value_type
related

The type of value on which the validator is called on.

Attention
This is a concept requirement, not an actual typedef (however types satisfying this concept will provide an implementation).

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