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

The optioanl argument class. More...

#include <optional.hpp>

Inheritance diagram for ap::argument::optional< T >:
ap::detail::argument_base

Public Types

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

Public Member Functions

 optional ()=delete
 
 optional (const detail::argument_name &name)
 Constructor for optional argument with the name identifier.
 
 ~optional ()=default
 
bool operator== (const optional &other) const noexcept
 Equality comparison operator for optional argument.
 
optionalhelp (std::string_view help_msg) noexcept
 Set the help message for the optional argument.
 
optionalhidden (const bool h=true) noexcept
 Set the hidden attribute for the positional argument.
 
optionalrequired (const bool r=true) noexcept
 Set the required attribute of the optional argument.
 
optionalbypass_required (const bool br=true) noexcept
 Enable/disable bypassing the required attribute for the optional argument.
 
optionalnargs (const nargs::range &range) noexcept
 Set the nargs range for the optional argument.
 
optionalnargs (const count_type n) noexcept
 Set the nargs range for the optional argument.
 
optionalnargs (const count_type lower_bound, const count_type upper_bound) noexcept
 Set the nargs range for the optional argument.
 
template<action::detail::c_action_specifier AS, typename F >
optionalaction (F &&action) noexcept
 Set the action for the optional argument.
 
template<detail::c_range_of< value_type, detail::type_validator::convertible > CR>
requires (std::equality_comparable<value_type>)
optionalchoices (const CR &choices) noexcept
 Set the choices for the optional argument.
 
optionalchoices (std::initializer_list< value_type > choices) noexcept
 Set the choices for the optional argument.
 
optionaldefault_value (const std::convertible_to< value_type > auto &default_value) noexcept
 Set the default value for the optional argument.
 
optionalimplicit_value (const std::convertible_to< value_type > auto &implicit_value) noexcept
 Set the implicit value for the optional argument.
 
- Public Member Functions inherited from ap::detail::argument_base
virtual ~argument_base ()=default
 

Private Types

using value_action_type = action::detail::value_action_variant_type< T >
 The argument's value action type.
 
using flag_action_type = typename action_type::on_flag::type
 

Private Member Functions

detail::argument_descriptor desc (const bool verbose) const noexcept override
 
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
 
std::weak_ordering nvalues_ordering () const noexcept override
 
const std::any & value () const override
 
const std::vector< std::any > & values () const override
 
bool _has_predefined_value () const noexcept
 
const std::any & _predefined_value () const
 
bool _accepts_further_values () const noexcept
 

Private Attributes

nargs::range _nargs_range = nargs::any()
 
std::any _default_value
 
std::any _implicit_value
 
std::vector< value_type_choices
 
std::vector< flag_action_type_flag_actions
 
std::vector< value_action_type_value_actions
 
std::size_t _count = 0ull
 
std::vector< std::any > _values
 

Friends

class ::ap::argument_parser
 Friend class declaration for access by argument_parser.
 

Additional Inherited Members

- Protected Member Functions inherited from ap::detail::argument_base
 argument_base (const argument_name &name, const bool required=false)
 
const ap::detail::argument_namename () const noexcept
 
const std::optional< std::string > & help () const noexcept
 
bool is_hidden () const noexcept
 
bool is_required () const noexcept
 
bool bypass_required_enabled () const noexcept
 
- Protected Attributes inherited from ap::detail::argument_base
const ap::detail::argument_name _name
 
std::optional< std::string > _help_msg
 
bool _required: 1
 
bool _bypass_required: 1 = false
 
bool _hidden: 1 = false
 

Detailed Description

template<detail::c_argument_value_type T = std::string>
class ap::argument::optional< T >

The optioanl argument class.

Template Parameters
TThe argument's value type.

Definition at line 31 of file optional.hpp.

Member Typedef Documentation

◆ count_type

template<detail::c_argument_value_type T = std::string>
using ap::argument::optional< T >::count_type = nargs::range::count_type

The argument's value count type.

Definition at line 34 of file optional.hpp.

◆ flag_action_type

template<detail::c_argument_value_type T = std::string>
using ap::argument::optional< T >::flag_action_type = typename action_type::on_flag::type
private

Definition at line 216 of file optional.hpp.

◆ value_action_type

template<detail::c_argument_value_type T = std::string>
using ap::argument::optional< T >::value_action_type = action::detail::value_action_variant_type<T>
private

The argument's value action type.

Definition at line 214 of file optional.hpp.

◆ value_type

template<detail::c_argument_value_type T = std::string>
using ap::argument::optional< T >::value_type = T

The argument's value type.

Definition at line 33 of file optional.hpp.

Constructor & Destructor Documentation

◆ optional() [1/2]

