incron
0.5.10
|
Application arguments. More...
#include <appargs.h>
Static Public Member Functions | |
static void | Init (size_t valMinCnt=0, size_t valMaxCnt=APPARGS_NOLIMIT) |
Initializes the processor. | |
static void | Destroy () |
Releases resources allocated by the processor. | |
static void | Parse (int argc, const char *const *argv) |
Parses arguments and builds the appropriate structure. | |
static bool | IsValid () |
Checks whether the arguments have valid form. | |
static bool | ExistsOption (const std::string &rArg) |
Checks whether an option exists. | |
static bool | GetOption (const std::string &rArg, std::string &rVal) |
Extracts an option value. | |
static bool | AddOption (const std::string &rName, char cShort, AppArgType_t type, bool fMandatory) |
Adds an option. | |
static size_t | GetValueCount () |
Returns the count of values. | |
static bool | GetValue (size_t index, std::string &rVal) |
Extracts a value. | |
static void | Dump () |
Dumps information about options and value to STDERR. | |
Static Protected Member Functions | |
static bool | IsOption (const char *pchStr) |
Checks whether a string is an option. | |
static bool | IsLongOption (const char *pchStr) |
Checks whether a string is a long option. | |
static bool | ParseLong (const char *pchStr, std::string &rName, std::string &rVal, bool &rfHasVal) |
Parses a string and attempts to treat it as a long option. | |
static void | ParseShort (const char *pchStr, char &rcName, std::string &rVal, bool &rfHasVal) |
Parses a string and attempts to treat it as a short option. | |
static void | DumpOption (const std::string &rName, char cShort, AppArgOption_t *pOpt) |
Dumps an option to STDERR. |
Application arguments.
This class is set-up for processing command line arguments. Then it parses these arguments and builds data which can be queried later.
There are two categories of arguments:
Options represent changeable parameters of the application. Values are a kind of input data.
Each option has one of the following types:
Each option always have two forms - long one (introcuded by two hyphens, e.g. --edit) and short one (introduced by one hyphen, e.g. -e). These forms are functionally equivalent.
Unknown options are silently ignored.
bool AppArgs::AddOption | ( | const std::string & | rName, |
char | cShort, | ||
AppArgType_t | type, | ||
bool | fMandatory | ||
) | [static] |
Adds an option.
This method is intended to be called between initilization and parsing. It adds an option which may (or must) occur inside the argument vector.
[in] | rName | long option name |
[in] | cShort | short (one-character) option name |
[in] | type | argument type |
[in] | fMandatory | option is mandatory yes/no |
void AppArgs::Destroy | ( | ) | [static] |
Releases resources allocated by the processor.
This method should be called if the argument values are no longer needed.
void AppArgs::Dump | ( | ) | [static] |
Dumps information about options and value to STDERR.
void AppArgs::DumpOption | ( | const std::string & | rName, |
char | cShort, | ||
AppArgOption_t * | pOpt | ||
) | [static, protected] |
Dumps an option to STDERR.
[in] | rName | long option name |
[in] | cShort | short option name |
[in] | pOpt | option data |
bool AppArgs::ExistsOption | ( | const std::string & | rArg | ) | [static] |
Checks whether an option exists.
[in] | rArg | long option name |
bool AppArgs::GetOption | ( | const std::string & | rArg, |
std::string & | rVal | ||
) | [static] |
Extracts an option value.
[in] | rArg | long option name |
[out] | rVal | option value |
bool AppArgs::GetValue | ( | size_t | index, |
std::string & | rVal | ||
) | [static] |
Extracts a value.
[in] | index | value index |
[out] | rVal | extracted value |
size_t AppArgs::GetValueCount | ( | ) | [static] |
Returns the count of values.
void AppArgs::Init | ( | size_t | valMinCnt = 0 , |
size_t | valMaxCnt = APPARGS_NOLIMIT |
||
) | [static] |
Initializes the processor.
[in] | valMinCnt | minimum count of values |
[in] | valMaxCnt | maximum number of values (no effect if lower than valMinCnt) |
bool AppArgs::IsLongOption | ( | const char * | pchStr | ) | [static, protected] |
Checks whether a string is a long option.
This methos assumes the string is an option (if not the behavior is undefined).
[in] | pchStr | text string |
bool AppArgs::IsOption | ( | const char * | pchStr | ) | [static, protected] |
Checks whether a string is an option.
[in] | pchStr | text string |
bool AppArgs::IsValid | ( | ) | [static] |
Checks whether the arguments have valid form.
Arguments are valid if:
void AppArgs::Parse | ( | int | argc, |
const char *const * | argv | ||
) | [static] |
Parses arguments and builds the appropriate structure.
[in] | argc | argument count |
[in] | argv | argument vector |
bool AppArgs::ParseLong | ( | const char * | pchStr, |
std::string & | rName, | ||
std::string & | rVal, | ||
bool & | rfHasVal | ||
) | [static, protected] |
Parses a string and attempts to treat it as a long option.
[in] | pchStr | text string |
[out] | rName | option name |
[out] | rVal | value string |
[out] | rfHasVal | option has value yes/no |
void AppArgs::ParseShort | ( | const char * | pchStr, |
char & | rcName, | ||
std::string & | rVal, | ||
bool & | rfHasVal | ||
) | [static, protected] |
Parses a string and attempts to treat it as a short option.
[in] | pchStr | text string |
[out] | rcName | option name |
[out] | rVal | value string |
[out] | rfHasVal | option has value yes/no |