Deepsolver
|
The command line parser. More...
Classes | |
struct | Key |
An available command line argument. More... | |
struct | Param |
Public Types | |
typedef std::list< Key > | KeyList |
typedef std::vector< Key > | KeyVector |
Public Member Functions | |
void | addKey (const std::string &name, const std::string &descr) |
Adds new argument to the table of the available arguments. | |
void | addKey (const std::string &name, const std::string &argName, const std::string &descr) |
Adds new argument to the table of the available arguments. | |
void | addKeyDoubleName (const std::string &name1, const std::string &name2, const std::string &descr) |
Adds new argument to the table of available arguments. | |
void | addKeyDoubleName (const std::string &name1, const std::string &name2, const std::string &argName, const std::string &descr) |
Adds new argument to the table of available arguments. | |
CliParser () | |
The default constructor. | |
void | init (int argc, char *argv[]) |
Fills internal vector of arguments mentioned by user. | |
bool | isKeyUsed (const std::string &keyName, std::string &arg) const |
Checks if the argument was mentioned by a user. | |
bool | isKeyUsed (const std::string &keyName) const |
Checks if the argument was mentioned by a user. | |
void | parse () |
Runs main parsing process. | |
void | printHelp (std::ostream &s) const |
Prints the help screen. | |
virtual | ~CliParser () |
The destructor. | |
Public Attributes | |
StringVector | files |
The arguments not present in available arguments table or mentioned after "--" sequence. | |
KeyVector | keys |
The table of all available arguments. | |
Protected Member Functions | |
KeyVector::size_type | findKey (const std::string &name) const |
Searches the argument in the table of available arguments. | |
bool | hasKeyArgument (const std::string &name) const |
virtual void | parseCluster (const StringVector &cluster, int &mode) |
Parses one cluster. | |
virtual size_t | recognizeCluster (const StringVector ¶ms, int &mode) const |
Recognizes cluster of command line arguments. | |
virtual void | stopMissedArgument (const std::string &keyName) const |
Indicates the argument was mentioned without a required parameter. | |
virtual void | stopNoPrgName () const |
Indicates that the provided argc value equals zero. |
This class implements flexible approach to the command line parsing procedure. General difference from usual command line parsing utilities is an adding preliminary step before checking what arguments a user has mentioned in command line. During this step entire arguments set is divided onto several clusters. Each cluster gathers a subset of arguments which should be parsed together. The second step is a parsing itself, which analyzes all constructed cluster one by one.
A user should implement recognizeCluster() and parseCluster() methods to get the exact behaviour he wants. CliParser class has its own implementation of these methods with default behaviour. The default behaviour performs clustering and parsing based on user-defined table of available command line arguments. On custom implementation the internal table of available arguments is used only for help screen printing, unless custom variant is not explicitly involve them.
void CliParser::addKey | ( | const std::string & | name, |
const std::string & | descr | ||
) |
[in] | name | The name of the argument to add |
[in] | descr | The argument description for a help screen |
void CliParser::addKey | ( | const std::string & | name, |
const std::string & | argName, | ||
const std::string & | descr | ||
) |
[in] | name | The name of the argument to add |
[in] | argName | The name of additional parameter (used in a help screen) |
[in] | descr | The argument description for a help screen |
void CliParser::addKeyDoubleName | ( | const std::string & | name1, |
const std::string & | name2, | ||
const std::string & | descr | ||
) |
[in] | name1 | The name of the argument to add |
[in] | name2 | The synonym of the argument to add |
[in] | descr | The argument description for a help screen |
void CliParser::addKeyDoubleName | ( | const std::string & | name1, |
const std::string & | name2, | ||
const std::string & | argName, | ||
const std::string & | descr | ||
) |
[in] | name1 | The name of the argument to add |
[in] | name2 | The synonym of the argument to add |
[in] | argName | The name of additional parameter (used in a help screen) |
[in] | descr | The argument description for a help screen |
CliParser::KeyVector::size_type CliParser::findKey | ( | const std::string & | name | ) | const [protected] |
[in] | name | Name of the argument to search |
bool CliParser::hasKeyArgument | ( | const std::string & | name | ) | const [protected] |
Checks if specified argument has an additional parameter
name | The name of the argument to check |
void Deepsolver::CliParser::init | ( | int | argc, |
char * | argv[] | ||
) |
[in] | argc | The argc value provided to the application main()function |
[in] | argv | The argv value provided to the application main()function |
bool Deepsolver::CliParser::isKeyUsed | ( | const std::string & | keyName, |
std::string & | arg | ||
) | const |
[in] | keyName | The name of the argument to check |
[out] | arg | The reference to the variable to receive additional parameter value |
bool Deepsolver::CliParser::isKeyUsed | ( | const std::string & | keyName | ) | const |
[in] | keyName | The name of an argument to check |
virtual void Deepsolver::CliParser::parseCluster | ( | const StringVector & | cluster, |
int & | mode | ||
) | [protected, virtual] |
[in] | cluster | The arguments of one cluster to parse |
[in/out] | mode The additional mode variable with user-defined purpose |
Reimplemented in DsPatchCliParser, and DsInstallCliParser.
void CliParser::printHelp | ( | std::ostream & | s | ) | const |
[in] | s | The stream to print help screen to |
virtual size_t Deepsolver::CliParser::recognizeCluster | ( | const StringVector & | params, |
int & | mode | ||
) | const [protected, virtual] |
The descent class may provide custom implementation of this method.
[in] | params | The list of all arguments potentially included into a cluster |
[in/out] | mode The additional mode variable with user-defined purpose |
Reimplemented in DsPatchCliParser, and DsInstallCliParser.
void CliParser::stopMissedArgument | ( | const std::string & | keyName | ) | const [protected, virtual] |
This method must throw an exception or call the exit() function to interrupt parsing procedure.
[in] | keyname | The name of the argument mentioned without a parameter. |
void CliParser::stopNoPrgName | ( | ) | const [protected, virtual] |
This method must throw an exception or call the exit() function to interrupt parsing procedure.