template<detail::c_argument_value_type T = std::string>
ap::argument::optional< T >::optional ( )
delete

◆ optional() [2/2]

template<detail::c_argument_value_type T = std::string>
ap::argument::optional< T >::optional ( const detail::argument_name name)
inline

Constructor for optional argument with the name identifier.

Parameters
nameThe name identifier of the optional argument.

Definition at line 42 of file optional.hpp.

◆ ~optional()

template<detail::c_argument_value_type T = std::string>
ap::argument::optional< T >::~optional ( )
default

Member Function Documentation

◆ _accepts_further_values()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::_accepts_further_values ( ) const
inlineprivatenoexcept

Definition at line 351 of file optional.hpp.

◆ _has_predefined_value()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::_has_predefined_value ( ) const
inlineprivatenoexcept
Returns
True if the optional argument has a predefined value, false otherwise.

Definition at line 324 of file optional.hpp.

◆ _predefined_value()

template<detail::c_argument_value_type T = std::string>
const std::any & ap::argument::optional< T >::_predefined_value ( ) const
inlineprivate
Returns
Reference to the predefined value of the optional argument.
Exceptions
std::logic_error

Definition at line 333 of file optional.hpp.

◆ action()

template<detail::c_argument_value_type T = std::string>
template<action::detail::c_action_specifier AS, typename F >
optional & ap::argument::optional< T >::action ( F &&  action)
inlinenoexcept

Set the action for the optional argument.

Template Parameters
ASThe action specifier type (see ap/action/specifiers.hpp).
FThe type of the action function.
Parameters
actionThe action function to set.
Returns
Reference to the optional argument.

Definition at line 140 of file optional.hpp.

◆ bypass_required()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::bypass_required ( const bool  br = true)
inlinenoexcept

Enable/disable bypassing the required attribute for the optional argument.

Parameters
brThe attribute value.
Returns
Reference to the optional argument.
Attention
Setting the bypass_required option to true disables the required attribute.

Definition at line 94 of file optional.hpp.

◆ choices() [1/2]

template<detail::c_argument_value_type T = std::string>
template<detail::c_range_of< value_type, detail::type_validator::convertible > CR>
requires (std::equality_comparable<value_type>)
optional & ap::argument::optional< T >::choices ( const CR &  choices)
inlinenoexcept

Set the choices for the optional argument.

Template Parameters
CRThe choices range type.
Parameters
choicesThe range of valid choices for the argument.
Returns
Reference to the optional argument.
Note
value_type must be equality comparable.
CR must be a range such that its value type is convertible to value_type.

Definition at line 161 of file optional.hpp.

◆ choices() [2/2]

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::choices ( std::initializer_list< value_type choices)
inlinenoexcept

Set the choices for the optional argument.

Parameters
choicesThe list of valid choices for the argument.
Returns
Reference to the optional argument.
Note
value_type must be equality comparable.

Definition at line 175 of file optional.hpp.

◆ count()

template<detail::c_argument_value_type T = std::string>
std::size_t ap::argument::optional< T >::count ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
The number of times the optional argument attribute has been used.

Implements ap::detail::argument_base.

Definition at line 261 of file optional.hpp.

◆ default_value()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::default_value ( const std::convertible_to< value_type > auto &  default_value)
inlinenoexcept

Set the default value for the optional argument.

Parameters
default_valueThe default value to set.
Returns
Reference to the optional argument.
Attention
Setting the default value disables the required attribute.

Definition at line 187 of file optional.hpp.

◆ desc()

template<detail::c_argument_value_type T = std::string>
detail::argument_descriptor ap::argument::optional< T >::desc ( const bool  verbose) const
inlineoverrideprivatevirtualnoexcept
Parameters
verboseThe verbosity mode value.
Returns
An argument descriptor object for the argument.

Implements ap::detail::argument_base.

Definition at line 222 of file optional.hpp.

◆ has_parsed_values()

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

Implements ap::detail::argument_base.

Definition at line 301 of file optional.hpp.

◆ has_value()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::has_value ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
True if the optional argument has a value, false otherwise.

Implements ap::detail::argument_base.

Definition at line 296 of file optional.hpp.

◆ help()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::help ( std::string_view  help_msg)
inlinenoexcept

Set the help message for the optional argument.

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

Definition at line 60 of file optional.hpp.

◆ hidden()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::hidden ( const bool  h = true)
inlinenoexcept

Set the hidden attribute for the positional argument.

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

Definition at line 70 of file optional.hpp.

◆ implicit_value()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::implicit_value ( const std::convertible_to< value_type > auto &  implicit_value)
inlinenoexcept

Set the implicit value for the optional argument.

Parameters
implicit_valueThe implicit value to set.
Returns
Reference to the optional argument.

