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

A command line argument, including its label, value type, keys, description, importance, default value, and parsed value. More...

#include <arguments.hpp>

Public Types

using ValueType = Type
 

Public Member Functions

 Argument () noexcept=default
 Default constructor. Initializes the command line argument with no keys, an empty description, required importance, and no default value.
 
 Argument (::lector::Argument< LabelValue, Type > &&) noexcept=default
 Move constructor. Constructs a command line argument by moving another one.
 
 Argument (const ::lector::Argument< LabelValue, Type > &)=default
 Copy constructor. Constructs a command line argument by copying another one.
 
 Argument (const ::std::initializer_list<::std::string > &keys, const ::std::string &description)
 Constructor for a required command line argument or a boolean command line argument. No default value is needed. Boolean command line arguments are always optional and always default to false.
 
 Argument (const ::std::initializer_list<::std::string > &keys, const ::std::string &description, const Type &default_value)
 Constructor for an optional non-boolean command line argument. A default value must be provided.
 
 ~Argument () noexcept=default
 Destructor. Destroys this command line argument.
 
const ::std::optional< Type > & default_value () const noexcept
 Default value of this command line argument. Only relevant for optional non-boolean arguments. 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::Importance importance () const noexcept
 Importance of this command line argument. Required arguments must be provided by the user, while optional arguments may or may not be provided by the user. Set at construction.
 
const ::std::vector<::std::string > & keys () const noexcept
 Keys that can be used to specify this command line 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.
 
::lector::Argument< LabelValue, Type > & operator= (::lector::Argument< LabelValue, Type > &&) noexcept=default
 Move assignment operator. Assigns this command line argument by moving another one.
 
::lector::Argument< LabelValue, Type > & operator= (const ::lector::Argument< LabelValue, Type > &)=default
 Copy assignment operator. Assigns this command line argument by copying another one.
 
::std::string options () const
 Prints the options of this command line argument as a string of text. The options consist of this command line argument's list of keys and value type along with its description.
 
const Type & parsed_or_default_value () const
 Value of this 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 command line argument. Set when this command line argument is parsed.
 
void set_parsed_value (const Type &value)
 Sets the parsed value of this command line argument.
 
::std::string usage () const
 Prints the usage of this command line argument as a string of text. The usage 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 constexpr auto label () noexcept
 Label of this command line argument. Used to uniquely identify this command line argument. Set at construction.
 

Detailed Description

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

A command line argument, including its label, value type, keys, description, importance, default value, and parsed value.

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

◆ Argument() [1/5]

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

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

◆ Argument() [2/5]

template<auto LabelValue, typename Type >
lector::Argument< LabelValue, Type >::Argument ( const ::std::initializer_list<::std::string > &  keys,
const ::std::string &  description 
)

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

Parameters
[in]keysThe keys that can be used to specify the command line argument.
[in]descriptionThe description of the command line argument.
Exceptions
std::invalid_argumentif any of the parameters are invalid.

◆ Argument() [3/5]

template<auto LabelValue, typename Type >
lector::Argument< LabelValue, Type >::Argument ( const ::std::initializer_list<::std::string > &  keys,
const ::std::string &  description,
const Type &  default_value 
)

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

Parameters
[in]keysThe keys that can be 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 any of the parameters are invalid.

◆ ~Argument()

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

Destructor. Destroys this command line argument.

◆ Argument() [4/5]

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

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

◆ Argument() [5/5]

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

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

Member Function Documentation

◆ default_value()

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

Default value of this command line argument. Only relevant for optional non-boolean arguments. Set at construction.

Returns
The default value of this command line argument.

◆ description()

template<auto LabelValue, typename Type >
::std::string_view lector::Argument< 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::Argument< 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.

◆ importance()

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

Importance of this command line argument. Required arguments must be provided by the user, while optional arguments may or may not be provided by the user. Set at construction.

Returns
The importance of this command line argument.

◆ keys()

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

Keys that can be used to specify this command line 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::Argument< 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::Argument< LabelValue, Type >::label ( )
staticconstexprnoexcept

Label of this command line argument. Used to uniquely identify this command line argument. Set at construction.

Returns
The label of this command line argument.

◆ longest_key_with_value_type()

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

Returns
The string that contains the longest key and its associated value type.

◆ operator=() [1/2]

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

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

Returns
This command line argument after the assignment.

◆ operator=() [2/2]

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

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

Returns
This command line argument after the assignment.

◆ options()

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

Prints the options of this command line argument as a string of text. The options consist of this command line argument's list of keys and value type along with its description.

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

◆ parsed_or_default_value()

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

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

Returns
The value of this command line argument.
Exceptions
std::logic_errorif this command line argument is missing both its parsed value and its default value.

◆ parsed_value()

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

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

Returns
The parsed value of this command line argument.

◆ set_parsed_value()

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

Sets the parsed value of this command line argument.

Parameters
[in]valueThe parsed value to set.

◆ usage()

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

Prints the usage of this command line argument as a string of text. The usage 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 of this command line argument.

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