All Classes Namespaces Functions Pages
hal::CLParser Class Reference

`#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

## Detailed Description

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.

## Member Function Documentation

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

Parameters

  name | Name of the argument description string

template<typename T >

void hal::CLParser::addOption | ( | const std::string & | name,
|  | const std::string & | descritpion,
|  | const T & | defaultValue
| ) |  |

inline

Add an optional command line argument to the parser

Parameters

  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)

Parameters

  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.

template<typename T >

T hal::CLParser::get | ( | const std::string & | name | ) | const

inline

Get value of option or flag or argument by name

template<typename T >

T hal::CLParser::getArgument | ( | const std::string & | name | ) | const

inline

Get the value of a positional argument

Parameters

  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

Parameters

  name | Name of option

template<typename T >

T hal::CLParser::getOption | ( | const std::string & | name | ) | const

inline

Get the value of an option in the parsed arguments

Parameters

  name | Name of option

bool hal::CLParser::hasArgument | ( | const std::string & | name | ) | const

Check if argument exists in the parser

Parameters

  name | Name of option to check

bool hal::CLParser::hasFlag | ( | const std::string & | name | ) | const

Check if option flag exists in the parser

Parameters

  name | Name of option to check

bool hal::CLParser::hasOption | ( | const std::string & | name | ) | const

Check if option exists in the parser

Parameters

  name | Name of option to check

virtual void hal::CLParser::parseOptions | ( | int | argc,
|  | char ** | argv
| ) |  |

virtual

Parse the command line arguments, throwing exception on failure.

virtual void hal::CLParser::printUsage | ( | std::ostream & | os | ) | const

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 void hal::CLParser::setOptionPrefix | ( | const std::string & | prefix | ) |

virtual

Set the prefix string for an optional argument [Default = "--"]

Parameters

  prefix | The prefix string

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

- inc/halCLParser.h