CPP-AP 3.0.1
Command-line argument parser for C++20
Loading...
Searching...
No Matches
ap::argument< ArgT, T > Class Template Reference

Represents a command-line argument, either positional or optional. More...

#include <argument.hpp>

Inheritance diagram for ap::argument< ArgT, T >:
ap::detail::argument_base

Public Types

using value_type = T
 The argument's value type alias.
 
using count_type = nargs::count_type
 The argument's count type alias.
 

Public Member Functions

 argument ()=delete
 
 argument (const detail::argument_name &name)
 Positional argument constructor.
 
 argument (const detail::argument_name &name)
 Optional argument constructor.
 
bool is_positional () const noexcept override
 Checks if the argument is positional.
 
bool is_optional () const noexcept override
 Checks if the argument is optional.
 
const ap::detail::argument_namename () const noexcept override
 
const std::optional< std::string > & help () const noexcept override
 
bool is_hidden () const noexcept override
 
bool is_required () const noexcept override
 
bool suppresses_arg_checks () const noexcept override
 
bool suppresses_group_checks () const noexcept override
 
bool is_greedy () const noexcept override
 
argumenthelp (std::string_view help_msg) noexcept
 Set the help message for the argument.
 
argumenthidden (const bool h=true) noexcept
 Set the hidden attribute for the argument.
 
argumentrequired (const bool value=true)
 Set the required attribute of the argument.
 
argumentsuppress_arg_checks (const bool value=true)
 Enable/disable suppressing argument checks for other arguments.
 
argumentsuppress_group_checks (const bool value=true)
 Enable/disable suppressing argument group checks.
 
argumentgreedy (const bool value=true) noexcept
 Set the greedy attribute of the argument.
 
argumentnargs (const nargs::range &range) noexcept
 Set the nargs range for the argument.
 
argumentnargs (const count_type n) noexcept
 Set the nargs range for the argument.
 
argumentnargs (const count_type lower, const count_type upper) noexcept
 Set the nargs range for the optional argument.
 
template<action::util::c_value_action_specifier AS, typename F >
requires (not util::c_is_none<value_type>)
argumentaction (F &&action) noexcept
 Set the value action for the argument.
 
template<action::util::c_flag_action_specifier AS, typename F >
requires (type == argument_type::optional)
argumentaction (F &&action) noexcept
 Set the on-flag action for the argument.
 
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>)
argumentchoices (const CR &choices) noexcept
 Add the choices for the argument.
 
argumentchoices (std::initializer_list< value_type > choices) noexcept
 Add the choices for the argument.
 
argumentchoices (const std::convertible_to< value_type > auto &... choices) noexcept
 Add the choices for the argument.
 
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>)
argumentdefault_values (const CR &values) noexcept
 Add default values for the argument.
 
argumentdefault_values (std::initializer_list< value_type > values) noexcept
 Add default values for the argument.
 
argumentdefault_values (const std::convertible_to< value_type > auto &... values) noexcept
 Add default values for the argument.
 
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and type == argument_type::optional)
argumentimplicit_values (const CR &values) noexcept
 Add implicit values for the optional argument.
 
argumentimplicit_values (std::initializer_list< value_type > values) noexcept
 Add implicit values for the optional argument.
 
argumentimplicit_values (const std::convertible_to< value_type > auto &... values) noexcept
 Add a implicit values for the optional argument.
 
- Public Member Functions inherited from ap::detail::argument_base
virtual ~argument_base ()=default
 

Static Public Attributes

static constexpr argument_type type = ArgT
 The argument's type discriminator.
 

Private Types

using value_action_type = action::util::value_action_variant_type< T >
 The argument's value action type alias.
 
using flag_action_type = typename action_type::on_flag::type
 The argument's flag action type alias.
 
template<typename _T >
using value_arg_specific_type = std::conditional_t< util::c_is_none< value_type >, none_type, _T >
 Type alias for value-argument-specific types.
 
