Ookii.CommandLine for C++  2.0.0
Public Types | Public Member Functions | List of all members
ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc > Class Template Reference

Class that provides information about arguments that are not multi-value arguments. More...

#include <ookii/command_line_argument.h>

Inheritance diagram for ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >:
Inheritance graph
[legend]
Collaboration diagram for ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >:
Collaboration graph
[legend]

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 T::value_type
 The type of the argument's container's elements.
 
using parser_type = typename base_type::parser_type
 The concrete type of basic_command_line_parser used. 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< T, element_type, CharType, Traits >
 The concrete type of argument information storage used. For internal use. More...
 
using value_type = T
 The type of the argument's container, which equals T.
 
- Public Types inherited from ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >
using parser_type = basic_command_line_parser< CharType, std::char_traits< CharType >, std::allocator< CharType > >
 The concrete type of basic_command_line_parser used.
 
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 stream_type = std::basic_ostream< CharType, std::char_traits< CharType > >
 The concrete type of std::basic_ostream used.
 
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.
 

Public Member Functions

 multi_value_command_line_argument (const typename base_type::parser_type &parser, typename base_type::storage_type &&storage, typed_storage_type &&typed_storage)
 Initializes a new instance of the multi_value_command_line_argument class. More...
 
void apply_default_value () override
 Sets the variable holding the argument's value to the default value. More...
 
bool has_default_value () const noexcept override
 Gets a value that indicates whether this argument has a default value. More...
 
bool is_multi_value () const noexcept override
 Gets a value that indicates whether the argument can be provided more than once, collecting all the specified values. 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...
 
void reset () override
 Resets the argument to indicate it hasn't been set. More...
 
CharType separator () const noexcept
 Gets the character used to separate multiple values in a single argument value, or '\0' if no separator is used. More...
 
set_value_result set_switch_value ([[maybe_unused]] parser_type &parser) override
 Applies the implicit value for a switch argument. More...
 
set_value_result set_value (string_view_type value, parser_type &parser) override
 Used to indicate that the argument has a value. More...
 
base_type::stream_typewrite_default_value (typename base_type::stream_type &stream) const override
 Writes the default value to the specified stream. More...
 
- Public Member Functions inherited from ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >
 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_typedescription () const noexcept
 Gets the long description of the argument. More...
 
bool has_long_name () const noexcept
 Gets a value that indicates whether the argument has a long name. More...
 
bool has_short_name () const noexcept
 Gets a value that indicates whether the argument has a short name. 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...
 
bool is_required () const noexcept
 Gets a value that indicates whether the argument is required. More...
 
const string_typename () const noexcept
 Gets the name of the argument. More...
 
string_type name_with_prefix (const parser_type &parser) const
 Gets the argument name with the appropriate prefix. More...
 
command_line_argument_baseoperator= (const command_line_argument_base &)=delete
 
std::optional< size_t > position () const noexcept
 Gets the position of the argument. More...
 
virtual set_value_result set_switch_value (parser_type &parser)=0
 Applies the implicit value for a switch argument. More...
 
virtual set_value_result set_value (string_view_type value, parser_type &parser)=0
 Sets the argument to the specified value. More...
 
const std::vector< CharType > & short_aliases () const noexcept
 Gets a list of short aliases that can be used instead of the argument's name. More...
 
CharType short_name () const noexcept
 Gets the short name of the argument, or a NULL character if it doesn't have one. More...
 
string_view_type short_or_long_name () const
 Gets the short name if the argument has one, otherwise the long name. More...
 
const string_typevalue_description () const noexcept
 Gets the value description for the argument. More...
 
virtual stream_typewrite_default_value (stream_type &stream) const=0
 Writes the default value to the specified stream. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >
 command_line_argument_base (const parser_type &parser, storage_type &&storage)
 Constructs a command line argument base from a command_line_argument_storage. More...
 
const storage_typebase_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...
 

Detailed Description

template<typename T, typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
class ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >

Class that provides information about arguments that are not multi-value arguments.

Template Parameters
TThe type of the argument's container.
CharTypeThe character type used for arguments and other strings.
TraitsThe character traits to use for strings. Defaults to std::char_traits<CharType>.
AllocThe allocator to use for strings. Defaults to std::allocator<CharType>.

This provides information for all arguments created using basic_parser_builder::add_multi_value_argument().

For arguments that are not multi-value, see command_line_argument.

Member Typedef Documentation

◆ parser_type

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
using ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::parser_type = typename base_type::parser_type

The concrete type of basic_command_line_parser used.

◆ string_type

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
using ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::string_type = typename base_type::string_type

The concrete type of std::basic_string used.

◆ string_view_type

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
using ookii::multi_value_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.

◆ typed_storage_type

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
using ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::typed_storage_type = details::typed_argument_storage<T, element_type, CharType, Traits>

The concrete type of argument information storage used. For internal use.

Constructor & Destructor Documentation

◆ multi_value_command_line_argument()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::multi_value_command_line_argument ( const typename base_type::parser_type parser,
typename base_type::storage_type &&  storage,
typed_storage_type &&  typed_storage 
)
inline

Initializes a new instance of the multi_value_command_line_argument class.

Parameters
parserThe basic_command_line_parser this argument belongs to.
storageStorage containing the argument's information.
typed_storageStorage 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.

Member Function Documentation

◆ apply_default_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
void ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::apply_default_value ( )
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::typed_argument_builder::default_value().

Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.

◆ has_default_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
bool ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::has_default_value ( ) const
inlineoverridevirtualnoexcept

Gets a value that indicates whether this argument has a default value.

Returns
true if the argument has a default value; otherwise, false.

Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.

◆ is_multi_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
bool ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::is_multi_value ( ) const
inlineoverridevirtualnoexcept

Gets a value that indicates whether the argument can be provided more than once, collecting all the specified values.

An argument is multi-value if it was created using basic_parser_builder::add_multi_value_argument().

This method always returns true.

Reimplemented from ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.

◆ is_switch()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
bool ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::is_switch ( ) const
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>.

Implements ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.

◆ reset()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
void ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::reset ( )
inlineoverridevirtual

Resets the argument to indicate it hasn't been set.

The reset() method is called on all arguments before parsing. After the call, the has_value() method will return false. This method does not affect the value of the variable holding the argument's value, except for multi-value arguments, where the container holding the values is cleared before parsing.

Reimplemented from ookii::command_line_argument_base< CharType, std::char_traits< CharType >, std::allocator< CharType > >.

◆ separator()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
CharType ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::separator ( ) const
inlinenoexcept

Gets the character used to separate multiple values in a single argument value, or '\0' if no separator is used.

The separator can be specified using basic_parser_builder::multi_value_argument_builder::separator().

◆ set_switch_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
set_value_result ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::set_switch_value ( [[maybe_unused] ] parser_type parser)
inlineoverride

Applies the implicit value for a switch argument.

Parameters
parserThe parser that this argument belongs to.
Returns
One of the values of the set_value_result enumeration.

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 set_value_result::error is returned.

For a multi-value switch argument, this adds a value of true to the container.

◆ set_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
set_value_result ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::set_value ( string_view_type  value,
parser_type parser 
)
inlineoverride

Used to indicate that the argument has a value.

After calling this method, has_value() will return true.

◆ write_default_value()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
base_type::stream_type& ookii::multi_value_command_line_argument< T, CharType, Traits, Alloc >::write_default_value ( typename base_type::stream_type stream) const
inlineoverride

Writes the default value to the specified stream.

The default value for an argument can be specified using basic_parser_builder::typed_argument_builder::default_value().

Parameters
streamThe stream to write to.
Returns
The stream.

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