Hermes
hermes::ArgParser Class Reference

Command line argument parser. More...

Public Member Functions

 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 >
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.
 

Detailed Description

Command line argument parser.

  • Example:
    int main(int argc, char** argv) {
    hermes::ArgParser parser("my program", "description");
    // define a simple float argument
    parser.addArgument("float_argument", "description");
    // an required argument
    parser.addArgument("int_argument", "description", true);
    // parse arguments
    parser.parse(argc, argv);
    // access argument value with default value
    parser.get<int>("int_argument", 0);
    // check if argument was given
    bool b = parser.check("float_argument");
    }
    Command line argument parser.
    Definition: arg_parser.h:64

Constructor & Destructor Documentation

◆ ArgParser()

hermes::ArgParser::ArgParser ( std::string  bin = "",
std::string  description = "" 
)
explicit

Constructor.

Parameters
binexecutable name
descriptionprogram description

Member Function Documentation

◆ 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
nameargument's name
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
T
Parameters
name
default_value
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
Tlist data type
Parameters
name
default_value
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: