koutil
Loading...
Searching...
No Matches
koutil::argparser::Parser< Ctx, UParser, Args, Cmds > Class Template Reference

Template class representing a parser. More...

#include <parser.h>

Public Member Functions

constexpr Parser (Ctx &ctx, Args &&args, Cmds &&commands)
 
constexpr Parser (Ctx &ctx, const Args &args, const Cmds &commands)
 
ParseResult parse (std::size_t argc, const char **argv)
 Parses the command-line arguments.
 

Private Member Functions

ParseResult parse_long_opt (std::string_view opt)
 Parses a long option.
 
ParseResult parse_short_opt (std::string_view opt)
 Parses a short option.
 
ParseResult parse_command_or_argument (std::string_view opt)
 Parses a command or argument.
 

Private Attributes

Args m_args
 
Cmds m_subcommands
 
ArgumentsBase const * m_current_args = &m_args
 
CommandsBase const * m_current_cms = &m_subcommands
 
Ctx & m_ctx
 
std::span< const char * > m_values
 
std::size_t m_offset = 0
 

Detailed Description

template<typename Ctx, parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
class koutil::argparser::Parser< Ctx, UParser, Args, Cmds >

Template class representing a parser.

Template Parameters
CtxThe context type.
UParserThe user-defined parser type.
ArgsThe argument types.
CmdsThe command types.

Constructor & Destructor Documentation

◆ Parser() [1/2]

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::Parser ( Ctx & ctx,
Args && args,
Cmds && commands )
inlineconstexpr

◆ Parser() [2/2]

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::Parser ( Ctx & ctx,
const Args & args,
const Cmds & commands )
inlineconstexpr

Member Function Documentation

◆ parse()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::parse ( std::size_t argc,
const char ** argv )

Parses the command-line arguments.

Parameters
argcThe argument count.
argvThe argument values.
Returns
The result of the parsing.

◆ parse_command_or_argument()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::parse_command_or_argument ( std::string_view opt)
private

Parses a command or argument.

Parameters
optThe command or argument.
Returns
The result of the parsing.

◆ parse_long_opt()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::parse_long_opt ( std::string_view opt)
private

Parses a long option.

Parameters
optThe long option.
Returns
The result of the parsing.

◆ parse_short_opt()

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ParseResult koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::parse_short_opt ( std::string_view opt)
private

Parses a short option.

Parameters
optThe short option.
Returns
The result of the parsing.

Member Data Documentation

◆ m_args

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
Args koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_args
private

◆ m_ctx

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
Ctx& koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_ctx
private

◆ m_current_args

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
ArgumentsBase const* koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_current_args = &m_args
private

◆ m_current_cms

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
CommandsBase const* koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_current_cms = &m_subcommands
private

◆ m_offset

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
std::size_t koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_offset = 0
private

◆ m_subcommands

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
Cmds koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_subcommands
private

◆ m_values

template<typename Ctx , parser< Ctx > UParser, are_arguments Args, are_commands Cmds>
std::span<const char*> koutil::argparser::Parser< Ctx, UParser, Args, Cmds >::m_values
private

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