template<typename _T >
using positional_specific_type = std::conditional_t< type==argument_type::positional, _T, none_type >
 The argument's positional-argument-specific type alias.
 
template<typename _T >
using optional_specific_type = std::conditional_t< type==argument_type::optional, _T, none_type >
 The argument's optional-argument-specific type alias.
 

Private Member Functions

detail::help_builder help_builder (const bool verbose) const noexcept override
 Creates a help message builder object for the argument.
 
bool mark_used () override
 Mark the optional argument as used.
 
bool is_used () const noexcept override
 
std::size_t count () const noexcept override
 
bool set_value (const std::string &str_value) override
 Set the value for the optional argument.
 
bool has_value () const noexcept override
 
bool has_parsed_values () const noexcept override
 
bool has_predefined_values () const noexcept override
 
std::weak_ordering nvalues_ordering () const noexcept override
 
const std::any & value () const override
 
const std::vector< std::any > & values () const override
 
const std::vector< std::any > & _values_impl () const noexcept
 
const std::vector< std::any > & _values_impl () const noexcept
 
bool _has_predefined_values_impl () const noexcept
 
bool _has_predefined_values_impl () const noexcept
 
const std::vector< std::any > & _predefined_values () const
 
bool _accepts_further_values () const noexcept
 
bool _is_valid_choice (const value_type &value) const noexcept
 
bool _set_value_impl (const std::string &str_value)
 The implementation of the set_value method for none-type arguments.
 
bool _set_value_impl (const std::string &str_value)
 The implementation of the set_value method for non-none-type arguments.
 

Private Attributes

const ap::detail::argument_name _name
 The argument's name.
 
std::optional< std::string > _help_msg
 The argument's help message.
 
nargs::range _nargs_range
 The argument's nargs range attribute value.
 
value_arg_specific_type< std::vector< std::any > > _default_values
 The argument's default value list.
 
value_arg_specific_type< optional_specific_type< std::vector< std::any > > > _implicit_values
 The optional argument's implicit value list.
 
value_arg_specific_type< std::vector< value_type > > _choices
 The argument's valid choices collection.
 
optional_specific_type< std::vector< flag_action_type > > _flag_actions
 The optional argument's flag actions collection.
 
value_arg_specific_type< std::vector< value_action_type > > _value_actions
 The argument's value actions collection.
 
bool _required: 1
 The argument's required attribute value.
 
bool _suppress_arg_checks: 1 = false
 The argument's suppress_arg_checks attribute value.
 
bool _suppress_group_checks: 1 = false
 The argument's suppress_group_checks attribute value.
 
bool _greedy: 1 = false
 The argument's greedy attribute value.
 
bool _hidden: 1 = false
 The argument's hidden attribute value.
 
optional_specific_type< std::size_t > _count
 The argument's value count.
 
std::vector< std::any > _values
 The argument's parsed values.
 

Static Private Attributes

static constexpr bool _default_required = (type == argument_type::positional)
 
static constexpr nargs::range _default_nargs_range
 
static constexpr nargs::range _default_nargs_range_actual
 

Additional Inherited Members

Detailed Description

template<argument_type ArgT, util::c_argument_value_type T = std::string>
class ap::argument< ArgT, T >

Represents a command-line argument, either positional or optional.

This class defines the behaviour of command-line arguments - both positional and optional, depending on the given type discriminator.

Note
This class is not intended to be constructed directly, but rather throught the
- add_positional_argument
- add_optional_argument
- add_flag
methods of ap::argument_parser.
Attention
Some member functions are conditionally enabled/disabled depending on the argument type and value type.

Example usage:

