Lector v1.0.0
C++ library for parsing command line arguments.
Classes | Public Member Functions | List of all members
lector::Arguments< ArgumentTypes > Class Template Referencefinal

A collection of command line arguments that can be parsed from argc and argv. More...

#include <arguments.hpp>

Public Member Functions

 Arguments (::lector::Arguments< ArgumentTypes... > &&) noexcept=default
 Move constructor. Constructs a collection of command line argument by moving another one.
 
 Arguments (ArgumentTypes... arguments)
 Compile-time check that all arguments have unique labels.
 
 Arguments (const ::lector::Arguments< ArgumentTypes... > &)=default
 Copy constructor. Constructs a collection of command line argument by copying another one.
 
 ~Arguments () noexcept=default
 Destructor. Destroys this collection of command line arguments.
 
const ::std::filesystem::path & executable_path () const
 Returns the executable path of this collection of command line arguments. If the command line arguments have not yet been parsed from argc and argv, this path is empty.
 
::std::string execution () const
 Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any.
 
template<auto Label>
const auto & get () const
 Returns a specified command line argument from this collection.
 
::lector::Arguments< ArgumentTypes... > & operator= (::lector::Arguments< ArgumentTypes... > &&) noexcept=default
 Move assignment operator. Assigns this collection of command line argument by moving another one.
 
::lector::Arguments< ArgumentTypes... > & operator= (const ::lector::Arguments< ArgumentTypes... > &)=default
 Copy assignment operator. Assigns this collection of command line argument by copying another one.
 
::std::string options () const
 Prints the options of this collection of command line argument as a string of text. The options consist of each command line argument's list of keys and value type along with their descriptions. Required command line arguments are printed first, followed by optional ones.
 
void parse (const int argc, char *argv[])
 Parses argc and argv to populate the parsed values of the command line arguments in this collection.
 
::std::string usage () const
 Prints the usage of this collection of command line arguments as a string of text. The usage consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments. Required command line arguments are printed first, followed by optional ones.
 

Detailed Description

template<typename... ArgumentTypes>
class lector::Arguments< ArgumentTypes >

A collection of command line arguments that can be parsed from argc and argv.

Template Parameters
...ArgumentTypesVariadic list of the types of the command line arguments in this collection.

Constructor & Destructor Documentation

◆ Arguments() [1/3]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( ArgumentTypes...  arguments)
explicit

Compile-time check that all arguments have unique labels.

Constructor. Constructs a collection of command line arguments by moving a variadic list of command line arguments.

Parameters
[in]...argumentsThe variadic list of command line arguments.

◆ ~Arguments()

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::~Arguments ( )
defaultnoexcept

Destructor. Destroys this collection of command line arguments.

◆ Arguments() [2/3]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( const ::lector::Arguments< ArgumentTypes... > &  )
default

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

◆ Arguments() [3/3]

template<typename... ArgumentTypes>
lector::Arguments< ArgumentTypes >::Arguments ( ::lector::Arguments< ArgumentTypes... > &&  )
defaultnoexcept

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

Member Function Documentation

◆ executable_path()

template<typename... ArgumentTypes>
const ::std::filesystem::path & lector::Arguments< ArgumentTypes >::executable_path ( ) const

Returns the executable path of this collection of command line arguments. If the command line arguments have not yet been parsed from argc and argv, this path is empty.

Returns
The executable path of this collection of command line arguments.

◆ execution()

template<typename... ArgumentTypes>
::std::string lector::Arguments< ArgumentTypes >::execution ( ) const

Prints the execution of this collection of command line argument as a string of text. The execution consists of the executable path followed by each argument's longest key and corresponding parsed value, if any.

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

◆ get()

template<typename... ArgumentTypes>
template<auto Label>
const auto & lector::Arguments< ArgumentTypes >::get ( ) const

Returns a specified command line argument from this collection.

Template Parameters
LabelThe label of the command line argument to return.
Returns
The specified command line argument.

◆ operator=() [1/2]

template<typename... ArgumentTypes>
::lector::Arguments< ArgumentTypes... > & lector::Arguments< ArgumentTypes >::operator= ( ::lector::Arguments< ArgumentTypes... > &&  )
defaultnoexcept

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

Returns
This collection of command line argument after the assignment.

◆ operator=() [2/2]

template<typename... ArgumentTypes>
::lector::Arguments< ArgumentTypes... > & lector::Arguments< ArgumentTypes >::operator= ( const ::lector::Arguments< ArgumentTypes... > &  )
default

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

Returns
This collection of command line argument after the assignment.

◆ options()

template<typename... ArgumentTypes>
::std::string lector::Arguments< ArgumentTypes >::options ( ) const

Prints the options of this collection of command line argument as a string of text. The options consist of each command line argument's list of keys and value type along with their descriptions. Required command line arguments are printed first, followed by optional ones.

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

◆ parse()

template<typename... ArgumentTypes>
void lector::Arguments< ArgumentTypes >::parse ( const int  argc,
char *  argv[] 
)

Parses argc and argv to populate the parsed values of the command line arguments in this collection.

Parameters
[in]argcThe number of command line arguments, including the executable path.
[in]argvThe array of C-strings that represents the command line arguments, starting with the executable path.
Exceptions
std::invalid_argumentif an invalid, unknown, duplicated, or missing argument is encountered.

◆ usage()

template<typename... ArgumentTypes>
::std::string lector::Arguments< ArgumentTypes >::usage ( ) const

Prints the usage of this collection of command line arguments as a string of text. The usage consists of each argument's longest key and value type, enclosed in square braces for optional command line arguments. Required command line arguments are printed first, followed by optional ones.

Returns
The string of text that contains the usage of this collection of command line arguments.

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