Ookii.CommandLine for C++
1.0.0
|
Class that provides information about arguments that are not multi-value arguments. More...
#include <ookii/command_line_argument.h>
Public Types | |
using | base_type = command_line_argument_base< CharType, Traits, Alloc > |
The type of the base class of this class. | |
using | element_type = typename details::element_type< T >::type |
The type of the argument's elements, which equals T . More... | |
using | string_type = typename base_type::string_type |
The concrete type of std::basic_string used. More... | |
using | string_view_type = typename base_type::string_view_type |
The concrete type of std::basic_string_view used. More... | |
using | typed_storage_type = details::typed_argument_storage< value_type, element_type, CharType, Traits > |
The concrete type of argument information storage used. For internal use. More... | |
using | usage_options_type = typename base_type::usage_options_type |
The concrete type of std::basic_usage_options used. | |
using | value_type = T |
The type of the argument's value, which equals T . | |
![]() | |
using | storage_type = details::argument_storage< CharType, std::char_traits< CharType >, std::allocator< CharType > > |
The concrete type of argument information storage used. For internal use. | |
using | string_type = typename storage_type::string_type |
The concrete type of std::basic_string used. | |
using | string_view_type = std::basic_string_view< CharType, std::char_traits< CharType > > |
The concrete type of std::basic_string_view used. | |
using | usage_options_type = basic_usage_options< CharType, std::char_traits< CharType >, std::allocator< CharType > > |
The concrete type of std::basic_usage_options used. | |
Public Member Functions | |
command_line_argument (typename base_type::storage_type &&storage, typed_storage_type &&typed_storage) | |
Initializes a new instance of the command_line_argument class. More... | |
void | apply_default_value () override |
Sets the variable holding the argument's value to the default value. More... | |
string_type | format_default_value (const usage_options_type &options, const std::locale &loc={}) const override |
Convert the default value of the argument to a string using the specified usage options. More... | |
bool | is_switch () const noexcept override |
Gets a value that indicates whether the argument is a switch, which means it can be supplied without a value. More... | |
bool | set_switch_value () override |
Applies the implicit value for a switch argument. More... | |
bool | set_value (string_view_type value, std::locale loc={}) override |
Used to indicate that the argument has a value. More... | |
![]() | |
command_line_argument_base (const command_line_argument_base &)=delete | |
const std::vector< string_type > & | aliases () const noexcept |
Gets a list of aliases that can be used instead of the argument's name. More... | |
bool | cancel_parsing () const noexcept |
Gets a value that indicates whether supplying this argument will cancel parsing. More... | |
const string_type & | description () const noexcept |
Gets the long description of the argument. More... | |
virtual string_type | format_default_value (const usage_options_type &options, const std::locale &loc={}) const=0 |
Convert the default value of the argument to a string using the specified usage options. More... | |
bool | has_value () const noexcept |
Gets a value that indicates whether the argument was specified on the last invocation of basic_command_line_parser::parse(). More... | |
virtual bool | is_multi_value () const noexcept |
Gets a value that indicates whether the argument can be provided more than once, collecting all the specified values. More... | |
bool | is_required () const noexcept |
Gets a value that indicates whether the argument is required. More... | |
const string_type & | name () const noexcept |
Gets the name of the argument. More... | |
command_line_argument_base & | operator= (const command_line_argument_base &)=delete |
std::optional< size_t > | position () const noexcept |
Gets the position of the argument. More... | |
virtual void | reset () |
Resets the argument to indicate it hasn't been set. More... | |
virtual bool | set_value (string_view_type value, std::locale loc={})=0 |
Sets the argument to the specified value. More... | |
const string_type & | value_description () const noexcept |
Gets the value description for the argument. More... | |
Additional Inherited Members | |
![]() | |
command_line_argument_base (storage_type &&storage) | |
Move constructor for command_line_argument_base. | |
const storage_type & | base_storage () const |
Provides access to the storage fields to derived classes. | |
void | set_value () noexcept |
Used to indicate that the argument has a value. More... | |
![]() | |
static string_type | format_default_value_helper (const std::optional< T > &value, const usage_options_type &options, const std::locale &loc={}) |
Helper function for derived classes to implement format_default_value(). More... | |
Class that provides information about arguments that are not multi-value arguments.
T | The type of the argument. |
Element | The element type of the argument. |
CharType | The character type used for arguments and other strings. |
Traits | The character traits to use for strings. Defaults to std::char_traits<CharType> . |
Alloc | The allocator to use for strings. Defaults to std::allocator<CharType> . |
This provides information for all arguments created using basic_parser_builder::add_argument().
For multi-value arguments, see multi_value_command_line_argument.
using ookii::command_line_argument< T, CharType, Traits, Alloc >::element_type = typename details::element_type<T>::type |
The type of the argument's elements, which equals T
.
The element type will be differnt from value_type only for multi-value arguments and arguments that use std::optional<T>
.
using ookii::command_line_argument< T, CharType, Traits, Alloc >::string_type = typename base_type::string_type |
The concrete type of std::basic_string
used.
using ookii::command_line_argument< T, CharType, Traits, Alloc >::string_view_type = typename base_type::string_view_type |
The concrete type of std::basic_string_view
used.
using ookii::command_line_argument< T, CharType, Traits, Alloc >::typed_storage_type = details::typed_argument_storage<value_type, element_type, CharType, Traits> |
The concrete type of argument information storage used. For internal use.
|
inline |
Initializes a new instance of the command_line_argument class.
storage | Storage containing the argument's information. |
typed_storage | Storage containing information that depends on the argument's type. |
You do not normally construct instances of this class manually. Instead, use the basic_parser_builder.
|
inlineoverridevirtual |
Sets the variable holding the argument's value to the default value.
This method has no effect if the argument was supplied on the command line (has_value() returns true
) or no default value was specified.
For a multi-value argument, the default value will be added as the only value in the container if no values were supplied on the command line.
The default value for an argument can be specified using basic_parser_builder::argument_builder::default_value().
Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.
|
inlineoverride |
Convert the default value of the argument to a string using the specified usage options.
options | The usage options specifying the default value format string. |
loc | The locale used to format the value. |
With the default options, this will return a string like "Default value: value".
The default value for an argument can be specified using basic_parser_builder::argument_builder::default_value().
|
inlineoverridevirtualnoexcept |
Gets a value that indicates whether the argument is a switch, which means it can be supplied without a value.
An argument is a switch if its type is bool
or std::optional<bool>
.
For a multi-value argument, the element_type must be bool
or std::optional<bool>
. For example, an argument with the container type std::vector<bool>
would be a multi-value switch argument.
Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.
|
inlineoverridevirtual |
Applies the implicit value for a switch argument.
true
if the argument was a switch argument; otherwise, false
.If the argument is a switch argument (is_switch() returns true
), the variable holding its variable will be set to true
. Otherwise, the value is not changed and false
is returned.
For a multi-value argument, this adds a value of true
to the container.
Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.
|
inlineoverride |
Used to indicate that the argument has a value.
After calling this method, has_value()
will return true
.