19struct optional_argument_test_fixture;
30template <detail::c_argument_value_type T = std::
string>
52 return this->
_name == other._name;
139 template <action::detail::c_action_specifier AS,
typename F>
160 template <detail::c_range_of<value_type, detail::type_val
idator::convertible> CR>
162 requires(std::equality_comparable<value_type>)
164 for (
const auto& choice :
choices)
165 this->
_choices.emplace_back(choice);
176 requires(std::equality_comparable<value_type>)
178 return this->choices<>(
choices);
204 friend class ::ap::argument_parser;
210 friend struct ::ap_testing::optional_argument_test_fixture;
232 desc.
add_param(
"bypass required",
"true");
239 desc.
add_param(
"default value", std::any_cast<value_type>(this->_default_value));
241 desc.
add_param(
"implicit value", std::any_cast<value_type>(this->_implicit_value));
256 [[nodiscard]]
bool is_used() const noexcept
override {
261 [[nodiscard]] std::size_t
count() const noexcept
override {
280 if (not (std::istringstream(str_value) >>
value))
289 std::visit(apply_visitor,
action);
296 [[nodiscard]]
bool has_value() const noexcept
override {
302 return not this->
_values.empty();
307 if (this->
_values.empty() and this->_has_predefined_value())
308 return std::weak_ordering::equivalent;
314 [[nodiscard]]
const std::any&
value()
const override {
319 [[nodiscard]]
const std::vector<std::any>&
values()
const override {
336 throw(std::logic_error(
337 std::format(
"No implicit value specified for argument `{}`.", this->
_name.
str())
344 throw(std::logic_error(
345 std::format(
"No default value specified for argument `{}`.", this->
_name.
str())
Defines the base argument class and common utility.
Defines structures for formatting argument descriptions.
The optioanl argument class.
optional & bypass_required(const bool br=true) noexcept
Enable/disable bypassing the required attribute for the optional argument.
const std::vector< std::any > & values() const override
std::weak_ordering nvalues_ordering() const noexcept override
optional & help(std::string_view help_msg) noexcept
Set the help message for the optional argument.
std::vector< value_action_type > _value_actions
bool has_value() const noexcept override
bool set_value(const std::string &str_value) override
Set the value for the optional argument.
optional(const detail::argument_name &name)
Constructor for optional argument with the name identifier.
detail::argument_descriptor desc(const bool verbose) const noexcept override
bool _accepts_further_values() const noexcept
const std::any & _predefined_value() const
optional & choices(std::initializer_list< value_type > choices) noexcept
Set the choices for the optional argument.
bool is_used() const noexcept override
optional & action(F &&action) noexcept
Set the action for the optional argument.
std::vector< std::any > _values
optional & default_value(const std::convertible_to< value_type > auto &default_value) noexcept
Set the default value for the optional argument.
optional & implicit_value(const std::convertible_to< value_type > auto &implicit_value) noexcept
Set the implicit value for the optional argument.
nargs::range _nargs_range
bool mark_used() override
Mark the optional argument as used.
const std::any & value() const override
T value_type
The argument's value type.
bool has_parsed_values() const noexcept override
optional & required(const bool r=true) noexcept
Set the required attribute of the optional argument.
optional & nargs(const nargs::range &range) noexcept
Set the nargs range for the optional argument.
optional & nargs(const count_type lower_bound, const count_type upper_bound) noexcept
Set the nargs range for the optional argument.
optional & choices(const CR &choices) noexcept
Set the choices for the optional argument.
bool _has_predefined_value() const noexcept
std::size_t count() const noexcept override
typename action_type::on_flag::type flag_action_type
nargs::range::count_type count_type
The argument's value count type.
bool operator==(const optional &other) const noexcept
Equality comparison operator for optional argument.
optional & hidden(const bool h=true) noexcept
Set the hidden attribute for the positional argument.
std::vector< flag_action_type > _flag_actions
optional & nargs(const count_type n) noexcept
Set the nargs range for the optional argument.
std::vector< value_type > _choices
action::detail::value_action_variant_type< T > value_action_type
The argument's value action type.
Argument class interface.
const ap::detail::argument_name _name
const ap::detail::argument_name & name() const noexcept
bool bypass_required_enabled() const noexcept
std::optional< std::string > _help_msg
argument_base(const argument_name &name, const bool required=false)
A structure used to represent an argument's description.
void add_param(const std::string ¶m_name, const std::string &value)
Adds a parameter descriptor with the given string value.
void add_range_param(const std::string ¶m_name, const R &range, const std::string_view delimiter=default_delimiter)
Adds a range parameter descriptor with the given value.
std::vector< parameter_descriptor > params
Argument's number of values managing class.
std::weak_ordering ordering(const range::count_type n) const noexcept
Determines the ordering of the count against a range instance.
bool is_bound() const noexcept
Returns true if at least one bound (lower, upper) is set. Otherwise returns false
The concept is satisfied when AS is a valid value action action specifier.
The concept is satisfied when T can be constructed from const std::string&.
The concept is satisfied when T overloads the std::ostream operator <<.
Provides the general concept definitions.
typename AS::template type< T > callable_type
Template argument action callable type alias.
std::variant< callable_type< action_type::observe, T >, callable_type< action_type::transform, T >, callable_type< action_type::modify, T > > value_action_variant_type
Template argument action callabla variant type alias.
bool is_valid_choice(const T &value, const std::vector< T > &choices) noexcept
Checks if the provided choice is valid for the given set of choices.
range any() noexcept
range class builder function. Creates a range [0, inf].
Defines the nargs::range class and it's builder functions.
A visitor structure used to apply value actions.
std::function< void()> type
Structure holding the argument's name.
std::string str() const noexcept
Get a string representation of the argument_name.
static parsing_failure invalid_value(const detail::argument_name &arg_name, const std::string &value) noexcept
static parsing_failure invalid_nvalues(const detail::argument_name &arg_name, const std::weak_ordering ordering) noexcept
static parsing_failure invalid_choice(const detail::argument_name &arg_name, const std::string &value) noexcept
Defines general action-related utility.