Claw  1.7.3
Classes | Public Member Functions | List of all members
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>

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.

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

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

Constructor.

Parameters
prog_nameForce the name of the program.

Definition at line 132 of file arguments_table.cpp.

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

Member Function Documentation

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

Parameters
argThe argument to add.
Precondition
(arg != "&ndash;") && (arg[0] == '-')

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.

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

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

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

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

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

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

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

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.

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

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.

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

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.

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

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.

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

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

Parameters
argcNumber of arguments.
argvArguments.

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.

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.


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