incron  0.5.10
Static Public Member Functions | Static Protected Member Functions
AppArgs Class Reference

Application arguments. More...

#include <appargs.h>

List of all members.

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.

Detailed Description

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.


Member Function Documentation

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.

Parameters:
[in]rNamelong option name
[in]cShortshort (one-character) option name
[in]typeargument type
[in]fMandatoryoption is mandatory yes/no
Returns:
true = success, false = failure (e.g. option already exists)
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.

Attention:
This method may be very slow.
void AppArgs::DumpOption ( const std::string &  rName,
char  cShort,
AppArgOption_t pOpt 
) [static, protected]

Dumps an option to STDERR.

Parameters:
[in]rNamelong option name
[in]cShortshort option name
[in]pOptoption data
bool AppArgs::ExistsOption ( const std::string &  rArg) [static]

Checks whether an option exists.

Parameters:
[in]rArglong option name
Returns:
true = option exists, false = otherwise
bool AppArgs::GetOption ( const std::string &  rArg,
std::string &  rVal 
) [static]

Extracts an option value.

Parameters:
[in]rArglong option name
[out]rValoption value
Returns:
true = value extracted, false = option not found or has no value
bool AppArgs::GetValue ( size_t  index,
std::string &  rVal 
) [static]

Extracts a value.

Parameters:
[in]indexvalue index
[out]rValextracted value
Returns:
true = value extracted, false = otherwise
size_t AppArgs::GetValueCount ( ) [static]

Returns the count of values.

Returns:
count of values
void AppArgs::Init ( size_t  valMinCnt = 0,
size_t  valMaxCnt = APPARGS_NOLIMIT 
) [static]

Initializes the processor.

Parameters:
[in]valMinCntminimum count of values
[in]valMaxCntmaximum 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).

Parameters:
[in]pchStrtext string
Returns:
true = option, false = otherwise
bool AppArgs::IsOption ( const char *  pchStr) [static, protected]

Checks whether a string is an option.

Parameters:
[in]pchStrtext string
Returns:
true = option, false = otherwise
bool AppArgs::IsValid ( ) [static]

Checks whether the arguments have valid form.

Arguments are valid if:

  • all mandatory options are present
  • all options with mandatory values have their values
  • value count is between its minimum and maximum
  • there are no unknown options (if unknown options are not accepted)
Returns:
true = arguments valid, false = otherwise
void AppArgs::Parse ( int  argc,
const char *const *  argv 
) [static]

Parses arguments and builds the appropriate structure.

Parameters:
[in]argcargument count
[in]argvargument vector
Attention:
All errors are silently ignored.
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.

Parameters:
[in]pchStrtext string
[out]rNameoption name
[out]rValvalue string
[out]rfHasValoption has value yes/no
Returns:
true = success, false = failure
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.

Parameters:
[in]pchStrtext string
[out]rcNameoption name
[out]rValvalue string
[out]rfHasValoption has value yes/no
Attention:
This method assumes the string is a valid short option.

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