Clingo
Loading...
Searching...
No Matches
Clingo::Options Class Reference

Object to add command-line options. More...

#include <app.hh>

Public Types

using Parser = std::function< bool(std::string_view value)>
 An option parser.
 
using ParserList = std::forward_list< Parser >
 A list of option parsers.
 

Public Member Functions

 Options (clingo_options_t *opts, ParserList &parsers)
 Construct an options object.
 
void add (std::string_view group, std::string_view option, std::string_view description, Parser parser, bool multi=false, std::optional< std::string_view > argument=std::nullopt)
 Add an option that is processed with a custom parser.
 
void add_flag (std::string_view group, std::string_view option, std::string_view description, bool &flag)
 Add an option that is a simple flag.
 

Friends

auto c_cast (Options const &x) -> clingo_options_t *
 Convert the class to it's underlying C type.
 

Detailed Description

Object to add command-line options.

Member Typedef Documentation

◆ Parser

using Clingo::Options::Parser = std::function<bool(std::string_view value)>

An option parser.

The function takes the value to parse and returns whether the value has been parsed successfully.

Constructor & Destructor Documentation

◆ Options()

Clingo::Options::Options ( clingo_options_t opts,
ParserList parsers 
)
inline

Construct an options object.

For internal use.

Parameters
optsthe corresponding C type
parsersa list to store option parsers in

Member Function Documentation

◆ add()

void Clingo::Options::add ( std::string_view  group,
std::string_view  option,
std::string_view  description,
Parser  parser,
bool  multi = false,
std::optional< std::string_view >  argument = std::nullopt 
)
inline

Add an option that is processed with a custom parser.

Note that the parser that the parse is responsible to store the semantic value.

Parameter option specifies the name(s) of the option. For example, "-p,ping" adds the short option "-p" and its long form "--ping". It is also possible to associate an option with a help level by prepending "@l" to the option specification. Options with a level greater than zero are only shown if the argument to help is greater or equal to l.

Parameters
groupthe section in the help output
optionthe option specification
descriptionthe option description
parsera parser callback
multiwhether the option can be specified multiple times
argumentthe value placeholder for the help output

◆ add_flag()

void Clingo::Options::add_flag ( std::string_view  group,
std::string_view  option,
std::string_view  description,
bool flag 
)
inline

Add an option that is a simple flag.

This function provides a simpler alternative to Options::add() to add flags, which do not take values. When the flag appears on the command line, the target parameter is set to true. Explicit values can also be provided using --flag={yes|no}.

Parameters
groupthe section in the help output
optionthe option specification
descriptionthe option description
flaga reference to the semantic value

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