Claw
1.7.3
|
A class to manage the arguments of your program, with automatic management of short/long arguments and help message. More...
#include <arguments_table.hpp>
Classes | |
class | argument_attributes |
This class manage the description of an argument. |
Public Member Functions | |
arguments_table (const std::string &prog_name) | |
Constructor. | |
arguments_table (int &argc, char **&argv) | |
Constructor. | |
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. | |
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. | |
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. | |
void | parse (int &argc, char **&argv) |
Parse the command line arguments. | |
void | help (const std::string &free_args="") const |
Print some help about the arguments. | |
bool | required_fields_are_set () const |
Tell if all arguments not marqued as "optional" have been specified in the command line. | |
bool | has_value (const std::string &arg_name) const |
Tell if an argument has a value. | |
bool | only_integer_values (const std::string &arg_name) const |
Tell if only integer values are associated to an argument. | |
bool | only_real_values (const std::string &arg_name) const |
Tell if only real values are associated to an argument. | |
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. | |
int | get_integer (const std::string &arg_name) const |
Get the integer value of an argument. | |
double | get_real (const std::string &arg_name) const |
Get the real value of an argument. | |
const std::string & | get_string (const std::string &arg_name) const |
Get the string value of an argument. | |
std::list< int > | get_all_of_integer (const std::string &arg_name) const |
Get all integer values of an argument. | |
std::list< double > | get_all_of_real (const std::string &arg_name) const |
Get all real values of an argument. | |
std::list< std::string > | get_all_of_string (const std::string &arg_name) const |
Get all string values of an argument. | |
void | add_argument (const std::string &arg) |
Add an argument in our list. |
A class to manage the arguments of your program, with automatic management of short/long arguments and help message.
Definition at line 48 of file arguments_table.hpp.
|
explicit |
Constructor.
prog_name | Force the name of the program. |
Definition at line 132 of file arguments_table.cpp.
claw::arguments_table::arguments_table | ( | int & | argc, |
char **& | argv | ||
) |
Constructor.
argc | Number of arguments. |
argv | Arguments. |
All supported arguments will be removed from argv.
Definition at line 146 of file arguments_table.cpp.
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.
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.
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.
arg | The argument to add. |
Definition at line 550 of file arguments_table.cpp.
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.
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().
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.
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.
std::list< int > claw::arguments_table::get_all_of_integer | ( | const std::string & | arg_name | ) | const |
Get all integer values of an argument.
arg_name | The name of the argument to get. |
Definition at line 471 of file arguments_table.cpp.
std::list< double > claw::arguments_table::get_all_of_real | ( | const std::string & | arg_name | ) | const |
Get all real values of an argument.
arg_name | The name of the argument to get. |
Definition at line 496 of file arguments_table.cpp.
std::list< std::string > claw::arguments_table::get_all_of_string | ( | const std::string & | arg_name | ) | const |
Get all string values of an argument.
arg_name | The name of the argument to get. |
Definition at line 521 of file arguments_table.cpp.
bool claw::arguments_table::get_bool | ( | const std::string & | arg_name | ) | const |
Get the boolean state of an argument.
arg_name | The name of the argument to find. |
Definition at line 395 of file arguments_table.cpp.
Referenced by claw::application::application().
int claw::arguments_table::get_integer | ( | const std::string & | arg_name | ) | const |
Get the integer value of an argument.
arg_name | The name of the argument to find. |
Definition at line 410 of file arguments_table.cpp.
References CLAW_PRECOND.
Referenced by claw::application::application().
double claw::arguments_table::get_real | ( | const std::string & | arg_name | ) | const |
Get the real value of an argument.
arg_name | The name of the argument to find. |
Definition at line 430 of file arguments_table.cpp.
References CLAW_PRECOND.
const std::string & claw::arguments_table::get_string | ( | const std::string & | arg_name | ) | const |
Get the string value of an argument.
arg_name | The name of the argument to find. |
Definition at line 451 of file arguments_table.cpp.
References CLAW_PRECOND.
Referenced by claw::application::application().
bool claw::arguments_table::has_value | ( | const std::string & | arg_name | ) | const |
Tell if an argument has a value.
arg_name | The name of the argument to find. |
Definition at line 310 of file arguments_table.cpp.
Referenced by claw::application::application().
void claw::arguments_table::help | ( | const std::string & | free_args = "" | ) | const |
Print some help about the arguments.
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.
bool claw::arguments_table::only_integer_values | ( | const std::string & | arg_name | ) | const |
Tell if only integer values are associated to an argument.
arg_name | The name of the argument to test. |
Definition at line 333 of file arguments_table.cpp.
Referenced by claw::application::application().
bool claw::arguments_table::only_real_values | ( | const std::string & | arg_name | ) | const |
Tell if only real values are associated to an argument.
arg_name | The name of the argument to test. |
Definition at line 360 of file arguments_table.cpp.
void claw::arguments_table::parse | ( | int & | argc, |
char **& | argv | ||
) |
Parse the command line arguments.
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::avl< K, Comp >::insert().
Referenced by claw::application::application().
bool claw::arguments_table::required_fields_are_set | ( | ) | const |
Tell if all arguments not marqued as "optional" have been specified in the command line.
Definition at line 289 of file arguments_table.cpp.