claw::arguments_table Class Reference

A class to manage the arguments of your program, with automatic management of short/long arguments and help message. More...

`#include <arguments_table.hpp>`

## Public Member Functions

| arguments_table (const std::string &prog_name)
| Constructor. More...
| arguments_table (int &argc, char **&argv)
| Constructor. More...
void | add (const std::string &short_name, const std::string &long_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
| Add an argument in the table. More...
void | add_long (const std::string &long_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
| Add an argument in the table. More...
void | add_short (const std::string &short_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
| Add an argument in the table. More...
void | parse (int &argc, char **&argv)
| Parse the command line arguments. More...
void | help (const std::string &free_args="") const
| Print some help about the arguments. More...
bool | required_fields_are_set () const
| Tell if all arguments not marqued as "optional" have been specified in the command line. More...
bool | has_value (const std::string &arg_name) const
| Tell if an argument has a value. More...
bool | only_integer_values (const std::string &arg_name) const
| Tell if only integer values are associated to an argument. More...
bool | only_real_values (const std::string &arg_name) const
| Tell if only real values are associated to an argument. More...
const std::string & | get_program_name () const
| Get the name of the program.
bool | get_bool (const std::string &arg_name) const
| Get the boolean state of an argument. More...
int | get_integer (const std::string &arg_name) const
| Get the integer value of an argument. More...
double | get_real (const std::string &arg_name) const
| Get the real value of an argument. More...
const std::string & | get_string (const std::string &arg_name) const
| Get the string value of an argument. More...
std::list< int > | get_all_of_integer (const std::string &arg_name) const
| Get all integer values of an argument. More...
std::list< double > | get_all_of_real (const std::string &arg_name) const
| Get all real values of an argument. More...
std::list< std::string > | get_all_of_string (const std::string &arg_name) const
| Get all string values of an argument. More...
void | add_argument (const std::string &arg)
| Add an argument in our list. More...

## Detailed Description

A class to manage the arguments of your program, with automatic management of short/long arguments and help message.

Remarks
  None of those methods is allowed to use claw::logger because when we are processing the arguments, we are at the really begining of the program and claw::logger is probably not initialised.

Author
  Julien Jorge

Definition at line 48 of file arguments_table.hpp.

## Constructor & Destructor Documentation

## arguments_table() [1/2]

claw::arguments_table::arguments_table | ( | const std::string & | prog_name | ) |

explicit

Constructor.

Parameters

  prog_name | Force the name of the program.

Definition at line 132 of file arguments_table.cpp.

## arguments_table() [2/2]

claw::arguments_table::arguments_table | ( | int & | argc,
|  | char **& | argv
| ) |  |

Constructor.

Parameters

  argc | Number of arguments.
  argv | Arguments.

All supported arguments will be removed from argv.

Definition at line 146 of file arguments_table.cpp.

## Member Function Documentation

## add()

void claw::arguments_table::add | ( | const std::string & | short_name,
|  | const std::string & | long_name,
|  | const std::string & | help_msg = `""`,
|  | bool | optional = `false`,
|  | const std::string & | val_name = `""`
| ) |  |

Add an argument in the table.

Parameters

  short_name | The short name of the argument.
  long_name | The long name of the argument.
  help_msg | A description of the argument.
  optional | Tell if the argument is optional.
  val_name | The type of the value needed for this argument.

Definition at line 161 of file arguments_table.cpp.

## add_argument()

void claw::arguments_table::add_argument | ( | const std::string & | arg | ) |

Add an argument in our list.

You can use this method to set default values to the parameters of your program, before calling parse.

Parameters

  arg | The argument to add.

Precondition
  (arg != "--") && (arg[0] == '-')

Definition at line 550 of file arguments_table.cpp.

References claw::arguments::add_argument().

## add_long()

void claw::arguments_table::add_long | ( | const std::string & | long_name,
|  | const std::string & | help_msg = `""`,
|  | bool | optional = `false`,
|  | const std::string & | val_name = `""`
| ) |  |

Add an argument in the table.

Parameters

  long_name | The long name of the argument.
  help_msg | A description of the argument.
  optional | Tell if the argument is optional.
  val_name | The type of the value needed for this argument.

Definition at line 180 of file arguments_table.cpp.

Referenced by claw::application::application().

## add_short()

void claw::arguments_table::add_short | ( | const std::string & | short_name,
|  | const std::string & | help_msg = `""`,
|  | bool | optional = `false`,
|  | const std::string & | val_name = `""`
| ) |  |

Add an argument in the table.

Parameters

  short_name | The short name of the argument.
  help_msg | A description of the argument.
  optional | Tell if the argument is optional.
  val_name | The type of the value needed for this argument.

Definition at line 197 of file arguments_table.cpp.

## get_all_of_integer()

std::list< int > claw::arguments_table::get_all_of_integer | ( | const std::string & | arg_name | ) | const

Get all integer values of an argument.

Parameters

  arg_name | The name of the argument to get.

Definition at line 471 of file arguments_table.cpp.

References claw::arguments::get_all_of_integer().

## get_all_of_real()

std::list< double > claw::arguments_table::get_all_of_real | ( | const std::string & | arg_name | ) | const

Get all real values of an argument.

Parameters

  arg_name | The name of the argument to get.

Definition at line 496 of file arguments_table.cpp.

References claw::arguments::get_all_of_real().

## get_all_of_string()

std::list< std::string > claw::arguments_table::get_all_of_string | ( | const std::string & | arg_name | ) | const

Get all string values of an argument.

Parameters

  arg_name | The name of the argument to get.

Definition at line 521 of file arguments_table.cpp.

References claw::arguments::get_all_of_string().

## get_bool()

bool claw::arguments_table::get_bool | ( | const std::string & | arg_name | ) | const

Get the boolean state of an argument.

Parameters

  arg_name | The name of the argument to find.

Definition at line 395 of file arguments_table.cpp.

References claw::arguments::get_bool().

Referenced by claw::application::application().

## get_integer()

int claw::arguments_table::get_integer | ( | const std::string & | arg_name | ) | const

Get the integer value of an argument.

Parameters

  arg_name | The name of the argument to find.

Precondition
  has_value(arg_name)

Definition at line 410 of file arguments_table.cpp.

References CLAW_PRECOND, claw::arguments::get_integer(), claw::arguments::has_value(), and has_value().

Referenced by claw::application::application().

## get_real()

double claw::arguments_table::get_real | ( | const std::string & | arg_name | ) | const

Get the real value of an argument.

Parameters

  arg_name | The name of the argument to find.

Precondition
  has_value(arg_name)

Definition at line 430 of file arguments_table.cpp.

References CLAW_PRECOND, claw::arguments::get_real(), claw::arguments::has_value(), and has_value().

## get_string()

const std::string & claw::arguments_table::get_string | ( | const std::string & | arg_name | ) | const

Get the string value of an argument.

Parameters

  arg_name | The name of the argument to find.

Precondition
  has_value(arg_name)

Definition at line 451 of file arguments_table.cpp.

References CLAW_PRECOND, claw::arguments::get_string(), claw::arguments::has_value(), and has_value().

Referenced by claw::application::application().

## has_value()

bool claw::arguments_table::has_value | ( | const std::string & | arg_name | ) | const

Tell if an argument has a value.

Parameters

  arg_name | The name of the argument to find.

Definition at line 310 of file arguments_table.cpp.

References claw::arguments::has_value().

Referenced by claw::application::application(), get_integer(), get_real(), get_string(), and required_fields_are_set().

## help()

void claw::arguments_table::help | ( | const std::string & | free_args = `""` | ) | const

Print some help about the arguments.

Parameters

  free_args | The arguments of your program that are not managed by claw::arguments_table.

The method prints the name of the program, required arguments, optional arguments and, then, free_args. Arguments are printed in short format when available. A line is then skipped and the long description of the arguments is printed.

Definition at line 239 of file arguments_table.cpp.

References claw::arguments::get_program_name().

## only_integer_values()

bool claw::arguments_table::only_integer_values | ( | const std::string & | arg_name | ) | const

Tell if only integer values are associated to an argument.

Parameters

  arg_name | The name of the argument to test.

Definition at line 333 of file arguments_table.cpp.

References claw::arguments::only_integer_values().

Referenced by claw::application::application().

## only_real_values()

bool claw::arguments_table::only_real_values | ( | const std::string & | arg_name | ) | const

Tell if only real values are associated to an argument.

Parameters

  arg_name | The name of the argument to test.

Definition at line 360 of file arguments_table.cpp.

References claw::arguments::only_real_values().

## parse()

void claw::arguments_table::parse | ( | int & | argc,
|  | char **& | argv
| ) |  |

Parse the command line arguments.

Parameters

  argc | Number of arguments.
  argv | Arguments.

All supported arguments will be removed from argv.

Definition at line 214 of file arguments_table.cpp.

References claw::arguments::parse().

Referenced by claw::application::application().

## required_fields_are_set()

bool claw::arguments_table::required_fields_are_set | ( |  | ) | const

Tell if all arguments not marqued as "optional" have been specified in the command line.

Remarks
  The method doesn't check the value of the arguments. If, for example, an argument needs to be an integer and the user use it as a boolean, the method will return true.

Definition at line 289 of file arguments_table.cpp.

References has_value().

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

- arguments_table.hpp
- code/arguments_table.cpp