parser.add_positional_argument("input", "i")
.help("An input file path");
parser.add_optional_argument("output", "o")
.default_values("out.txt")
.help("An output file path");
The main argument parser class.
optional_argument< T > & add_optional_argument(const std::string_view name, const detail::argument_name_discriminator name_discr=n_primary)
Adds an optional argument to the parser's configuration.
positional_argument< T > & add_positional_argument(const std::string_view name)
Adds a positional argument to the parser's configuration.
Template Parameters
ArgTThe argument type, either ap::argument_type::positional or ap::argument_type::optional.
TThe value type accepted by the argument (defaults to std::string).

Definition at line 58 of file argument.hpp.

Member Typedef Documentation

◆ count_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
using ap::argument< ArgT, T >::count_type = nargs::count_type

The argument's count type alias.

Definition at line 61 of file argument.hpp.

◆ flag_action_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
using ap::argument< ArgT, T >::flag_action_type = typename action_type::on_flag::type
private

The argument's flag action type alias.

Definition at line 430 of file argument.hpp.

◆ optional_specific_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<typename _T >
using ap::argument< ArgT, T >::optional_specific_type = std::conditional_t<type == argument_type::optional, _T, none_type>
private

The argument's optional-argument-specific type alias.

Template Parameters
_TThe actual type used if the argument's type is argument_type::optional.

Definition at line 449 of file argument.hpp.

◆ positional_specific_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<typename _T >
using ap::argument< ArgT, T >::positional_specific_type = std::conditional_t<type == argument_type::positional, _T, none_type>
private

The argument's positional-argument-specific type alias.

Template Parameters
_TThe actual type used if the argument's type is argument_type::positional.

Definition at line 443 of file argument.hpp.

◆ value_action_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
using ap::argument< ArgT, T >::value_action_type = action::util::value_action_variant_type<T>
private

The argument's value action type alias.

Definition at line 427 of file argument.hpp.

◆ value_arg_specific_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<typename _T >
using ap::argument< ArgT, T >::value_arg_specific_type = std::conditional_t< util::c_is_none<value_type>, none_type, _T>
private

Type alias for value-argument-specific types.

Definition at line 435 of file argument.hpp.

◆ value_type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
using ap::argument< ArgT, T >::value_type = T

The argument's value type alias.

Definition at line 60 of file argument.hpp.

Constructor & Destructor Documentation

