MVE - Multi-View Environment mve-devel
|
Argument class that provides a parser and convenient access for command line arguments as used by GNU utils. More...
#include <arguments.h>
Public Member Functions | |
Arguments (void) | |
void | add_option (char shortname, std::string const &longname, bool has_argument, std::string const &description="") |
Adds an option to the list of possible arguments. | |
void | generate_helptext (std::ostream &stream) const |
Generates a help text that lists all arguments. | |
void | get_ids_from_string (std::string const &str, std::vector< int > *ids) |
Returns a numeric list of IDs by parsing the given string. | |
std::string | get_nth_nonopt (std::size_t index) |
Returns the Nth non-option argument, or an empty string. | |
template<typename T > | |
T | get_nth_nonopt_as (std::size_t index) |
Returns the Nth non-option argument as type T, or throws. | |
ArgResult const * | next_option (void) |
Iterator for the options. | |
ArgResult const * | next_result (void) |
Iterator for the results. | |
void | parse (int argc, char const *const *argv) |
Parses command line arguments. | |
void | parse (std::vector< std::string > const &args) |
Parses arguments from a vector. | |
void | set_description (std::string const &str) |
Sets the optional description text to be printed on help. | |
void | set_description_word_wrap (int width) |
Sets the text width of the description string for automatic line breaking. | |
void | set_exit_on_error (bool exit) |
Specifies if the application should be exited if parsing was not successful. | |
void | set_helptext_indent (int indent) |
Sets amount column width for indenting help description. | |
void | set_nonopt_maxnum (std::size_t limit) |
Sets a maximum limit on the amount of non-option argument. | |
void | set_nonopt_minnum (std::size_t limit) |
Sets a minimum limit on the amount of non-option argument. | |
void | set_usage (char const *argv0, std::string const &usage) |
Sets the usage string for printing the help text. | |
void | set_usage (std::string const &str) |
Sets the usage string for printing the help text. | |
Argument class that provides a parser and convenient access for command line arguments as used by GNU utils.
An error while parsing the arguments raises exception util::Exception. The resulting list of arguments is provided as iterator over ArgResult objects.
The parser enforces arguments in the format:
command [options | non-options] [–] [non-options]
The following rules apply:
The first argument, argv[0], is treated as the command that started the application and is ignored; thus argument parsing starts at argv[1].
Definition at line 75 of file arguments.h.
util::Arguments::Arguments | ( | void | ) |
Definition at line 22 of file arguments.cc.
void util::Arguments::add_option | ( | char | shortname, |
std::string const & | longname, | ||
bool | has_argument, | ||
std::string const & | description = "" |
||
) |
Adds an option to the list of possible arguments.
Definition at line 45 of file arguments.cc.
void util::Arguments::generate_helptext | ( | std::ostream & | stream | ) | const |
Generates a help text that lists all arguments.
Definition at line 362 of file arguments.cc.
void util::Arguments::get_ids_from_string | ( | std::string const & | str, |
std::vector< int > * | ids | ||
) |
Returns a numeric list of IDs by parsing the given string.
Definition at line 333 of file arguments.cc.
std::string util::Arguments::get_nth_nonopt | ( | std::size_t | index | ) |
Returns the Nth non-option argument, or an empty string.
Definition at line 315 of file arguments.cc.
T util::Arguments::get_nth_nonopt_as | ( | std::size_t | index | ) |
Returns the Nth non-option argument as type T, or throws.
Definition at line 242 of file arguments.h.
ArgResult const * util::Arguments::next_option | ( | void | ) |
Iterator for the options.
It does not return arguments that are non-options, i.e. opt is never null. The method returns null if there are no more non-option arguments.
Definition at line 296 of file arguments.cc.
ArgResult const * util::Arguments::next_result | ( | void | ) |
Iterator for the results.
If opt is null, the argument is a non-option. Otherwise opt points to one of the given argument options. The method returns null if there are no more arguments.
Definition at line 281 of file arguments.cc.
void util::Arguments::parse | ( | int | argc, |
char const *const * | argv | ||
) |
Parses command line arguments.
Definition at line 68 of file arguments.cc.
void util::Arguments::parse | ( | std::vector< std::string > const & | args | ) |
Parses arguments from a vector.
Definition at line 79 of file arguments.cc.
|
inline |
Sets the optional description text to be printed on help.
Definition at line 205 of file arguments.h.
|
inline |
Sets the text width of the description string for automatic line breaking.
This defaults to 75, 0 disables feature.
Definition at line 211 of file arguments.h.
|
inline |
Specifies if the application should be exited if parsing was not successful.
Before exiting, the arguments help text is printed to stderr. Defaults to "not exit".
Definition at line 235 of file arguments.h.
|
inline |
Sets amount column width for indenting help description.
This property defaults to 16.
Definition at line 217 of file arguments.h.
|
inline |
Sets a maximum limit on the amount of non-option argument.
This propertiy default to no limit.
Definition at line 223 of file arguments.h.
|
inline |
Sets a minimum limit on the amount of non-option argument.
This property defaults to zero.
Definition at line 229 of file arguments.h.
void util::Arguments::set_usage | ( | char const * | argv0, |
std::string const & | usage | ||
) |
Sets the usage string for printing the help text.
Definition at line 35 of file arguments.cc.
|
inline |
Sets the usage string for printing the help text.
Definition at line 199 of file arguments.h.