VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
G::OptionParser Class Reference

A parser for command-line arguments that operates according to an Options specification and returns an OptionValue multimap. More...

#include <goptionparser.h>

Public Member Functions

 OptionParser (const Options &spec, OptionMap &values_out, StringArray &errors_out)
 Constructor. More...
 
 OptionParser (const Options &spec, OptionMap &values_out)
 Constructor for when errors can be ignored.
 
size_t parse (const StringArray &args, size_t start_position=1U)
 Parses the given command-line arguments into the value map and/or error list defined by the constructor. More...
 

Detailed Description

A parser for command-line arguments that operates according to an Options specification and returns an OptionValue multimap.

See Also
G::Options, G::OptionValue

Definition at line 42 of file goptionparser.h.

Constructor & Destructor Documentation

G::OptionParser::OptionParser ( const Options spec,
OptionMap values_out,
StringArray errors_out 
)

Constructor.

Output references are kept. The output map is a multimap, but with methods that also allow it to be used as a simple map with multi-valued options concatenated into a comma-separated list.

Member Function Documentation

size_t G::OptionParser::parse ( const StringArray args,
size_t  start_position = 1U 
)

Parses the given command-line arguments into the value map and/or error list defined by the constructor.

By default the program name is expected to be the first item in the array and it is ignored, although the 'start-position' parameter can be used to change this. See also G::Arg::array().

Individual arguments can be in short-form like "-c", or long-form like "--foo" or "--foo=bar". Long-form arguments can be passed in two separate arguments, eg. "--foo" followed by "bar". Short-form options can be grouped (eg. "-abc"). Boolean options can be enabled by (eg.) "--verbose" or "--verbose=yes", and disabled by "--verbose=no". Boolean options cannot use two separate arguments (eg. "--verbose" followed by "yes").

Entries in the output map are keyed by the option's long name, even if supplied in short-form.

Errors are reported into the error list.

Returns the position in the array where the non-option command-line arguments begin.

Definition at line 44 of file goptionparser.cpp.


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