Command line argument parser.
More...
|
| ArgParser (std::string bin="", std::string description="") |
| Constructor. More...
|
|
bool | parse (int argc, const char **argv, bool verbose_parsing=false) |
| Parse program arguments. More...
|
|
void | addArgument (const std::string &name, const std::string &description="", bool is_required=false) |
| Define program argument. More...
|
|
template<typename T > |
T | get (const std::string &name, const T &default_value={}) const |
| Get argument value. More...
|
|
template<typename T > |
std::vector< T > | getList (const std::string &name, const std::vector< T > &default_value={}) const |
| Get argument value as list. More...
|
|
bool | check (const std::string &name) const |
| Checks if an argument was given. More...
|
|
void | printHelp () const |
| Output help into stdout.
|
|
Command line argument parser.
- Example:
int main(int argc, char** argv) {
parser.addArgument("float_argument", "description");
parser.addArgument("int_argument", "description", true);
parser.parse(argc, argv);
parser.get<int>("int_argument", 0);
bool b = parser.check("float_argument");
}
Command line argument parser.
Definition: arg_parser.h:64
◆ ArgParser()
hermes::ArgParser::ArgParser |
( |
std::string |
bin = "" , |
|
|
std::string |
description = "" |
|
) |
| |
|
explicit |
Constructor.
- Parameters
-
bin | executable name |
description | program description |
◆ addArgument()
void hermes::ArgParser::addArgument |
( |
const std::string & |
name, |
|
|
const std::string & |
description = "" , |
|
|
bool |
is_required = false |
|
) |
| |
Define program argument.
- Parameters
-
name | |
description | |
is_required | |
◆ check()
bool hermes::ArgParser::check |
( |
const std::string & |
name | ) |
const |
Checks if an argument was given.
- Parameters
-
- Returns
- true if argument was given
◆ get()
template<typename T >
T hermes::ArgParser::get |
( |
const std::string & |
name, |
|
|
const T & |
default_value = {} |
|
) |
| const |
|
inline |
Get argument value.
- Template Parameters
-
- Parameters
-
- Returns
◆ getList()
template<typename T >
std::vector<T> hermes::ArgParser::getList |
( |
const std::string & |
name, |
|
|
const std::vector< T > & |
default_value = {} |
|
) |
| const |
|
inline |
Get argument value as list.
- Template Parameters
-
- Parameters
-
- Returns
◆ parse()
bool hermes::ArgParser::parse |
( |
int |
argc, |
|
|
const char ** |
argv, |
|
|
bool |
verbose_parsing = false |
|
) |
| |
Parse program arguments.
- Parameters
-
argc | |
argv | |
verbose_parsing | |
The documentation for this class was generated from the following files: