#include <halCLParser.h>
Classes | |
struct | Argument |
struct | Option |
Public Member Functions | |
virtual void | setOptionPrefix (const std::string &prefix) |
template<typename T > | |
void | addOption (const std::string &name, const std::string &descritpion, const T &defaultValue) |
template<typename T > | |
T | getOption (const std::string &name) const |
bool | hasOption (const std::string &name) const |
void | addArgument (const std::string &name, const std::string &description) |
template<typename T > | |
T | getArgument (const std::string &name) const |
bool | hasArgument (const std::string &name) const |
void | addOptionFlag (const std::string &name, const std::string &description, bool defaultValue) |
bool | getFlag (const std::string &name) const |
bool | hasFlag (const std::string &name) const |
template<typename T > | |
T | get (const std::string &name) const |
void | setDescription (const std::string &description) |
void | setExample (const std::string &example) |
virtual void | parseOptions (int argc, char **argv) |
virtual void | printUsage (std::ostream &os) const |
Protected Member Functions | |
template<typename T > | |
T | convertFromString (const std::string &token) const |
Static Protected Member Functions | |
static std::string | multiLine (const std::string &line, size_t indent) |
Protected Attributes | |
std::string | _prefix |
std::string | _exeName |
std::string | _description |
std::string | _example |
std::vector< Argument > | _args |
std::map< std::string, Option > | _options |
size_t | _maxArgLen |
size_t | _maxOptLen |
Static Protected Attributes | |
static size_t | lineWidth |
Very basic command line parser. Modeled after Python's. Supports options. Ex: –threshold 10.0 flags. Ex: –overwrite positional arugments. Ex: outfile.txt 100 in any combination. The idea is to use this a base class to derive common parsers for different hal implementations (ie just hdf5 for the time being) since any tool using hal (ex halCons, halValidate, halAppendCactusSubtree will have many common options.
void hal::CLParser::addArgument | ( | const std::string & | name, |
const std::string & | description | ||
) |
Add a positional (mandatory) command line argument The argument is given as a value on the command line ie with no name or prefix or anything. There is no default value because it is mandaatory
name | Name of the argument description string |
|
inline |
Add an optional command line argument to the parser
name | Name of option: will take form of <prefix><name> |
description | Description of the option |
defaultValue | Default Value |
void hal::CLParser::addOptionFlag | ( | const std::string & | name, |
const std::string & | description, | ||
bool | defaultValue | ||
) |
Add an optional command line flag to the parser (ie no value taken)
name | Name of option: will take form of <prefix><name> |
description | Description of the option |
defaultValue | The value if the flag is not specifed. if the flag is provided than !defaultValue is set. |
|
inline |
Get value of option or flag or argument by name
|
inline |
Get the value of a positional argument
name | Name of argument to get |
bool hal::CLParser::getFlag | ( | const std::string & | name | ) | const |
Get the value of an option flag in the parsed arguments
name | Name of option |
|
inline |
Get the value of an option in the parsed arguments
name | Name of option |
bool hal::CLParser::hasArgument | ( | const std::string & | name | ) | const |
Check if argument exists in the parser
name | Name of option to check |
bool hal::CLParser::hasFlag | ( | const std::string & | name | ) | const |
Check if option flag exists in the parser
name | Name of option to check |
bool hal::CLParser::hasOption | ( | const std::string & | name | ) | const |
Check if option exists in the parser
name | Name of option to check |
|
virtual |
Parse the command line arguments, throwing exception on failure.
|
virtual |
Print the help screen to output stream
void hal::CLParser::setDescription | ( | const std::string & | description | ) |
Set global description of tool
void hal::CLParser::setExample | ( | const std::string & | example | ) |
Set an example
|
virtual |
Set the prefix string for an optional argument [Default = "--"]
prefix | The prefix string |