HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
arguments

Classes

class  ArgParse::Arg
 

Typedefs

using ArgParse::Action = std::function< void(cspan< const char * > myargs)>
 Holder for a callback that takes a span of C strings as arguments. More...
 
using ArgParse::ArgAction = std::function< void(Arg &arg, cspan< const char * > myargs)>
 

Functions

Arg & ArgParse::add_argument (const char *argname)
 
template<typename... T>
Arg & ArgParse::add_argument (const char *argname, T...args)
 
Arg & ArgParse::arg (const char *argname)
 Shorter synonym for add_argument(). More...
 
template<typename... T>
Arg & ArgParse::arg (const char *argname, T...args)
 Shorter synonym for add_argument(). More...
 
Arg & ArgParse::separator (string_view text)
 

Detailed Description

Typedef Documentation

using ArgParse::Action = std::function<void(cspan<const char*> myargs)>

Holder for a callback that takes a span of C strings as arguments.

Definition at line 387 of file argparse.h.

using ArgParse::ArgAction = std::function<void(Arg& arg, cspan<const char*> myargs)>

Holder for a callback that takes an Arg ref and a span of C strings as arguments.

Definition at line 391 of file argparse.h.

Function Documentation

Arg& ArgParse::add_argument ( const char *  argname)

Add an argument declaration. Ordinary arguments start with a leading - character (or --, either will be accepted). Positional arguments lack a leading -.

The argname consists of any of these options:

  • "name" : a positional argument.
  • "-name" or "--name" : an ordinary flag argument. If this argument should be followed by parameters, they will later be declared using some combination of Arg::nargs() and Arg::metavar().
  • "--name A B C" : including the names of parameters following the flag itself implicitly means the same thing as calling nargs() and metavar(), and there is no need to call them separately.

This method returns an Arg&, so it is permissible to chain Arg method calls. Those chained calls are what communicates the number of parameters, help message, action, etc. See the Arg class for all the possible Arg methods.

template<typename... T>
Arg& ArgParse::add_argument ( const char *  argname,
T...  args 
)
inline

Alternate way to add an argument, specifying external storage destinations for the parameters. This is more reminiscent of the older, pre-2.2 API, and also can be convenient as an alternative to extracting every parameter and putting them into variables.

Flags with no parameters are followed by a bool*. Args with parameters must declare them as "%T:NAME", where the "%T" part corresponds to the storage type, d for int, f for float, s for std::string, and L for std::vector<std::string>.

Examples:

ArgParse ap;
bool verbose = false;
ap.add_argument("-v", &verbose)
  .help("verbose mode");

float r = 0, g = 0, b = 0;
ap.add_argument("--color %f:R %f:G %f:B", &r, &g, &b)
  .help("diffuse color")
  .action(ArgParse::store<float>());

Definition at line 346 of file argparse.h.

Arg& ArgParse::arg ( const char *  argname)
inline

Shorter synonym for add_argument().

Definition at line 352 of file argparse.h.

template<typename... T>
Arg& ArgParse::arg ( const char *  argname,
T...  args 
)
inline

Shorter synonym for add_argument().

Definition at line 355 of file argparse.h.

Arg& ArgParse::separator ( string_view  text)

Add a separator with a text message. This can be used to group arguments with section headings.

Example:

ArgParse ap;
ap.separator("Basic arguments:");
ap.add_argument("-v");
ap.add_argument("-a");
ap.separator("Advanced arguments:");
ap.add_argument("-b");
ap.add_argument("-c");

Will print the help section like:

Basic arguments:
    -v
    -a
Advanced arguments:
    -b
    -c