Lector v1.0.0
C++ library for parsing command line arguments.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lector::RepeatableArgument< LabelValue, Type > Class Template Referencefinal

A repeatable command line argument. More...

#include <arguments.hpp>

Public Types

using ValueType = Type
 

Public Member Functions

 RepeatableArgument () noexcept=default
 Default constructor. Initializes the repeatable command line argument with no keys, an empty description, required importance, and no default values.
 
 RepeatableArgument (const lector::RepeatableArgument< LabelValue, Type > &)=default
 Copy constructor. Constructs a repeatable command line argument by copying another one.
 
 RepeatableArgument (const std::string_view description)
 Constructor for a repeatable positional required command line argument. No default values are needed.
 
 RepeatableArgument (const std::string_view description, const std::vector< Type > &default_values)
 Constructor for a repeatable positional optional non-boolean command line argument.
 
 RepeatableArgument (const std::vector< std::string > &keys, const std::string_view description)
 Constructor for a repeatable named required command line argument or a repeatable named optional boolean command line argument. No default value is needed. Repeatable named boolean command line arguments are always optional and always default to false.
 
 RepeatableArgument (const std::vector< std::string > &keys, const std::string_view description, const std::vector< Type > &default_values)
 Constructor for a repeatable named optional non-boolean command line argument.
 
 RepeatableArgument (lector::RepeatableArgument< LabelValue, Type > &&) noexcept=default
 Move constructor. Constructs a repeatable command line argument by moving another one.
 
 ~RepeatableArgument () noexcept=default
 Destructor. Destroys this repeatable command line argument.
 
const std::vector< Type > & default_values () const noexcept
 Default values of this repeatable command line argument. Set at construction.
 
std::string_view description () const noexcept
 Description of this command line argument. Set at construction.
 
std::string execution () const
 Prints the execution of this command line argument as a string of text. The execution consists of this command line argument's longest key and parsed values, if any.
 
lector::Form form () const noexcept
 Form of this command line argument. A positional argument does not define any keys and must be specified in a specific order on the command line, whereas a named argument defines one or more keys and is specified on the command line by one of its keys. Named arguments can be specified in any order on the command line.
 
bool has_default () const noexcept
 Returns whether this repeatable command line argument has one or more default values.
 
bool has_parsed () const noexcept
 Returns whether this repeatable command line argument has one or more parsed values.
 
lector::Importance importance () const noexcept
 Importance of this command line argument. A required argument must be provided by the user on the command line, whereas an optional argument may or may not be provided by the user on the command line. Set at construction.
 
const std::vector< std::string > & keys () const noexcept
 Keys that can be used to specify this argument on the command line if it is a named argument, or an empty collection if this argument is a positional argument. Set at construction.
 
std::string keys_with_value_type () const
 Prints the keys and value type of this command line argument as a string of text.
 
std::string longest_key_with_value_type () const
 Prints the longest key of this command line argument with its associated value type as a string of text.
 
lector::RepeatableArgument< LabelValue, Type > & operator= (const lector::RepeatableArgument< LabelValue, Type > &)=default
 Copy assignment operator. Assigns this repeatable command line argument by copying another one.
 
lector::RepeatableArgument< LabelValue, Type > & operator= (lector::RepeatableArgument< LabelValue, Type > &&) noexcept=default
 Move assignment operator. Assigns this repeatable command line argument by moving another one.
 
std::string options () const
 Prints the options information of this command line argument as a string of text. The options information consists of this command line argument's keys, value type, and description.
 
const std::vector< Type > & parsed_or_default_values () const
 Values of this repeatable command line argument. Returns the parsed values if they exist; otherwise, returns the default values.
 
const std::vector< Type > & parsed_values () const noexcept
 Parsed values of this repeatable command line argument. Set when this argument is parsed from the command line.
 
void set_parsed_value (const Type &value)
 Inserts an additional parsed value into this repeatable command line argument.
 
std::string usage () const
 Prints the usage information of this command line argument as a string of text. The usage information consists of this command line argument's longest key and value type, enclosed in square braces if this command line argument is optional.
 

Static Public Member Functions

static lector::Arity arity () noexcept
 Arity of this command line argument. A repeatable argument can only appear once on the command line, whereas a repeatable argument can appear multiple times.
 
static constexpr auto label () noexcept
 Label of this command line argument. Used to uniquely identify this command line argument in a collection of command line arguments. Set at construction.
 

Detailed Description

