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 C++ CLI for .type_various() #3067

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
36 changes: 19 additions & 17 deletions cpp/core/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,30 +1296,32 @@ int64_t App::ParsedArgument::as_int() const {
}
return static_cast<int>(std::distance(choices.begin(), it));
}
assert(0);
return (0);

assert(arg->type == Various);
return to<int64_t>(p);
}

default_type App::ParsedArgument::as_float() const {
assert(arg->type == Float);
assert(arg->type == Float || arg->type == Various);
const default_type retval = to<default_type>(p);
const auto range = std::get<Argument::FloatRange>(arg->limits);
if (retval < range.min || retval > range.max) {
std::string msg("value supplied for ");
if (opt)
msg += std::string("option \"") + opt->id;
else
msg += std::string("argument \"") + arg->id;
msg += "\" is out of bounds (valid range: " + str(range.min) + " to " + str(range.max) +
", value supplied: " + str(retval) + ")";
throw Exception(msg);
if (arg->type == Float) {
const auto range = std::get<Argument::FloatRange>(arg->limits);
if (retval < range.min || retval > range.max) {
std::string msg("value supplied for ");
if (opt)
msg += std::string("option \"") + opt->id;
else
msg += std::string("argument \"") + arg->id;
msg += "\" is out of bounds (valid range: " + str(range.min) + " to " + str(range.max) +
", value supplied: " + str(retval) + ")";
throw Exception(msg);
}
}

return retval;
}

std::vector<int32_t> ParsedArgument::as_sequence_int() const {
assert(arg->type == IntSeq);
assert(arg->type == IntSeq || arg->type == Various);
try {
return parse_ints<int32_t>(p);
} catch (Exception &e) {
Expand All @@ -1329,7 +1331,7 @@ std::vector<int32_t> ParsedArgument::as_sequence_int() const {
}

std::vector<uint32_t> ParsedArgument::as_sequence_uint() const {
assert(arg->type == IntSeq);
assert(arg->type == IntSeq || arg->type == Various);
try {
return parse_ints<uint32_t>(p);
} catch (Exception &e) {
Expand All @@ -1339,7 +1341,7 @@ std::vector<uint32_t> ParsedArgument::as_sequence_uint() const {
}

std::vector<default_type> ParsedArgument::as_sequence_float() const {
assert(arg->type == FloatSeq);
assert(arg->type == FloatSeq || arg->type == Various);
try {
return parse_floats(p);
} catch (Exception &e) {
Expand Down
4 changes: 3 additions & 1 deletion cpp/core/cmdline_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ class Argument {
struct FloatRange {
default_type min, max;
};
struct VoidRange {};

//! a structure to store the various parameters of the Argument
using Limits = std::variant<std::vector<std::string>, IntRange, FloatRange>;
using Limits = std::variant<std::vector<std::string>, IntRange, FloatRange, VoidRange>;
Limits limits;

operator bool() const { return id.empty(); }
Expand Down Expand Up @@ -279,6 +280,7 @@ class Argument {
Argument &type_various() {
assert(type == Undefined);
type = Various;
limits = VoidRange();
return *this;
}

Expand Down
Loading