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

The positional argument class. More...

#include <positional.hpp>

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

Public Types

using value_type = T
 The argument's value type.
 

Public Member Functions

 positional ()=delete
 
 positional (const detail::argument_name &name)
 Constructor for positional argument with the name identifier.
 
 ~positional ()=default
 
bool operator== (const positional &other) const noexcept
 Equality operator for positional argument.
 
positionalhelp (std::string_view help_msg) noexcept
 Set the help message for the positional argument.
 
positionalhidden (const bool h=true) noexcept
 Set the hidden attribute for the positional argument.
 
positionalrequired (const bool r=true) noexcept
 Set the required attribute of the positional argument.
 
positionalbypass_required (const bool br=true) noexcept
 Enable/disable bypassing the required attributeattribute for the positional argument.
 
template<detail::c_range_of< value_type, detail::type_validator::convertible > CR>
requires (std::equality_comparable<value_type>)
positionalchoices (const CR &choices) noexcept
 Set the choices for the positional argument.
 
positionalchoices (std::initializer_list< value_type > choices) noexcept
 Set the choices for the positional argument.
 
positionaldefault_value (const std::convertible_to< value_type > auto &default_value) noexcept
 Set the default value for the positional argument.
 
template<action::detail::c_value_action_specifier AS, std::invocable< value_type & > F>
positionalaction (F &&action) noexcept
 Set the action for the positional 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.
 

Private Member Functions

detail::argument_descriptor desc (const bool verbose) const noexcept override
 
bool mark_used () override
 Mark the positional 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 positional 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
 Get the stored value of the positional argument.
 
const std::vector< std::any > & values () const override
 

Private Attributes

std::any _default_value
 
std::vector< value_type_choices
 
std::vector< value_action_type_value_actions
 
std::any _value
 Stored value of the positional 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 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::positional< T >

The positional argument class.

Template Parameters
TThe argument's value type.

Definition at line 29 of file positional.hpp.

Member Typedef Documentation

◆ value_action_type

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

The argument's value action type.

Definition at line 164 of file positional.hpp.

◆ value_type

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

The argument's value type.

Definition at line 31 of file positional.hpp.

Constructor & Destructor Documentation

◆ positional() [1/2]

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

◆ positional() [2/2]

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

Constructor for positional argument with the name identifier.

Parameters
nameThe name identifier of the positional argument.

Definition at line 39 of file positional.hpp.

◆ ~positional()

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

Member Function Documentation

◆ action()

template<detail::c_argument_value_type T = std::string>
template<action::detail::c_value_action_specifier AS, std::invocable< value_type & > F>
positional & ap::argument::positional< T >::action ( F &&  action)
inlinenoexcept

Set the action for the positional argument.

Template Parameters
ASThe value action specifier type (valued_action or void_action).
FThe type of the action function.
Parameters
actionThe action function to set.
Returns
Reference to the positional argument.

Definition at line 147 of file positional.hpp.

◆ bypass_required()

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

Enable/disable bypassing the required attributeattribute for the positional argument.

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

Definition at line 91 of file positional.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>)
positional & ap::argument::positional< T >::choices ( const CR &  choices)
inlinenoexcept

Set the choices for the positional argument.

Template Parameters
CRThe choices range type.
Parameters
choicesThe range of valid choices for the argument.
Returns
Reference to the positional 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 107 of file positional.hpp.

◆ choices() [2/2]

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

Set the choices for the positional argument.

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

Definition at line 121 of file positional.hpp.

◆ count()

template<detail::c_argument_value_type T = std::string>
std::size_t ap::argument::positional< T >::count ( ) const
inlineoverrideprivatevirtualnoexcept
Returns
1 if a value has been parsed for the positional argument, 0 otherwise.

Implements ap::detail::argument_base.

Definition at line 205 of file positional.hpp.

◆ default_value()

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

Set the default value for the positional argument.

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

Definition at line 133 of file positional.hpp.

◆ desc()

template<detail::c_argument_value_type T = std::string>
detail::argument_descriptor ap::argument::positional< 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 171 of file positional.hpp.

◆ has_parsed_values()

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

Implements ap::detail::argument_base.

Definition at line 245 of file positional.hpp.

◆ has_value()

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

Implements ap::detail::argument_base.

Definition at line 240 of file positional.hpp.

◆ help()

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

Set the help message for the positional argument.

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

Definition at line 57 of file positional.hpp.

◆ hidden()

template<detail::c_argument_value_type T = std::string>
positional & ap::argument::positional< 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 67 of file positional.hpp.

◆ is_used()

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

Implements ap::detail::argument_base.

Definition at line 200 of file positional.hpp.

◆ mark_used()

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

Mark the positional argument as used.

Remarks
No logic is performed for positional arguments

Implements ap::detail::argument_base.

Definition at line 195 of file positional.hpp.

◆ nvalues_ordering()

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

Implements ap::detail::argument_base.

Definition at line 250 of file positional.hpp.

◆ operator==()

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

Equality operator for positional argument.

Parameters
otherAnother positional argument for comparison.
Returns
Result of equality

Definition at line 48 of file positional.hpp.

◆ required()

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

Set the required attribute of the positional argument.

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

Definition at line 78 of file positional.hpp.

◆ set_value()

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

Set the value for the positional argument.

Parameters
str_valueThe string representation of the value.
Returns
Reference to the positional argument.
Exceptions
ap::parsing_failure

Implements ap::detail::argument_base.

Definition at line 215 of file positional.hpp.

◆ value()

template<detail::c_argument_value_type T = std::string>
const std::any & ap::argument::positional< T >::value ( ) const
inlineoverrideprivatevirtual

Get the stored value of the positional argument.

Exceptions
std::logic_error

Implements ap::detail::argument_base.

Definition at line 261 of file positional.hpp.

◆ values()

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

Implements ap::detail::argument_base.

Definition at line 277 of file positional.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 154 of file positional.hpp.

Member Data Documentation

◆ _choices

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

Definition at line 284 of file positional.hpp.

◆ _default_value

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

Definition at line 283 of file positional.hpp.

◆ _value

template<detail::c_argument_value_type T = std::string>
std::any ap::argument::positional< T >::_value
private

Stored value of the positional argument.

Definition at line 287 of file positional.hpp.

◆ _value_actions

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

Definition at line 285 of file positional.hpp.


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