template<auto LabelValue, typename Type>
class lector::RepeatableArgument< LabelValue, Type >

A repeatable command line argument.

Template Parameters
LabelValueValue of this command line argument's label. The label is used to uniquely identify this command line argument in a collection of command line arguments.
TypeThe type of the value stored in this command line argument.

Constructor & Destructor Documentation

◆ RepeatableArgument() [1/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( )
defaultnoexcept

Default constructor. Initializes the repeatable command line argument with no keys, an empty description, required importance, and no default values.

◆ RepeatableArgument() [2/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( const std::string_view  description)
explicit

Constructor for a repeatable positional required command line argument. No default values are needed.

Parameters
[in]descriptionThe description of the command line argument.
Exceptions
std::invalid_argumentif the type is boolean or if the description is empty.

◆ RepeatableArgument() [3/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( const std::vector< std::string > &  keys,
const std::string_view  description 
)

Constructor for a repeatable named required command line argument or a repeatable named optional boolean command line argument. No default value is needed. Repeatable named boolean command line arguments are always optional and always default to false.

Parameters
[in]keysThe keys used to specify the command line argument.
[in]descriptionThe description of the command line argument.
Exceptions
std::invalid_argumentif the keys are invalid or if the description is empty.

◆ RepeatableArgument() [4/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( const std::string_view  description,
const std::vector< Type > &  default_values 
)

Constructor for a repeatable positional optional non-boolean command line argument.

Parameters
[in]descriptionThe description of the command line argument.
[in]default_valuesThe default values of the command line argument, if any.
Exceptions
std::invalid_argumentif the type is boolean or if the description is empty.

◆ RepeatableArgument() [5/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( const std::vector< std::string > &  keys,
const std::string_view  description,
const std::vector< Type > &  default_values 
)

Constructor for a repeatable named optional non-boolean command line argument.

Parameters
[in]keysThe keys used to specify the command line argument.
[in]descriptionThe description of the command line argument.
[in]default_valuesThe default values of the command line argument, if any.
Exceptions
std::invalid_argumentif the type is boolean, if the keys are invalid, or if the description is empty.

◆ ~RepeatableArgument()

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::~RepeatableArgument ( )
defaultnoexcept

Destructor. Destroys this repeatable command line argument.

◆ RepeatableArgument() [6/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( const lector::RepeatableArgument< LabelValue, Type > &  )
default

Copy constructor. Constructs a repeatable command line argument by copying another one.

◆ RepeatableArgument() [7/7]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type >::RepeatableArgument ( lector::RepeatableArgument< LabelValue, Type > &&  )
defaultnoexcept

Move constructor. Constructs a repeatable command line argument by moving another one.

Member Function Documentation

◆ arity()

template<auto LabelValue, typename Type >
static lector::Arity lector::RepeatableArgument< LabelValue, Type >::arity ( )
staticnoexcept

Arity of this command line argument. A repeatable argument can only appear once on the command line, whereas a repeatable argument can appear multiple times.

Returns
The arity of this command line argument.

◆ default_values()

template<auto LabelValue, typename Type >
const std::vector< Type > & lector::RepeatableArgument< LabelValue, Type >::default_values ( ) const
noexcept

Default values of this repeatable command line argument. Set at construction.

Returns
The default values of this repeatable command line argument.

◆ description()

template<auto LabelValue, typename Type >
std::string_view lector::RepeatableArgument< LabelValue, Type >::description ( ) const
noexcept

Description of this command line argument. Set at construction.

Returns
The description of this command line argument.

◆ execution()

template<auto LabelValue, typename Type >
std::string lector::RepeatableArgument< LabelValue, Type >::execution ( ) const

Prints the execution of this command line argument as a string of text. The execution consists of this command line argument's longest key and parsed values, if any.

Returns
The string of text that contains the execution of this command line argument.

◆ form()

template<auto LabelValue, typename Type >
lector::Form lector::RepeatableArgument< LabelValue, Type >::form ( ) const
noexcept

Form of this command line argument. A positional argument does not define any keys and must be specified in a specific order on the command line, whereas a named argument defines one or more keys and is specified on the command line by one of its keys. Named arguments can be specified in any order on the command line.

Returns
The form of this command line argument.

◆ has_default()

template<auto LabelValue, typename Type >
bool lector::RepeatableArgument< LabelValue, Type >::has_default ( ) const
noexcept

Returns whether this repeatable command line argument has one or more default values.

Returns
True if this repeatable command line argument has one or more default values; false if it has none.

◆ has_parsed()

template<auto LabelValue, typename Type >
bool lector::RepeatableArgument< LabelValue, Type >::has_parsed ( ) const
noexcept

Returns whether this repeatable command line argument has one or more parsed values.

Returns
True if this repeatable command line argument has one or more parsed values; false if it has none.

◆ importance()

template<auto LabelValue, typename Type >
lector::Importance lector::RepeatableArgument< LabelValue, Type >::importance ( ) const
noexcept

Importance of this command line argument. A required argument must be provided by the user on the command line, whereas an optional argument may or may not be provided by the user on the command line. Set at construction.

Returns
The importance of this command line argument.

◆ keys()

template<auto LabelValue, typename Type >
const std::vector< std::string > & lector::RepeatableArgument< LabelValue, Type >::keys ( ) const
noexcept

Keys that can be used to specify this argument on the command line if it is a named argument, or an empty collection if this argument is a positional argument. Set at construction.

Returns
The keys that can be used to specify this command line argument.

◆ keys_with_value_type()

template<auto LabelValue, typename Type >
std::string lector::RepeatableArgument< LabelValue, Type >::keys_with_value_type ( ) const

Prints the keys and value type of this command line argument as a string of text.

Returns
The string of text that contains the keys and value type of this command line argument.

◆ label()

template<auto LabelValue, typename Type >
static constexpr auto lector::RepeatableArgument< LabelValue, Type >::label ( )
staticconstexprnoexcept

Label of this command line argument. Used to uniquely identify this command line argument in a collection of command line arguments. Set at construction.

Returns
The label of this command line argument.

◆ longest_key_with_value_type()

template<auto LabelValue, typename Type >
std::string lector::RepeatableArgument< LabelValue, Type >::longest_key_with_value_type ( ) const

Prints the longest key of this command line argument with its associated value type as a string of text.

Returns
The string of text that contains the longest key of this command line argument with its associated value type.

◆ operator=() [1/2]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type > & lector::RepeatableArgument< LabelValue, Type >::operator= ( const lector::RepeatableArgument< LabelValue, Type > &  )
default

Copy assignment operator. Assigns this repeatable command line argument by copying another one.

Returns
This repeatable command line argument after the assignment.

◆ operator=() [2/2]

template<auto LabelValue, typename Type >
lector::RepeatableArgument< LabelValue, Type > & lector::RepeatableArgument< LabelValue, Type >::operator= ( lector::RepeatableArgument< LabelValue, Type > &&  )
defaultnoexcept

Move assignment operator. Assigns this repeatable command line argument by moving another one.

Returns
This repeatable command line argument after the assignment.

◆ options()

template<auto LabelValue, typename Type >
std::string lector::RepeatableArgument< LabelValue, Type >::options ( ) const

Prints the options information of this command line argument as a string of text. The options information consists of this command line argument's keys, value type, and description.

Returns
The string of text that contains the options information of this command line argument.

◆ parsed_or_default_values()

template<auto LabelValue, typename Type >
const std::vector< Type > & lector::RepeatableArgument< LabelValue, Type >::parsed_or_default_values ( ) const

Values of this repeatable command line argument. Returns the parsed values if they exist; otherwise, returns the default values.

Returns
The values of this repeatable command line argument.

◆ parsed_values()

template<auto LabelValue, typename Type >
const std::vector< Type > & lector::RepeatableArgument< LabelValue, Type >::parsed_values ( ) const
noexcept

Parsed values of this repeatable command line argument. Set when this argument is parsed from the command line.

Returns
The parsed values of this repeatable command line argument.

◆ set_parsed_value()

template<auto LabelValue, typename Type >
void lector::RepeatableArgument< LabelValue, Type >::set_parsed_value ( const Type &  value)

Inserts an additional parsed value into this repeatable command line argument.

Parameters
[in]valueThe parsed value to insert.
Exceptions
std::logic_errorif this repeatable command line argument is default-constructed.
std::invalid_argumentif this repeatable command line argument is boolean and the parsed value is false.

◆ usage()

template<auto LabelValue, typename Type >
std::string lector::RepeatableArgument< LabelValue, Type >::usage ( ) const

Prints the usage information of this command line argument as a string of text. The usage information consists of this command line argument's longest key and value type, enclosed in square braces if this command line argument is optional.

Returns
The string of text that contains the usage information of this command line argument.

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