claw::arguments Class Reference

A class to manage the arguments of your program. More...

`#include <arguments.hpp>`

## Public Member Functions

| arguments ()
| Constructor.
| arguments (const std::string &prog_name)
| Constructor. More...
| arguments (int &argc, char **&argv)
| Constructor. More...
| arguments (int &argc, char **&argv, const claw::math::ordered_set< std::string > &allowed)
| Constructor. More...
void | parse (int &argc, char **&argv)
| Parse arguments. More...
void | parse (int &argc, char **&argv, const claw::math::ordered_set< std::string > &allowed)
| Parse arguments. More...
bool | has_value (const std::string &arg_name) const
| Tell if a value is associated to an argument. 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.

This class will handle all arguments of type -l[=val] or –long[=val].

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 50 of file arguments.hpp.

## Constructor & Destructor Documentation

## arguments() [1/3]

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

explicit

Constructor.

Parameters

  prog_name | Force the name of the program.

Definition at line 52 of file arguments.cpp.

## arguments() [2/3]

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

Constructor.

Parameters

  argc | Number of arguments.
  argv | Arguments.

You should construct an instance with the parameters given to your function main(). The constructor will remove all supported arguments from argv.

Definition at line 67 of file arguments.cpp.

References parse().

## arguments() [3/3]

claw::arguments::arguments | ( | int & | argc,
|  | char **& | argv,
|  | const claw::math::ordered_set< std::string > & | allowed
| ) |  |

Constructor.

Parameters

  argc | Number of arguments.
  argv | Arguments.
  allowed | The set of allowed arguments.

You should construct an instance with the parameters given to your function main(). The constructor will remove all supported arguments from argv.

Definition at line 82 of file arguments.cpp.

References parse().

## Member Function Documentation

## add_argument()

void claw::arguments::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_arguments.

Parameters

  arg | The argument to add.

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

Definition at line 325 of file arguments.cpp.

References CLAW_ASSERT, has_value(), and parse().

Referenced by claw::arguments_table::add_argument().

## get_all_of_integer()

std::list< int > claw::arguments::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 248 of file arguments.cpp.

Referenced by claw::arguments_table::get_all_of_integer().

## get_all_of_real()

std::list< double > claw::arguments::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 276 of file arguments.cpp.

Referenced by claw::arguments_table::get_all_of_real().

## get_all_of_string()

std::list< std::string > claw::arguments::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 304 of file arguments.cpp.

Referenced by claw::arguments_table::get_all_of_string().

## get_bool()

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

Get the boolean state of an argument.

Parameters

  arg_name | The name of the argument to get.

Definition at line 186 of file arguments.cpp.

Referenced by claw::arguments_table::get_bool().

## get_integer()

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

Get the integer value of an argument.

Parameters

  arg_name | The name of the argument to get.

Precondition
  has_value(arg_name)

Definition at line 197 of file arguments.cpp.

References CLAW_ASSERT, and has_value().

Referenced by claw::arguments_table::get_integer().

## get_real()

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

Get the real value of an argument.

Parameters

  arg_name | The name of the argument to get.

Precondition
  has_value(arg_name)

Definition at line 215 of file arguments.cpp.

References CLAW_ASSERT, and has_value().

Referenced by claw::arguments_table::get_real().

## get_string()

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

Get the string value of an argument.

Parameters

  arg_name | The name of the argument to get.

Precondition
  has_value(arg_name)

Definition at line 234 of file arguments.cpp.

References CLAW_ASSERT, and has_value().

Referenced by claw::arguments_table::get_string().

## has_value()

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

Tell if a value is associated to an argument.

Parameters

  arg_name | The name of the argument to test.

Definition at line 123 of file arguments.cpp.

Referenced by add_argument(), get_integer(), claw::arguments_table::get_integer(), get_real(), claw::arguments_table::get_real(), get_string(), claw::arguments_table::get_string(), and claw::arguments_table::has_value().

## only_integer_values()

bool claw::arguments::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 133 of file arguments.cpp.

Referenced by claw::arguments_table::only_integer_values().

## only_real_values()

bool claw::arguments::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 155 of file arguments.cpp.

Referenced by claw::arguments_table::only_real_values().

## parse() [1/2]

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

Parse arguments.

Parameters

  argc | Number of arguments.
  argv | Arguments.

All supported arguments will be removed from argv.

Definition at line 97 of file arguments.cpp.

Referenced by add_argument(), arguments(), parse(), and claw::arguments_table::parse().

## parse() [2/2]

void claw::arguments::parse | ( | int & | argc,
|  | char **& | argv,
|  | const claw::math::ordered_set< std::string > & | allowed
| ) |  |

Parse arguments.

Parameters

  argc | Number of arguments.
  argv | Arguments.
  allowed | The set of allowed arguments.

All supported arguments will be removed from argv.

Definition at line 112 of file arguments.cpp.

References parse().

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

- arguments.hpp
- code/arguments.cpp