SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::input_directory_validator Class Reference

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

#include <seqan3/argument_parser/validators.hpp>

+ Inheritance diagram for seqan3::input_directory_validator:

Public Types

using option_value_type = std::string
 Type of values that are tested by validator.
 
- Public Types inherited from seqan3::file_validator_base
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.
 
virtual void operator() (std::filesystem::path const &dir) const override
 Tests whether path is an existing directory and is readable.
 
Constructors, destructor and assignment
 input_directory_validator ()=default
 Defaulted.
 
 input_directory_validator (input_directory_validator const &)=default
 Defaulted.
 
 input_directory_validator (input_directory_validator &&)=default
 Defaulted.
 
input_directory_validatoroperator= (input_directory_validator const &)=default
 Defaulted.
 
input_directory_validatoroperator= (input_directory_validator &&)=default
 Defaulted.
 
virtual ~input_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.
 
- Public Member Functions inherited from seqan3::file_validator_base
template<std::ranges::forward_range range_type>
requires (std::convertible_to<std::ranges::range_value_t<range_type>, std::filesystem::path const &> && !std::convertible_to<range_type, std::filesystem::path const &>)
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.
 
 file_validator_base ()=default
 Defaulted.
 
 file_validator_base (file_validator_base const &)=default
 Defaulted.
 
 file_validator_base (file_validator_base &&)=default
 Defaulted.
 
file_validator_baseoperator= (file_validator_base const &)=default
 Defaulted.
 
file_validator_baseoperator= (file_validator_base &&)=default
 Defaulted.
 
virtual ~file_validator_base ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from seqan3::file_validator_base
bool case_insensitive_string_ends_with (std::string_view str, std::string_view suffix) const
 Helper function that checks if a string is a suffix of another string. Case insensitive.
 
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.
 
void validate_readability (std::filesystem::path const &path) const
 Checks if the given path is readable.
 
void validate_writeability (std::filesystem::path const &path) const
 Checks if the given path is writable.
 
- Protected Attributes inherited from seqan3::file_validator_base
std::vector< std::stringextensions {}
 Stores the extensions.
 

Detailed Description

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

The class acts as a functor that throws a seqan3::validation_error exception whenever a given directory (std::filesystem::path) does not exist, the specified path is not a directory, or if the directory is not readable.

// 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
#include <filesystem>
int main(int argc, char const ** argv)
{
seqan3::argument_parser myparser{"Test", argc, argv}; // initialize
myparser.add_option(mydir,
'd',
"dir",
"The directory containing the input files.",
// an exception will be thrown if the user specifies a directory that does not exists or has insufficient
// read 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;
}
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 if a given path is a valid input directory.
Definition validators.hpp:763
Provides seqan3::debug_stream and related types.
@ standard
The default were no checking or special displaying is happening.
Definition auxiliary.hpp:242
debug_stream_type debug_stream
A global instance of seqan3::debug_stream_type.
Definition debug_stream.hpp:37
T what(T... args)
Note
The validator works on every type that can be implicitly converted to std::filesystem::path.
Remarks
For a complete overview, take a look at Argument Parser

Member Function Documentation

◆ get_help_page_message()

std::string seqan3::input_directory_validator::get_help_page_message ( ) const
inline

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

Implements validator.

◆ operator()()

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

Tests whether path is an existing directory and is readable.

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.


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