◆ argument() [1/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
ap::argument< ArgT, T >::argument ( )
delete

◆ argument() [2/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
ap::argument< ArgT, T >::argument ( const detail::argument_name name)
inline

Positional argument constructor.

Parameters
nameThe name of the positional argument.
Note
The constructor is enabled only if type is argument_type::positional.

Definition at line 72 of file argument.hpp.

◆ argument() [3/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
ap::argument< ArgT, T >::argument ( const detail::argument_name name)
inline

Optional argument constructor.

Parameters
nameThe name of the optional argument.
Note
The constructor is enabled only if type is argument_type::optional.

Definition at line 81 of file argument.hpp.

Member Function Documentation

◆ _accepts_further_values()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_accepts_further_values ( ) const
inlineprivatenoexcept
Returns
true if the argument accepts further values, false otherwise.

Definition at line 657 of file argument.hpp.

◆ _has_predefined_values_impl() [1/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_has_predefined_values_impl ( ) const
inlineprivatenoexcept
Returns
true if the argument has a predefined value, false otherwise.

Definition at line 605 of file argument.hpp.

◆ _has_predefined_values_impl() [2/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_has_predefined_values_impl ( ) const
inlineprivatenoexcept
Returns
true if the argument has a predefined value, false otherwise.
Note
The method is enabled only if value_type is not none_type.
- For positional arguments, a predefined value exists if a default value is set.
- For optional arguments, a predefined value exists if either a default value is set or if the argument has been used and an implicit value is set.

Definition at line 617 of file argument.hpp.

◆ _is_valid_choice()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_is_valid_choice ( const value_type value) const
inlineprivatenoexcept
Returns
true if the given value is a valid choice for the argument, false otherwise.
Todo:
Use std::ranges::contains after the switch to C++23

Definition at line 663 of file argument.hpp.

◆ _predefined_values()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::vector< std::any > & ap::argument< ArgT, T >::_predefined_values ( ) const
inlineprivate
Returns
Reference to the argument's predefined value list.
Exceptions
std::logic_errorif no predefined values are available.
Note
The method is enabled only if value_type is not none_type.
- For positional arguments, the default value list is returned.
- For optional arguments, if the argument has been used, the implicit value list is returned, otherwise the default value list is returned.

Definition at line 634 of file argument.hpp.

◆ _set_value_impl() [1/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_set_value_impl ( const std::string &  str_value)
inlineprivate

The implementation of the set_value method for none-type arguments.

Parameters
str_valueThe string value to set.
Exceptions
ap::parsing_failure
Attention
Always throws! (set_value should never be called for a none-type argument).

Definition at line 676 of file argument.hpp.

◆ _set_value_impl() [2/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_set_value_impl ( const std::string &  str_value)
inlineprivate

The implementation of the set_value method for non-none-type arguments.

Returns
true if the argument accepts further values, false otherwise.
Parameters
str_valueThe string value to set.
Exceptions
ap::parsing_failureif:
-the argument does not accept further values (nargs limit exceeded).
-the value cannot be parsed to the argument's value_type.
-the value is not a valid choice for the argument (if choices are defined).
Note
The method is enabled only if value_type is not none_type.

Definition at line 696 of file argument.hpp.

◆ _values_impl() [1/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::vector< std::any > & ap::argument< ArgT, T >::_values_impl ( ) const
inlineprivatenoexcept
Returns
Reference to the vector of parsed values for the argument.
Note
For none-type arguments, the method always returns an empty vector.

Definition at line 579 of file argument.hpp.

◆ _values_impl() [2/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::vector< std::any > & ap::argument< ArgT, T >::_values_impl ( ) const
inlineprivatenoexcept
Returns
Reference to the vector of parsed values for the argument.
Note
If no parsed values are available, the method attempts to return the predefined values (default/implicit).
The method is enabled only if value_type is not none_type.

Definition at line 590 of file argument.hpp.

◆ action() [1/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<action::util::c_value_action_specifier AS, typename F >
requires (not util::c_is_none<value_type>)
argument & ap::argument< ArgT, T >::action ( F &&  action)
inlinenoexcept

Set the value action for the argument.

Template Parameters
ASThe action specifier type (see ap/action/type.hpp).
FThe type of the action function.
Parameters
actionThe action callable.
Returns
Reference to the argument instance.
Note
The method is enabled only if:
- value_type is not none_type.
- AS is a valid value action specifier: action_type::observe, action_type::transform, action_type::modify.

Definition at line 267 of file argument.hpp.

◆ action() [2/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<action::util::c_flag_action_specifier AS, typename F >
requires (type == argument_type::optional)
argument & ap::argument< ArgT, T >::action ( F &&  action)
inlinenoexcept

Set the on-flag action for the argument.

Template Parameters
ASThe action specifier type (see ap/action/types.hpp).
FThe type of the action function.
Parameters
actionThe action callable.
Returns
Reference to the argument instance.
Note
The method is enabled only for optional arguments and if AS is action_type::on_flag.

Definition at line 284 of file argument.hpp.

◆ choices() [1/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>)
argument & ap::argument< ArgT, T >::choices ( const CR &  choices)
inlinenoexcept

Add the choices for the argument.

Template Parameters
CRThe choices range type.
Parameters
choicesThe range of valid choices for the argument.
Returns
Reference to the argument instance.
Note
The method is enabled only if:
- value_type must not be none_type and must be equality comparable
- CR must be a range such that its value type is convertible to the argument's value_type

Definition at line 301 of file argument.hpp.

◆ choices() [2/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::choices ( const std::convertible_to< value_type > auto &...  choices)
inlinenoexcept

Add the choices for the argument.

Template Parameters
ArgsThe types of the choices.
Parameters
choicesThe list of valid choices for the argument.
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type and is equality comparable.

Definition at line 328 of file argument.hpp.

◆ choices() [3/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::choices ( std::initializer_list< value_type choices)
inlinenoexcept

Add the choices for the argument.

Parameters
choicesThe list of valid choices for the argument.
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type and is equality comparable.

Definition at line 315 of file argument.hpp.

◆ count()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
std::size_t ap::argument< ArgT, T >::count ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
The number of times the argument has been used.
Note
- For positional arguments, the count is either 0 (not used) or 1 (used).
- For optional arguments, the count reflects the number of times the argument's flag has been used.

Implements ap::detail::argument_base.

Definition at line 514 of file argument.hpp.

◆ default_values() [1/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>)
argument & ap::argument< ArgT, T >::default_values ( const CR &  values)
inlinenoexcept

Add default values for the argument.

Parameters
valuesThe default values to add.
Returns
Reference to the argument instance.
Attention
Setting the default values resets the required attribute to false.
Note
The method is enabled only if value_type is not none_type.

Definition at line 343 of file argument.hpp.

◆ default_values() [2/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::default_values ( const std::convertible_to< value_type > auto &...  values)
inlinenoexcept

Add default values for the argument.

Parameters
valuesThe default values to add.
Returns
Reference to the argument instance.
Attention
Setting the default values resets the required attribute to false.
Note
The method is enabled only if value_type is not none_type.

Definition at line 372 of file argument.hpp.

◆ default_values() [3/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::default_values ( std::initializer_list< value_type values)
inlinenoexcept

Add default values for the argument.

Parameters
valuesThe default values to add.
Returns
Reference to the argument instance.
Attention
Setting the default values resets the required attribute to false.
Note
The method is enabled only if value_type is not none_type.

Definition at line 359 of file argument.hpp.

◆ greedy()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::greedy ( const bool  value = true)
inlinenoexcept

Set the greedy attribute of the argument.

Parameters
valueThe attribute value (default: true).
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type.

Definition at line 211 of file argument.hpp.

◆ has_parsed_values()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::has_parsed_values ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
true if parsed values are available for the argument, false otherwise.

Implements ap::detail::argument_base.

Definition at line 538 of file argument.hpp.

◆ has_predefined_values()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::has_predefined_values ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
true if the argument has predefined values, false otherwise.

Implements ap::detail::argument_base.

Definition at line 543 of file argument.hpp.

◆ has_value()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::has_value ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
true if the argument has a value, false otherwise.
Note
An argument is considered to have a value if it has parsed values or predefined values (default/implicit).

Implements ap::detail::argument_base.

Definition at line 533 of file argument.hpp.

◆ help() [1/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::optional< std::string > & ap::argument< ArgT, T >::help ( ) const
inlineoverridevirtualnoexcept
Returns
Optional help message for the positional argument.

Implements ap::detail::argument_base.

Definition at line 106 of file argument.hpp.

◆ help() [2/2]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::help ( std::string_view  help_msg)
inlinenoexcept

Set the help message for the argument.

Parameters
help_msgThe help message to set.
Returns
Reference to the argument instance.

Definition at line 142 of file argument.hpp.

◆ help_builder()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
detail::help_builder ap::argument< ArgT, T >::help_builder ( const bool  verbose) const
inlineoverrideprivatevirtualnoexcept

Creates a help message builder object for the argument.

Parameters
verboseThe verbosity mode value.
Note
If the verbose parameter is set to true all non-default parameters will be included in the output,
otherwise only the argument's name and help message will be included.

Implements ap::detail::argument_base.

Definition at line 458 of file argument.hpp.

◆ hidden()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::hidden ( const bool  h = true)
inlinenoexcept

Set the hidden attribute for the argument.

Parameters
hThe attribute value.
Returns
Reference to the argument instance.

Definition at line 152 of file argument.hpp.

◆ implicit_values() [1/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
template<util::c_range_of< value_type, util::type_validator::convertible > CR>
requires (not util::c_is_none<value_type> and type == argument_type::optional)
argument & ap::argument< ArgT, T >::implicit_values ( const CR &  values)
inlinenoexcept

Add implicit values for the optional argument.

Template Parameters
CRThe choices range type.
Parameters
valuesThe range of implicit values to set.
Returns
Reference to the optional argument instance.
Note
The method is enabled only for optional arguments and if value_type is not none_type.

Definition at line 388 of file argument.hpp.

◆ implicit_values() [2/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::implicit_values ( const std::convertible_to< value_type > auto &...  values)
inlinenoexcept

Add a implicit values for the optional argument.

Parameters
valuesThe implicit values to set.
Returns
Reference to the optional argument instance.
Note
The method is enabled only for optional arguments and if value_type is not none_type.

Definition at line 414 of file argument.hpp.

◆ implicit_values() [3/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::implicit_values ( std::initializer_list< value_type values)
inlinenoexcept

Add implicit values for the optional argument.

Parameters
valuesThe initializer list of implicit values to set.
Returns
Reference to the optional argument instance.
Note
The method is enabled only for optional arguments and if value_type is not none_type.

Definition at line 402 of file argument.hpp.

◆ is_greedy()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_greedy ( ) const
inlineoverridevirtualnoexcept
Returns
true if the argument is greedy, false otherwise.

Implements ap::detail::argument_base.

Definition at line 131 of file argument.hpp.

◆ is_hidden()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_hidden ( ) const
inlineoverridevirtualnoexcept
Returns
true if the argument is hidden, false otherwise

Implements ap::detail::argument_base.

Definition at line 111 of file argument.hpp.

◆ is_optional()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_optional ( ) const
inlineoverridevirtualnoexcept

Checks if the argument is optional.

Returns
true if the argument's type is argument_type::optional, false otherwise.

Implements ap::detail::argument_base.

Definition at line 96 of file argument.hpp.

◆ is_positional()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_positional ( ) const
inlineoverridevirtualnoexcept

Checks if the argument is positional.

Returns
true if the argument's type is argument_type::positional, false otherwise.

Implements ap::detail::argument_base.

Definition at line 90 of file argument.hpp.

◆ is_required()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_required ( ) const
inlineoverridevirtualnoexcept
Returns
true if the argument is required, false otherwise

Implements ap::detail::argument_base.

Definition at line 116 of file argument.hpp.

◆ is_used()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::is_used ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
true if the argument is used, false otherwise.

Implements ap::detail::argument_base.

Definition at line 505 of file argument.hpp.

◆ mark_used()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::mark_used ( )
inlineoverrideprivatevirtual

Mark the optional argument as used.

Returns
true if the argument accepts further values, false otherwise.

Implements ap::detail::argument_base.

Definition at line 494 of file argument.hpp.

◆ name()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const ap::detail::argument_name & ap::argument< ArgT, T >::name ( ) const
inlineoverridevirtualnoexcept
Returns
Reference the name of the positional argument.

Implements ap::detail::argument_base.

Definition at line 101 of file argument.hpp.

◆ nargs() [1/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::nargs ( const count_type  lower,
const count_type  upper 
)
inlinenoexcept

Set the nargs range for the optional argument.

Parameters
lowerThe lower bound for the nargs range attribute.
upperThe upper bound for the nargs range attribute.
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type.

Definition at line 250 of file argument.hpp.

◆ nargs() [2/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::nargs ( const count_type  n)
inlinenoexcept

Set the nargs range for the argument.

Parameters
nThe exact bound for the nargs range attribute.
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type.

Definition at line 237 of file argument.hpp.

◆ nargs() [3/3]

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::nargs ( const nargs::range range)
inlinenoexcept

Set the nargs range for the argument.

Parameters
rangeThe attribute value.
Returns
Reference to the argument instance.
Note
The method is enabled only if value_type is not none_type.

Definition at line 224 of file argument.hpp.

◆ nvalues_ordering()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
std::weak_ordering ap::argument< ArgT, T >::nvalues_ordering ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
The ordering relationship of the argument's values and its nargs range attribute.

Implements ap::detail::argument_base.

Definition at line 548 of file argument.hpp.

◆ required()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::required ( const bool  value = true)
inline

Set the required attribute of the argument.

Parameters
valueThe attribute value (default: true).
Returns
Reference to the argument instance.
Exceptions
ap::invalid_configurationif the argument is configured to suppress argument/group checks.

Definition at line 163 of file argument.hpp.

◆ set_value()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::set_value ( const std::string &  str_value)
inlineoverrideprivatevirtual

Set the value for the optional argument.

Parameters
str_valueThe string value to use.
Returns
true if the argument accepts further values, false otherwise.
Exceptions
ap::parsing_failure

Implements ap::detail::argument_base.

Definition at line 527 of file argument.hpp.

◆ suppress_arg_checks()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::suppress_arg_checks ( const bool  value = true)
inline

Enable/disable suppressing argument checks for other arguments.

Parameters
valueThe attribute value (default: true).
Returns
Reference to the argument instance.
Exceptions
ap::invalid_configurationif the argument is configured to be required.

Definition at line 179 of file argument.hpp.

◆ suppress_group_checks()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
argument & ap::argument< ArgT, T >::suppress_group_checks ( const bool  value = true)
inline

Enable/disable suppressing argument group checks.

Parameters
valueThe attribute value (default: true).
Returns
Reference to the argument instance.
Exceptions
ap::invalid_configurationif the argument is configured to be required.

Definition at line 195 of file argument.hpp.

◆ suppresses_arg_checks()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::suppresses_arg_checks ( ) const
inlineoverridevirtualnoexcept
Returns
true if argument checks suppressing is enabled for the argument, false otherwise.

Implements ap::detail::argument_base.

Definition at line 121 of file argument.hpp.

◆ suppresses_group_checks()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::suppresses_group_checks ( ) const
inlineoverridevirtualnoexcept
Returns
true if argument group checks suppressing is enabled for the argument, false otherwise.

Implements ap::detail::argument_base.

Definition at line 126 of file argument.hpp.

◆ value()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::any & ap::argument< ArgT, T >::value ( ) const
inlineoverrideprivatevirtual
Returns
Reference to the stored value of the argument.
Note
If multiple values are available, the first one is returned.
Exceptions
std::logic_errorif no values are available.

Implements ap::detail::argument_base.

Definition at line 560 of file argument.hpp.

◆ values()

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const std::vector< std::any > & ap::argument< ArgT, T >::values ( ) const
inlineoverrideprivatevirtual
Returns
Reference to the vector of parsed values for the argument.

Implements ap::detail::argument_base.

Definition at line 573 of file argument.hpp.

Member Data Documentation

◆ _choices

template<argument_type ArgT, util::c_argument_value_type T = std::string>
value_arg_specific_type<std::vector<value_type> > ap::argument< ArgT, T >::_choices
private

The argument's valid choices collection.

Definition at line 735 of file argument.hpp.

◆ _count

template<argument_type ArgT, util::c_argument_value_type T = std::string>
optional_specific_type<std::size_t> ap::argument< ArgT, T >::_count
private

The argument's value count.

Definition at line 751 of file argument.hpp.

◆ _default_nargs_range

template<argument_type ArgT, util::c_argument_value_type T = std::string>
constexpr nargs::range ap::argument< ArgT, T >::_default_nargs_range
staticconstexprprivate
Initial value:
=
(type == argument_type::positional) ? nargs::range(1ull) : nargs::any()
static constexpr argument_type type
The argument's type discriminator.
Definition argument.hpp:63
constexpr range any() noexcept
range class builder function. Creates a range [0, inf].
Definition range.hpp:163

Definition at line 756 of file argument.hpp.

◆ _default_nargs_range_actual

template<argument_type ArgT, util::c_argument_value_type T = std::string>
constexpr nargs::range ap::argument< ArgT, T >::_default_nargs_range_actual
staticconstexprprivate
Initial value:
=
static constexpr nargs::range _default_nargs_range
Definition argument.hpp:756
The concept is satisfied when T is ap::none_type.
Definition concepts.hpp:25

Definition at line 758 of file argument.hpp.

◆ _default_required

template<argument_type ArgT, util::c_argument_value_type T = std::string>
constexpr bool ap::argument< ArgT, T >::_default_required = (type == argument_type::positional)
staticconstexprprivate

Definition at line 755 of file argument.hpp.

◆ _default_values

template<argument_type ArgT, util::c_argument_value_type T = std::string>
value_arg_specific_type<std::vector<std::any> > ap::argument< ArgT, T >::_default_values
private

The argument's default value list.

Definition at line 731 of file argument.hpp.

◆ _flag_actions

template<argument_type ArgT, util::c_argument_value_type T = std::string>
optional_specific_type<std::vector<flag_action_type> > ap::argument< ArgT, T >::_flag_actions
private

The optional argument's flag actions collection.

Definition at line 737 of file argument.hpp.

◆ _greedy

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_greedy
private

The argument's greedy attribute value.

Definition at line 746 of file argument.hpp.

◆ _help_msg

template<argument_type ArgT, util::c_argument_value_type T = std::string>
std::optional<std::string> ap::argument< ArgT, T >::_help_msg
private

The argument's help message.

Definition at line 728 of file argument.hpp.

◆ _hidden

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_hidden
private

The argument's hidden attribute value.

Definition at line 747 of file argument.hpp.

◆ _implicit_values

template<argument_type ArgT, util::c_argument_value_type T = std::string>
value_arg_specific_type<optional_specific_type<std::vector<std::any> > > ap::argument< ArgT, T >::_implicit_values
private

The optional argument's implicit value list.

Definition at line 733 of file argument.hpp.

◆ _name

template<argument_type ArgT, util::c_argument_value_type T = std::string>
const ap::detail::argument_name ap::argument< ArgT, T >::_name
private

The argument's name.

Definition at line 727 of file argument.hpp.

◆ _nargs_range

template<argument_type ArgT, util::c_argument_value_type T = std::string>
nargs::range ap::argument< ArgT, T >::_nargs_range
private

The argument's nargs range attribute value.

Definition at line 729 of file argument.hpp.

◆ _required

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_required
private

The argument's required attribute value.

Definition at line 741 of file argument.hpp.

◆ _suppress_arg_checks

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_suppress_arg_checks
private

The argument's suppress_arg_checks attribute value.

Definition at line 742 of file argument.hpp.

◆ _suppress_group_checks

template<argument_type ArgT, util::c_argument_value_type T = std::string>
bool ap::argument< ArgT, T >::_suppress_group_checks
private

The argument's suppress_group_checks attribute value.

Definition at line 744 of file argument.hpp.

◆ _value_actions

template<argument_type ArgT, util::c_argument_value_type T = std::string>
value_arg_specific_type<std::vector<value_action_type> > ap::argument< ArgT, T >::_value_actions
private

The argument's value actions collection.

Definition at line 739 of file argument.hpp.

◆ _values

template<argument_type ArgT, util::c_argument_value_type T = std::string>
std::vector<std::any> ap::argument< ArgT, T >::_values
private

The argument's parsed values.

Definition at line 752 of file argument.hpp.

◆ type

template<argument_type ArgT, util::c_argument_value_type T = std::string>
constexpr argument_type ap::argument< ArgT, T >::type = ArgT
staticconstexpr

The argument's type discriminator.

Definition at line 63 of file argument.hpp.


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