claw 1.9.0
 
Loading...
Searching...
No Matches
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.
 
 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.
 

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_nameForce the name of the program.

Definition at line 142 of file arguments_table.cpp.

◆ arguments_table() [2/2]

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

Constructor.

Parameters
argcNumber of arguments.
argvArguments.

All supported arguments will be removed from argv.

Definition at line 153 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_nameThe short name of the argument.
long_nameThe long name of the argument.
help_msgA description of the argument.
optionalTell if the argument is optional.
val_nameThe type of the value needed for this argument.

Definition at line 165 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
argThe argument to add.
Precondition
(arg != "--") && (arg[0] == '-')

Definition at line 541 of file arguments_table.cpp.

◆ 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_nameThe long name of the argument.
help_msgA description of the argument.
optionalTell if the argument is optional.
val_nameThe type of the value needed for this argument.

Definition at line 183 of file arguments_table.cpp.

◆ 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_nameThe short name of the argument.
help_msgA description of the argument.
optionalTell if the argument is optional.
val_nameThe type of the value needed for this argument.

Definition at line 199 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_nameThe name of the argument to get.

Definition at line 465 of file arguments_table.cpp.

◆ 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_nameThe name of the argument to get.

Definition at line 489 of file arguments_table.cpp.

◆ 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_nameThe name of the argument to get.

Definition at line 513 of file arguments_table.cpp.

◆ get_bool()

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

Get the boolean state of an argument.

Parameters
arg_nameThe name of the argument to find.

Definition at line 393 of file arguments_table.cpp.

◆ get_integer()

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

Get the integer value of an argument.

Parameters
arg_nameThe name of the argument to find.
Precondition
has_value(arg_name)

Definition at line 407 of file arguments_table.cpp.

◆ get_program_name()

const std::string & claw::arguments_table::get_program_name ( ) const

Get the name of the program.

Definition at line 384 of file arguments_table.cpp.

◆ get_real()

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

Get the real value of an argument.

Parameters
arg_nameThe name of the argument to find.
Precondition
has_value(arg_name)

Definition at line 426 of file arguments_table.cpp.

◆ 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_nameThe name of the argument to find.
Precondition
has_value(arg_name)

Definition at line 446 of file arguments_table.cpp.

◆ has_value()

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

Tell if an argument has a value.

Parameters
arg_nameThe name of the argument to find.

Definition at line 313 of file arguments_table.cpp.

◆ help()

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

Print some help about the arguments.

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

◆ 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_nameThe name of the argument to test.

Definition at line 334 of file arguments_table.cpp.

◆ 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_nameThe name of the argument to test.

Definition at line 360 of file arguments_table.cpp.

◆ parse()

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

Parse the command line arguments.

Parameters
argcNumber of arguments.
argvArguments.

All supported arguments will be removed from argv.

Definition at line 215 of file arguments_table.cpp.

◆ 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 291 of file arguments_table.cpp.


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