SeqAn3  3.0.2
The Modern C++ library for sequence analysis.
seqan3::output_directory_validator Class Reference

A validator that checks if a given path is a valid output directory. More...

#include <seqan3/argument_parser/validators.hpp>

+ Inheritance diagram for seqan3::output_directory_validator:

Public Types

using option_value_type = std::string
 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.
 
template<std::ranges::forward_range range_type>
void operator() (range_type const &v) const
 Tests whether every path in list v passes validation. See operator()(option_value_type const & value) for further information. More...
 
virtual void operator() (std::filesystem::path const &dir) const override
 Tests whether path is writable. More...
 
Constructors, destructor and assignment
 output_directory_validator ()=default
 Defaulted.
 
 output_directory_validator (output_directory_validator const &)=default
 Defaulted.
 
 output_directory_validator (output_directory_validator &&)=default
 Defaulted.
 
output_directory_validatoroperator= (output_directory_validator const &)=default
 Defaulted.
 
output_directory_validatoroperator= (output_directory_validator &&)=default
 Defaulted.
 
virtual ~output_directory_validator ()=default
 Virtual Destructor.
 
 file_validator_base ()=default
 Defaulted.
 
 file_validator_base (file_validator_base const &)=default
 Defaulted.
 
 file_validator_base (file_validator_base &&)=default
 Defaulted.
 

Protected Member Functions

std::string valid_extensions_help_page_message () const
 Returns the information of valid file extensions.
 
void validate_filename (std::filesystem::path const &path) const
 Validates the given filename path based on the specified extensions. More...
 
void validate_readability (std::filesystem::path const &path) const
 Checks if the given path is readable. More...
 
void validate_writeability (std::filesystem::path const &path) const
 Checks if the given path is writable. More...
 

Protected Attributes

std::vector< std::stringextensions {}
 Stores the extensions.
 

Detailed Description

A validator that checks if a given path is a valid output directory.

The class acts as a functor that throws a seqan3::validation_error exception whenever a given path (std::filesystem::path) is not writable. This can happen if either the parent path does not exists, or the path doesn't have the proper write permissions.

int main(int argc, const char ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
myparser.add_option(mydir, 'd', "dir", "The output directory for storing the files.",
// an exception will be thrown if the user specifies a directory that cannot be created by the filesystem either
// because the parent path does not exists or the path has insufficient write permissions.
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 << "directory given by user passed validation: " << mydir << "\n";
return 0;
}
Note
The validator works on every type that can be implicitly converted to std::filesystem::path.

Member Function Documentation

◆ operator()() [1/2]

template<std::ranges::forward_range range_type>
void seqan3::file_validator_base::operator() ( range_type const &  v) const
inlineinherited

Tests whether every path in list v passes validation. See operator()(option_value_type const & value) for further information.

Template Parameters
range_typeThe type of range to check; must model std::ranges::forward_range and the value type must be convertible to std::filesystem::path.
Parameters
vThe input range to iterate over and check every element.
Exceptions
seqan3::validation_error

◆ operator()() [2/2]

virtual void seqan3::output_directory_validator::operator() ( std::filesystem::path const &  dir) const
inlineoverridevirtual

Tests whether path is writable.

Parameters
dirThe input value to check.
Exceptions
seqan3::validation_errorif the validation process failed. Might be nested with std::filesystem::filesystem_error on unhandled OS API errors.

Implements seqan3::file_validator_base.

◆ validate_filename()

void seqan3::file_validator_base::validate_filename ( std::filesystem::path const &  path) const
inlineprotectedinherited

Validates the given filename path based on the specified extensions.

Parameters
pathThe filename path.
Exceptions
seqan3::validation_errorif the specified extensions don't match the given path, or std::filesystem::filesystem_error on underlying OS API errors.

◆ validate_readability()

void seqan3::file_validator_base::validate_readability ( std::filesystem::path const &  path) const
inlineprotectedinherited

Checks if the given path is readable.

Parameters
pathThe path to check.
Returns
true if readable, otherwise false.
Exceptions
seqan3::validation_errorif the path is not readable, or std::filesystem::filesystem_error on underlying OS API errors.

◆ validate_writeability()

void seqan3::file_validator_base::validate_writeability ( std::filesystem::path const &  path) const
inlineprotectedinherited

Checks if the given path is writable.

Parameters
pathThe path to check.
Returns
true if writable, otherwise false.
Exceptions
seqan3::validation_errorif the file could not be opened for writing, or std::filesystem::filesystem_error on underlying OS API errors.

Friends And Related Function Documentation

◆ 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).

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
@ DEFAULT
The default were no checking or special displaying is happening.
Definition: auxiliary.hpp:234
std::cerr
filesystem
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...
seqan3::output_directory_validator
A validator that checks if a given path is a valid output directory.
Definition: validators.hpp:765
std::filesystem::path
all.hpp
Meta-Header for the argument parser module.
seqan3::argument_parser_error
Argument parser exception that is thrown whenever there is an error while parsing the command line ar...
Definition: exceptions.hpp:48
seqan3::debug_stream
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition: debug_stream.hpp:42
std::runtime_error::what
T what(T... args)