Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] floating point validator #16

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions src/stellar3.arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@
namespace stellar::app
{

struct float_in_range_validator
{
using option_value_type = double; // used for all arithmetic types

option_value_type min;
option_value_type max;

float_in_range_validator(option_value_type min_value, option_value_type max_value) : min{min_value}, max{max_value} {}

void operator()(option_value_type const & val) const
{
if ((min >= val) || (val >= max))
{
throw sharg::validation_error{"Value must be in range [" + std::to_string(min) +
", " + std::to_string(max) + "]."};
}
}

std::string get_help_page_message() const
{
return "Value must be in range [" + std::to_string(min) +
", " + std::to_string(max) + "].";
}
};

struct sequence_vector_validator
{
using el_value_type = size_t; // used for all arithmetic types
Expand Down Expand Up @@ -89,7 +64,7 @@ void init_parser(sharg::parser & parser, StellarOptions & options)
sharg::config{.short_id = 'e',
.long_id = "epsilon",
.description = "Maximal error rate (max 0.25).",
.validator = float_in_range_validator{0, 0.25}});
.validator = sharg::arithmetic_range_validator{0.0, 0.25}});
parser.add_option(options.minLength,
sharg::config{.short_id = 'l',
.long_id = "minLength",
Expand Down Expand Up @@ -157,7 +132,7 @@ void init_parser(sharg::parser & parser, StellarOptions & options)
sharg::config{.short_id = 'c',
.long_id = "abundanceCut",
.description = "k-mer overabundance cut ratio.",
.validator = float_in_range_validator{0, 1}});
.validator = sharg::arithmetic_range_validator{0, 1}});

// Verification options
parser.add_option(options.xDrop,
Expand Down