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::SingularArgument< LabelValue, Type > Class Template Referencefinal

A singular command line argument. More...

#include <arguments.hpp>

Public Types

using ValueType = Type
 

Public Member Functions

 SingularArgument () noexcept=default
 Default constructor. Initializes the singular command line argument with no keys, an empty description, required importance, and no default value.
 
 SingularArgument (const lector::SingularArgument< LabelValue, Type > &)=default
 Copy constructor. Constructs a singular command line argument by copying another one.
 
 SingularArgument (const std::string_view description)
 Constructor for a singular positional required command line argument. No default value is needed.
 
 SingularArgument (const std::string_view description, const Type &default_value)
 Constructor for a singular positional optional non-boolean command line argument. A default value must be provided.
 
 SingularArgument (const std::vector< std::string > &keys, const std::string_view description)
 Constructor for a singular named required command line argument or a singular named boolean command line argument. No default value is needed. Singular named boolean command line arguments are always optional and always default to false.
 
 SingularArgument (const std::vector< std::string > &keys, const std::string_view description, const Type &default_value)
 Constructor for a singular named optional non-boolean command line argument. A default value must be provided.
 
 SingularArgument (lector::SingularArgument< LabelValue, Type > &&) noexcept=default
 Move constructor. Constructs a singular command line argument by moving another one.
 
 ~SingularArgument () noexcept=default
 Destructor. Destroys this singular command line argument.
 
const std::optional< Type > & default_value () const noexcept
 Default value of this singular command line argument if it is optional and non-boolean, or std::nullopt otherwise. 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 value, 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 singular command line argument has a default value.
 
bool has_parsed () const noexcept
 Returns whether this singular command line argument has a parsed value.
 
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::SingularArgument< LabelValue, Type > & operator= (const lector::SingularArgument< LabelValue, Type > &)=default
 Copy assignment operator. Assigns this singular command line argument by copying another one.
 
lector::SingularArgument< LabelValue, Type > & operator= (lector::SingularArgument< LabelValue, Type > &&) noexcept=default
 Move assignment operator. Assigns this singular 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 Type & parsed_or_default_value () const
 Value of this singular command line argument. Returns the parsed value if it exists; otherwise, returns the default value.
 
const std::optional< Type > & parsed_value () const noexcept
 Parsed value of this singular command line argument. Set when this argument is parsed from the command line.
 
void set_parsed_value (const Type &value)
 Sets the parsed value of this singular 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 singular 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::SingularArgument< LabelValue, Type >

A singular 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

◆ SingularArgument() [1/7]

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

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

◆ SingularArgument() [2/7]

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

Constructor for a singular positional required command line argument. No default value is needed.

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

◆ SingularArgument() [3/7]

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

Constructor for a singular named required command line argument or a singular named boolean command line argument. No default value is needed. Singular 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.

◆ SingularArgument() [4/7]

template<auto LabelValue, typename Type >
lector::SingularArgument< LabelValue, Type >::SingularArgument ( const std::string_view  description,
const Type &  default_value 
)

Constructor for a singular positional optional non-boolean command line argument. A default value must be provided.

Parameters
[in]descriptionThe description of the command line argument.
[in]default_valueThe default value of the command line argument.
Exceptions
std::invalid_argumentif this argument's type is boolean or if its description is empty.

◆ SingularArgument() [5/7]

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

Constructor for a singular named optional non-boolean command line argument. A default value must be provided.

Parameters
[in]keysThe keys used to specify the command line argument.
[in]descriptionThe description of the command line argument.
[in]default_valueThe default value of the command line argument.
Exceptions
std::invalid_argumentif this argument's type is boolean, if its keys are invalid, or if its description is empty.

◆ ~SingularArgument()

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

Destructor. Destroys this singular command line argument.

◆ SingularArgument() [6/7]

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

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

◆ SingularArgument() [7/7]

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

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

Member Function Documentation

◆ arity()

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

Arity of this command line argument. A singular 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_value()

template<auto LabelValue, typename Type >
const std::optional< Type > & lector::SingularArgument< LabelValue, Type >::default_value ( ) const
noexcept

Default value of this singular command line argument if it is optional and non-boolean, or std::nullopt otherwise. Set at construction.

Returns
The default value of this singular command line argument.

◆ description()

template<auto LabelValue, typename Type >
std::string_view lector::SingularArgument< 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::SingularArgument< 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 value, 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::SingularArgument< 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::SingularArgument< LabelValue, Type >::has_default ( ) const
noexcept

Returns whether this singular command line argument has a default value.

Returns
True if this singular command line argument has a default value; false if it does not.

◆ has_parsed()

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

Returns whether this singular command line argument has a parsed value.

Returns
True if this singular command line argument has a parsed value; false if it does not.

◆ importance()

template<auto LabelValue, typename Type >
lector::Importance lector::SingularArgument< 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::SingularArgument< 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::SingularArgument< 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::SingularArgument< 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::SingularArgument< 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::SingularArgument< LabelValue, Type > & lector::SingularArgument< LabelValue, Type >::operator= ( const lector::SingularArgument< LabelValue, Type > &  )
default

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

Returns
This singular command line argument after the assignment.

◆ operator=() [2/2]

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

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

Returns
This singular command line argument after the assignment.

◆ options()

template<auto LabelValue, typename Type >
std::string lector::SingularArgument< 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_value()

template<auto LabelValue, typename Type >
const Type & lector::SingularArgument< LabelValue, Type >::parsed_or_default_value ( ) const

Value of this singular command line argument. Returns the parsed value if it exists; otherwise, returns the default value.

Returns
The value of this singular command line argument.
Exceptions
std::logic_errorif this singular command line argument is missing both its parsed value and its default value. Cannot occur in practice due to checks done at construction.

◆ parsed_value()

template<auto LabelValue, typename Type >
const std::optional< Type > & lector::SingularArgument< LabelValue, Type >::parsed_value ( ) const
noexcept

Parsed value of this singular command line argument. Set when this argument is parsed from the command line.

Returns
The parsed value of this singular command line argument.

◆ set_parsed_value()

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

Sets the parsed value of this singular command line argument.

Parameters
[in]valueThe parsed value to set.
Exceptions
std::logic_errorif this singular command line argument is default-constructed or if a parsed value has already been set for this singular command line argument.
std::invalid_argumentif this singular command line argument is boolean and the parsed value is false.

◆ usage()

template<auto LabelValue, typename Type >
std::string lector::SingularArgument< 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: