|
VideoTools
|
A class to represent allowed command-line options and to provide command-line usage text. More...
#include <goptions.h>
Public Types | |
| typedef OptionsLevel | Level |
| typedef OptionsLayout | Layout |
Public Member Functions | |
| Options (const std::string &spec, char sep_major= '|', char sep_minor= '!', char escape= '^') | |
| Constructor taking a specification string. More... | |
| Options () | |
| Default constructor for no options. | |
| const StringArray & | names () const |
| Returns the sorted list of long-form option names. | |
| std::string | lookup (char c) const |
| Converts from short-form option character to the corresponding long-form name. More... | |
| bool | valid (const std::string &) const |
| Returns true if the long-form option name is valid. | |
| bool | visible (const std::string &name, Level, bool exact) const |
| Returns true if the option is visible at the given level. More... | |
| bool | valued (char) const |
| Returns true if the short-form option character is valid. More... | |
| bool | valued (const std::string &) const |
| Returns true if the long-form option name is valid. More... | |
| bool | multivalued (char) const |
| Returns true if the short-form option can have multiple values. More... | |
| bool | multivalued (const std::string &) const |
| Returns true if the long-form option can have multiple values. More... | |
| bool | unvalued (const std::string &option_name) const |
| Returns true if the given option name is valid and takes no value. More... | |
| std::string | usageSummary (const std::string &exe, const std::string &args, const std::string &introducer=introducerDefault(), Level level=levelDefault(), size_t wrap_width=widthDefault()) const |
| Returns a one-line (or line-wrapped) usage summary, as "usage: <exe> <options> <args>". | |
| std::string | usageHelp (Level level=levelDefault(), Layout layout=layoutDefault(), bool level_exact=false, bool extra=true) const |
| Returns a multi-line string giving help on each option. | |
| void | showUsage (std::ostream &stream, const std::string &exe, const std::string &args=std::string(), const std::string &introducer=introducerDefault(), Level level=levelDefault(), Layout layout=layoutDefault(), bool extra=true) const |
| Streams out multi-line usage text using usageSummary() and usageHelp(). More... | |
Static Public Member Functions | |
| static size_t | widthDefault () |
| Returns a default, non-zero word-wrapping width, reflecting the size of the standard output where possible. More... | |
| static Layout | layoutDefault () |
| Returns a default column layout. | |
| static Level | levelDefault () |
| Returns the default level. | |
| static std::string | introducerDefault () |
| Returns the string "usage: ". | |
A class to represent allowed command-line options and to provide command-line usage text.
Definition at line 65 of file goptions.h.
|
explicit |
Constructor taking a specification string.
Uses specifications like "p!port!defines the port number!!1!port!1|v!verbose!shows more logging!!0!!1" made up of (1) an optional single-character-option-letter, (2) a multi-character-option-name (3) an option-description, (4) optional option-description-extra text, (5) a value-type (with 0 for unvalued, 1 for a string value, and 2 for a comma-separated list (possibly multiple times)) or (6) a value-description (unless unvalued), and (7) a level enumeration.
By convention mainstream options should have a level of 1, and obscure ones level 2 and above. If the option-description field is empty or if the level is zero then the option is hidden.
Definition at line 33 of file goptions.cpp.
| std::string G::Options::lookup | ( | char | c | ) | const |
Converts from short-form option character to the corresponding long-form name.
Returns the empty string if none.
Definition at line 126 of file goptions.cpp.
| bool G::Options::multivalued | ( | char | c | ) | const |
Returns true if the short-form option can have multiple values.
Returns false if not valid().
Definition at line 100 of file goptions.cpp.
| bool G::Options::multivalued | ( | const std::string & | name | ) | const |
Returns true if the long-form option can have multiple values.
Returns false if not valid().
Definition at line 105 of file goptions.cpp.
| void G::Options::showUsage | ( | std::ostream & | stream, |
| const std::string & | exe, | ||
| const std::string & | args = std::string(), |
||
| const std::string & | introducer = introducerDefault(), |
||
| Level | level = levelDefault(), |
||
| Layout | layout = layoutDefault(), |
||
| bool | extra = true |
||
| ) | const |
Streams out multi-line usage text using usageSummary() and usageHelp().
The 'args' parameter should represent the non-option arguments (with a leading space), like " <foo> [<bar>]".
Definition at line 292 of file goptions.cpp.
| bool G::Options::unvalued | ( | const std::string & | option_name | ) | const |
Returns true if the given option name is valid and takes no value.
Returns false if not valid().
Definition at line 95 of file goptions.cpp.
| bool G::Options::valued | ( | char | c | ) | const |
Returns true if the short-form option character is valid.
Returns false if not valid().
Definition at line 84 of file goptions.cpp.
| bool G::Options::valued | ( | const std::string & | name | ) | const |
Returns true if the long-form option name is valid.
Returns false if not valid().
Definition at line 89 of file goptions.cpp.
| bool G::Options::visible | ( | const std::string & | name, |
| Level | level, | ||
| bool | exact | ||
| ) | const |
Returns true if the option is visible at the given level.
Returns false if not valid().
Definition at line 111 of file goptions.cpp.
|
static |
Returns a default, non-zero word-wrapping width, reflecting the size of the standard output where possible.
Definition at line 143 of file goptions.cpp.