Definition at line 198 of file optional.hpp.

◆ is_used()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::is_used ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
True if the optional argument is used, false otherwise.

Implements ap::detail::argument_base.

Definition at line 256 of file optional.hpp.

◆ mark_used()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::mark_used ( )
inlineoverrideprivatevirtual

Mark the optional argument as used.

Implements ap::detail::argument_base.

Definition at line 248 of file optional.hpp.

◆ nargs() [1/3]

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::nargs ( const count_type  lower_bound,
const count_type  upper_bound 
)
inlinenoexcept

Set the nargs range for the optional argument.

Parameters
lower_boundThe lower bound for nargs range.
upper_boundThe upper bound for nargs range.
Returns
Reference to the optional argument.

Definition at line 127 of file optional.hpp.

◆ nargs() [2/3]

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::nargs ( const count_type  n)
inlinenoexcept

Set the nargs range for the optional argument.

Parameters
nThe exact bound for nargs range.
Returns
Reference to the optional argument.

Definition at line 116 of file optional.hpp.

◆ nargs() [3/3]

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::nargs ( const nargs::range range)
inlinenoexcept

Set the nargs range for the optional argument.

Parameters
rangeThe nargs range to set.
Returns
Reference to the optional argument.

Definition at line 106 of file optional.hpp.

◆ nvalues_ordering()

template<detail::c_argument_value_type T = std::string>
std::weak_ordering ap::argument::optional< T >::nvalues_ordering ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
ordering relationship of optional argument range.

Implements ap::detail::argument_base.

Definition at line 306 of file optional.hpp.

◆ operator==()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::operator== ( const optional< T > &  other) const
inlinenoexcept

Equality comparison operator for optional argument.

Parameters
otherThe optional argument to compare with.
Returns
Equality of comparison.

Definition at line 51 of file optional.hpp.

◆ required()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::required ( const bool  r = true)
inlinenoexcept

Set the required attribute of the optional argument.

Parameters
rThe attribute value.
Returns
Reference to the optional argument.
Attention
Setting the required attribute to true disables the bypass_required attribute.

Definition at line 81 of file optional.hpp.

◆ set_value()

template<detail::c_argument_value_type T = std::string>
bool ap::argument::optional< T >::set_value ( const std::string &  str_value)
inlineoverrideprivatevirtual

Set the value for the optional argument.

Parameters
str_valueThe string value to set.
Returns
Reference to the optional argument.
Exceptions
ap::parsing_failure

Implements ap::detail::argument_base.

Definition at line 271 of file optional.hpp.

◆ value()

template<detail::c_argument_value_type T = std::string>
const std::any & ap::argument::optional< T >::value ( ) const
inlineoverrideprivatevirtual
Returns
Reference to the stored value of the optional argument.

Implements ap::detail::argument_base.

Definition at line 314 of file optional.hpp.

◆ values()

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

Implements ap::detail::argument_base.

Definition at line 319 of file optional.hpp.

Friends And Related Symbol Documentation

◆ ::ap::argument_parser

template<detail::c_argument_value_type T = std::string>
friend class ::ap::argument_parser
friend

Friend class declaration for access by argument_parser.

Definition at line 204 of file optional.hpp.

Member Data Documentation

◆ _choices

template<detail::c_argument_value_type T = std::string>
std::vector<value_type> ap::argument::optional< T >::_choices
private

Definition at line 358 of file optional.hpp.

◆ _count

template<detail::c_argument_value_type T = std::string>
std::size_t ap::argument::optional< T >::_count = 0ull
private

Definition at line 362 of file optional.hpp.

◆ _default_value

template<detail::c_argument_value_type T = std::string>
std::any ap::argument::optional< T >::_default_value
private

Definition at line 356 of file optional.hpp.

◆ _flag_actions

template<detail::c_argument_value_type T = std::string>
std::vector<flag_action_type> ap::argument::optional< T >::_flag_actions
private

Definition at line 359 of file optional.hpp.

◆ _implicit_value

template<detail::c_argument_value_type T = std::string>
std::any ap::argument::optional< T >::_implicit_value
private

Definition at line 357 of file optional.hpp.

◆ _nargs_range

template<detail::c_argument_value_type T = std::string>
nargs::range ap::argument::optional< T >::_nargs_range = nargs::any()
private

Definition at line 355 of file optional.hpp.

◆ _value_actions

template<detail::c_argument_value_type T = std::string>
std::vector<value_action_type> ap::argument::optional< T >::_value_actions
private

Definition at line 360 of file optional.hpp.

◆ _values

template<detail::c_argument_value_type T = std::string>
std::vector<std::any> ap::argument::optional< T >::_values
private

Definition at line 363 of file optional.hpp.


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