SeqAn3
seqan3::file_ext_validator Class Reference

A validator that checks if a filenames has one of the valid extensions. More...

#include <seqan3/argument_parser/validators.hpp>

Inheritance diagram for seqan3::file_ext_validator:
[legend]

Public Types

using value_type = std::string
 Type of values that are tested by validator.
 

Public Member Functions

 file_ext_validator (std::vector< std::string > const &v)
 Constructing from a vector. More...
 
 file_ext_validator (std::initializer_list< std::string > const &v)
 Constructing from an initializer_list. More...
 
std::string get_help_page_message () const
 Returns a message that can be appended to the (positional) options help page info.
 
void operator() (filesystem::path const &path) const
 Tests whether the filepath path ends with a valid extension. More...
 
void operator() (std::vector< std::string > const &v) const
 Tests whether every value of v lies inside extensions.
 

Related Functions

(Note that these are not member functions.)

Requirements for seqan3::validator_concept

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

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

Detailed Description

A validator that checks if a filenames has one of the valid extensions.

On construction, the validator must receive a list (vector) of valid file extensions. The struct than acts as a functor, that throws a seqan3::parser_invalid_argument exception whenever a given filename (string) is not in the given extension list.

int main(int argc, const char ** argv)
{
seqan3::argument_parser myparser("Test", argc, argv); // initialize
std::string myfile;
seqan3::file_ext_validator my_validator{"fa","fasta"};
myparser.add_option(myfile,'f',"file","Give me a filename.",
// an exception will be thrown if the user specifies a filename
// that does not have one of the extensions ["fa","fasta"]
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;
}
catch (seqan3::parser_interruption const &) // expected behaviour on special requests (e.g. `--help`)
{
return 0;
}
seqan3::debug_stream << "filename given by user passed validation: " << myfile << "\n";
return 0;
}

Constructor & Destructor Documentation

◆ file_ext_validator() [1/2]

seqan3::file_ext_validator::file_ext_validator ( std::vector< std::string > const &  v)
inline

Constructing from a vector.

Parameters
[in]vThe vector of valid file extensions to test (e.g. {"fa", "fasta"}).

◆ file_ext_validator() [2/2]

seqan3::file_ext_validator::file_ext_validator ( std::initializer_list< std::string > const &  v)
inline

Constructing from an initializer_list.

Parameters
[in]vThe initializer_list of valid file extensions to test (e.g. {"fa", "fasta"}).

Member Function Documentation

◆ operator()()

void seqan3::file_ext_validator::operator() ( filesystem::path const &  path) const
inline

Tests whether the filepath path ends with a valid extension.

Parameters
pathThe input value to check.
Exceptions
parser_invalid_argument

Friends And Related Function Documentation

◆ operator()()

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

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

Template Parameters
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).

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