CPP-AP 2.2.6
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 (const detail::argument_name &name)
 Constructor for optional argument with the name identifier.
 
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.
 
optionalrequired () noexcept
 Mark the optional argument as required.
 
optionalbypass_required () noexcept
 Enable bypassing the required status 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 value_type &default_value) noexcept
 Set the default value for the optional argument.
 
optionalimplicit_value (const value_type &implicit_value) noexcept
 Set the implicit value for the optional argument.
 

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 ap::detail::argument_namename () const noexcept
 
const std::optional< std::string > & help () const noexcept
 
- Protected Attributes inherited from ap::detail::argument_base
const ap::detail::argument_name _name
 
std::optional< std::string > _help_msg
 

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.

◆ 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()

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.

Member Function Documentation

◆ 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 124 of file optional.hpp.

◆ bypass_required()

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

Enable bypassing the required status for the optional argument.

Returns
Reference to the optional argument.

Definition at line 80 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 145 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 159 of file optional.hpp.

◆ default_value()

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

Set the default value for the optional argument.

Parameters
default_valueThe default value to set.
Returns
Reference to the optional argument.

Definition at line 170 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.

◆ implicit_value()

template<detail::c_argument_value_type T = std::string>
optional & ap::argument::optional< T >::implicit_value ( const value_type 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 180 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 111 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 100 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 90 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 ( )
inlinenoexcept

Mark the optional argument as required.

Returns
Reference to the optional argument.
Todo:
Add a const bool parameter to enable explicit enabling/disabling of this option.

Definition at line 71 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 186 of file optional.hpp.


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