ui-utilcpp 1.10.1
|
Abstraction class for GNU getopt_long(3). More...
#include <GetOpt.hpp>
Public Types | |
enum | Type { NoArg_ , Arg_ , OptArg_ } |
All three possible types of CLOption* Classes. More... | |
Public Member Functions | |
GetOpt (int argc, char *const *const argv) | |
Standard constructor. More... | |
~GetOpt () | |
Standard destructor. | |
GetOpt & | set (std::string const &nameLong, char nameShort, Type type, std::string const &doc="No documentation for this option.", std::string const &defaultArg="") |
Introduce a new option. More... | |
CLOption * | get (char nameShort) |
Get an option object from short name. More... | |
CLOption * | get (std::string const &nameLong) |
Get an option object from long name. More... | |
void | printUsage (std::string const &title="\nUsage:\n\n") const |
Prints out Usage information to cout (stdout). More... | |
int | wrongUsage (std::string const &reason, std::string const &title="\nUsage:\n\n") const |
Helper. More... | |
bool | isValid () |
Check if given command line arguments are "well-formed". More... | |
Abstraction class for GNU getopt_long(3).
Use this rather than the CLOption*-Classes directly.
All three possible types of CLOption* Classes.
In normal use, you would use this in set(), who then choses what type of object to create. Use "NOARG" for CLOption, "ARG" for CLOptionArg and "OPTARG" for CLOptionOptArg.
UI::Util::GetOpt::GetOpt | ( | int | argc, |
char *const *const | argv | ||
) |
Standard constructor.
argc | Number of arguments (first argument of main() function). |
argv | Array of arguments (second argument of main() function). |
CLOption * UI::Util::GetOpt::get | ( | char | nameShort | ) |
Get an option object from short name.
The pointer is valid as long as the GetOpt object stays alive. This will implicitely parse the command line options, if not already done.
nameShort | Short name (one character) of the option; e.g. 'v'. |
References UI::Util::CLOption::getNameShort().
CLOption * UI::Util::GetOpt::get | ( | std::string const & | nameLong | ) |
Get an option object from long name.
nameLong | Long name of the option; e.g. "version". |
References UI::Util::CLOption::getNameLong().
bool UI::Util::GetOpt::isValid | ( | ) |
Check if given command line arguments are "well-formed".
void UI::Util::GetOpt::printUsage | ( | std::string const & | title = "\nUsage:\n\n" | ) | const |
Prints out Usage information to cout (stdout).
title | Print this text before usage information. |
References UI::Util::CLOption::printUsage().
Referenced by wrongUsage().
GetOpt & UI::Util::GetOpt::set | ( | std::string const & | nameLong, |
char | nameShort, | ||
Type | type, | ||
std::string const & | doc = "No documentation for this option." , |
||
std::string const & | defaultArg = "" |
||
) |
Introduce a new option.
nameLong | Long name of the option; e.g. "version". |
nameShort | Short name (one character) of the option; e.g. 'v'. |
type | Type of the option (NOARG, ARG, OPTARG); e.g. "NOARG". |
doc | Documentaion for this option; e.g. "Show version information". |
defaultArg | Default value for that option. |
int UI::Util::GetOpt::wrongUsage | ( | std::string const & | reason, |
std::string const & | title = "\nUsage:\n\n" |
||
) | const |
Helper.
Prints out an error text to cerr, prints usage to cout and always returns 1 (suitable as program exit code).
reason | Explanatory error text. |
title | Print this text before usage information. |
References printUsage().