Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
Class that helps parse command line input arguments from (argc,argv[])
and set options.
More...
#include <Teuchos_CommandLineProcessor.hpp>
Classes | |
struct | enum_opt_data_t |
class | HelpPrinted |
Thrown if –help was specified and throwExceptions==true. More... | |
struct | opt_doc_t |
struct | opt_val_val_t |
class | ParseError |
Thrown if a parse std::exception occurs and throwExceptions==true. More... | |
class | TimeMonitorSurrogate |
Interface by which CommandLineProcessor may use TimeMonitor. More... | |
class | UnrecognizedOption |
Thrown if an unrecognized option was found and throwExceptions==true. More... | |
Public Types | |
enum | EOptType { OPT_NONE, OPT_BOOL_TRUE, OPT_BOOL_FALSE, OPT_INT, OPT_LONG_INT, OPT_SIZE_T, OPT_LONG_LONG_INT, OPT_DOUBLE, OPT_FLOAT, OPT_STRING, OPT_ENUM_INT } |
Static Public Member Functions | |
static void | setTimeMonitorSurrogate (const RCP< TimeMonitorSurrogate > &timeMonitorSurrogate) |
static RCP< TimeMonitorSurrogate > | getTimeMonitorSurrogate () |
Private Types | |
typedef Teuchos::map < std::string, opt_val_val_t > | options_list_t |
typedef std::vector< opt_doc_t > | options_documentation_list_t |
typedef std::vector < enum_opt_data_t > | enum_opt_data_list_t |
Private Member Functions | |
void | add_extra_output_setup_options () const |
void | setEnumOption (const char enum_option_name[], int *enum_option_val, const int num_enum_opt_values, const int enum_opt_values[], const char *const enum_opt_names[], const char documentation[], const bool required) |
bool | set_enum_value (int argv_i, char *argv[], const std::string &enum_opt_name, const int enum_id, const std::string &enum_str_val, std::ostream *errout) const |
void | print_enum_opt_names (const int enum_id, std::ostream &out) const |
std::string | enum_opt_default_val_name (const std::string &enum_name, const int enum_id, std::ostream *errout) const |
int | find_enum_opt_index (const std::string &enum_opt_name, const int opt_value, const enum_opt_data_t &enum_data, std::ostream *errout) const |
bool | get_opt_val (const char str[], std::string *opt_name, std::string *opt_val_str) const |
std::string | opt_type_str (EOptType) const |
void | print_bad_opt (int argv_i, char *argv[], std::ostream *errout) const |
Static Private Member Functions | |
static RCP < TimeMonitorSurrogate > & | getRawTimeMonitorSurrogate () |
Private Attributes | |
bool | throwExceptions_ |
bool | recogniseAllOptions_ |
bool | addOutputSetupOptions_ |
std::string | doc_string_ |
options_list_t | options_list_ |
options_documentation_list_t | options_documentation_list_ |
enum_opt_data_list_t | enum_opt_data_list_ |
bool | output_all_front_matter_ |
bool | output_show_line_prefix_ |
bool | output_show_tab_count_ |
bool | output_show_proc_rank_ |
int | output_to_root_rank_only_ |
bool | print_rcpnode_statistics_on_exit_ |
bool | show_timer_summary_on_exit_ |
bool | printed_timer_summary_ |
bool | added_extra_output_setup_options_ |
bool | in_add_extra_output_setup_options_ |
Static Private Attributes | |
static const bool | output_all_front_matter_default_ |
static const bool | output_show_line_prefix_default_ |
static const bool | output_show_tab_count_default_ |
static const bool | output_show_proc_rank_default_ |
static const int | output_to_root_rank_only_default_ |
static const bool | print_rcpnode_statistics_on_exit_default_ |
static const bool | show_timer_summary_on_exit_default_ |
Related Functions | |
(Note that these are not member functions.) | |
void | setVerbosityLevelOption (const std::string &optionName, EVerbosityLevel *verbLevel, const std::string &docString, CommandLineProcessor *clp, const bool required=false) |
Set a verbosity level parameter on a CommandLineProcessor object.. More... | |
Public types | |
enum | EParseCommandLineReturn { PARSE_SUCCESSFUL = 0, PARSE_HELP_PRINTED = 1, PARSE_UNRECOGNIZED_OPTION = 2, PARSE_ERROR = 3 } |
Return value for CommandLineProcessor::parse() . Note: These enums are all given non-negative values since they are designed to be returned from main(). More... | |
Constructors | |
CommandLineProcessor (bool throwExceptions=true, bool recogniseAllOptions=true, bool addOutputSetupOptions=false) | |
Default Constructor. More... | |
~CommandLineProcessor () | |
Destructor. More... | |
Behavior modes | |
void | throwExceptions (const bool &throwExceptions) |
Set if an std::exception is thrown, there is a parse error, or help is printed. More... | |
bool | throwExceptions () const |
Returns true if an std::exception is thrown, there is a parse error, or help is printed. More... | |
void | recogniseAllOptions (const bool &recogniseAllOptions) |
Set if all options must be recognized or not. More... | |
bool | recogniseAllOptions () const |
Returns true if all options must be recognized by the parser. More... | |
void | addOutputSetupOptions (const bool &addOutputSetupOptions) |
Set if options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStream() . More... | |
bool | addOutputSetupOptions () const |
Returns true options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStream() . More... | |
Set up options | |
void | setDocString (const char doc_string[]) |
Set a documentation sting for the entire program printed when –help is specified. More... | |
void | setOption (const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL) |
Set a boolean option. More... | |
void | setOption (const char option_name[], int *option_val, const char documentation[]=NULL, const bool required=false) |
Set an integer option. More... | |
void | setOption (const char option_name[], long int *option_val, const char documentation[]=NULL, const bool required=false) |
Set a long integer option. More... | |
void | setOption (const char option_name[], size_t *option_val, const char documentation[]=NULL, const bool required=false) |
Set a size_t option. More... | |
void | setOption (const char option_name[], long long int *option_val, const char documentation[]=NULL, const bool required=false) |
Set a long long integer option. More... | |
void | setOption (const char option_name[], double *option_val, const char documentation[]=NULL, const bool required=false) |
Set a floating-point option. More... | |
void | setOption (const char option_name[], float *option_val, const char documentation[]=NULL, const bool required=false) |
Set a floating-point option. More... | |
void | setOption (const char option_name[], std::string *option_val, const char documentation[]=NULL, const bool required=false) |
Set a std::string option. More... | |
template<class EType > | |
void | setOption (const char enum_option_name[], EType *enum_option_val, const int num_enum_opt_values, const EType enum_opt_values[], const char *const enum_opt_names[], const char documentation[]=nullptr, const bool required=false) |
Set an enumeration option (templated by enumeration type). More... | |
Parse | |
EParseCommandLineReturn | parse (int argc, char *argv[], std::ostream *errout=&std::cerr) const |
Parse a command line. More... | |
Miscellaneous | |
void | printHelpMessage (const char program_name[], std::ostream &out) const |
Print the help message. More... | |
void | printFinalTimerSummary (const Ptr< std::ostream > &out=null) |
Call to print timers so that they don't get printed in the destructor. More... | |
Class that helps parse command line input arguments from (argc,argv[])
and set options.
This class will process command-line arguments in the form of (argc,argv[])
and set user-defined options. This class can also work in a number of modes. This processor can require that all options be recognized or not.
This class object will also setup the behavior of Teuchos::VerboseObjectBase::getDefaultOStream()
if this->addOutputSetupOptions()==true
Warning, the option –show-timer-summary is only enabled if the subpackage TeuchosComm is enabled!
Definition at line 44 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 442 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 462 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 489 of file Teuchos_CommandLineProcessor.hpp.
Return value for CommandLineProcessor::parse()
. Note: These enums are all given non-negative values since they are designed to be returned from main().
Definition at line 66 of file Teuchos_CommandLineProcessor.hpp.
Enumerator | |
---|---|
OPT_NONE | |
OPT_BOOL_TRUE | |
OPT_BOOL_FALSE | |
OPT_INT | |
OPT_LONG_INT | |
OPT_SIZE_T | |
OPT_LONG_LONG_INT | |
OPT_DOUBLE | |
OPT_FLOAT | |
OPT_STRING | |
OPT_ENUM_INT |
Definition at line 407 of file Teuchos_CommandLineProcessor.hpp.
Teuchos::CommandLineProcessor::CommandLineProcessor | ( | bool | throwExceptions = true , |
bool | recogniseAllOptions = true , |
||
bool | addOutputSetupOptions = false |
||
) |
Default Constructor.
throwExceptions | [in] If true then this->parse() will throw exceptions instead of returning !=PARSE_SUCCESSFUL . |
recogniseAllOptions | [in] If true then this->parse() will return the appropriate error for any option it does not recognize. If false , then this->parse() will simply ignore options that it does not recognize. However, a warning will be printed for any unrecognized option, but no errors will be returned. |
addOutputSetupOptions | [in] If true then options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStream() . |
Definition at line 66 of file Teuchos_CommandLineProcessor.cpp.
Teuchos::CommandLineProcessor::~CommandLineProcessor | ( | ) |
Destructor.
Definition at line 87 of file Teuchos_CommandLineProcessor.cpp.
|
inline |
Set if an std::exception is thrown, there is a parse error, or help is printed.
Definition at line 661 of file Teuchos_CommandLineProcessor.hpp.
|
inline |
Returns true if an std::exception is thrown, there is a parse error, or help is printed.
Definition at line 666 of file Teuchos_CommandLineProcessor.hpp.
|
inline |
Set if all options must be recognized or not.
Definition at line 671 of file Teuchos_CommandLineProcessor.hpp.
|
inline |
Returns true if all options must be recognized by the parser.
Definition at line 676 of file Teuchos_CommandLineProcessor.hpp.
|
inline |
Set if options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStream()
.
Definition at line 681 of file Teuchos_CommandLineProcessor.hpp.
|
inline |
Returns true options will be automatically added to setup Teuchos::VerboseObjectBase::getDefaultOStream()
.
Definition at line 686 of file Teuchos_CommandLineProcessor.hpp.
void Teuchos::CommandLineProcessor::setDocString | ( | const char | doc_string[] | ) |
Set a documentation sting for the entire program printed when –help is specified.
Definition at line 96 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_true[], |
const char | option_false[], | ||
bool * | option_val, | ||
const char | documentation[] = NULL |
||
) |
Set a boolean option.
option_true | [in] (null terminated std::string) If this option is found then *option_val = true will be set. |
option_false | [in] (null terminated std::string) If this option is found then *option_val = false will be set. |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 102 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
int * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set an integer option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 122 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
long int * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a long integer option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 140 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
size_t * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a size_t option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 158 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
long long int * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a long long integer option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 175 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
double * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a floating-point option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 192 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
float * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a floating-point option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 209 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::setOption | ( | const char | option_name[], |
std::string * | option_val, | ||
const char | documentation[] = NULL , |
||
const bool | required = false |
||
) |
Set a std::string option.
option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
option_val | [in/out] On input, *option_val gives the default value of the option (used for printing in –help). On output, will be set according to (argc,argv[]) . |
documentation | [in] If !=NULL , then this null terminated std::string gives the documentation for the option. |
Definition at line 226 of file Teuchos_CommandLineProcessor.cpp.
|
inline |
Set an enumeration option (templated by enumeration type).
enum_option_name | [in] (null terminated std::string) The name of the option (without the leading '–' or trailing '='). |
enum_option_val | [in/out] On input, *enum_option_val gives the default value of the enumeration (used for printing in –help). After parse() finishes executing successfully, *enum_option_val will contain the user-selected value of the enumeration. |
num_enum_opt_values | [in] Gives the number of possible option values to select |
enum_opt_values | [in] Array (length num_enum_opt_values ) that gives the numeric values for each option. The values in this array are used to set the actual option *enum_option_val . |
enum_opt_names | [in] Array (length num_enum_opt_values ) that gives the char string names for each option. The strings in this function are what is used in the commandline. |
documentation | [in] If !=NULL , then this array of null-terminated char string gives the documentation for the option. |
Warning! Only use an enum
or int
for EType
. Using any other type for EType
could be trouble!
Definition at line 692 of file Teuchos_CommandLineProcessor.hpp.
CommandLineProcessor::EParseCommandLineReturn Teuchos::CommandLineProcessor::parse | ( | int | argc, |
char * | argv[], | ||
std::ostream * | errout = &std::cerr |
||
) | const |
Parse a command line.
argc | [in] number of entries in argv[] |
argv | [in/out] array (length argc) of command line arguments. argv[0] should be the name of the program on the shell as usual. |
errout | [out] If !=NULL then error and help messages are sent here. The default is set to &std::cerr . |
Postconditions:
this->recogniseAllOptions()==true
*errout
and parsing will stop as follows: this->throwExceptions()==true
UnrecognizedOption
std::exceptionPARSE_UNRECOGNIZED_OPTION
*errout
and parsing will continue–help
is found this->throwExceptions()==true
HelpPrinted
std::exceptionPARSE_HELP_PRINTED
PARSE_SUCCESSFUL
Note that if the option –pause-for-debugging
is present, then std::string Type 0 and press enter to continue :
will be printed to standard error (std::cerr
) and execution will be suspended until the user enters any non-null character(s). This option is designed to make it easier to attach a debugger, especially in a parallel MPI program. If HAVE_MPI is defined, then output/input is only performed with the process with rank 0 and then MPI calls insure that all processors wait (using MPI_Barrier(MPI_COMM_WORLD)
) until the user has entered something. This allows the user to attach a debugger to one or more parallel MPI processes and set breakpoints before execution resumes. Note that the stream *errout
is not used for this output/input but instead std::cerr
is directly used.
If Teuchos::VerboseObjectBase::getDefaultOStream().get()!=NULL
and this->addOutputSetupOptions()
, then any of the default setup options for Teuchos::VerboseObjectBase::getDefaultOStream()
that are set on the commandline will be set on Teuchos::VerboseObjectBase::getDefaultOStream()
.
Definition at line 248 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::printHelpMessage | ( | const char | program_name[], |
std::ostream & | out | ||
) | const |
Print the help message.
out | [in/out] The stream the documentation will be printed to. |
This will print a formatted set of documentation that shows what options are set, what their default values are and any user-supplied documentation about each option.
Definition at line 404 of file Teuchos_CommandLineProcessor.cpp.
void Teuchos::CommandLineProcessor::printFinalTimerSummary | ( | const Ptr< std::ostream > & | out = null | ) |
Call to print timers so that they don't get printed in the destructor.
Calling this function after the first call has no effect.
Definition at line 573 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 594 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 653 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 683 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 720 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 742 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 758 of file Teuchos_CommandLineProcessor.cpp.
|
private |
Definition at line 784 of file Teuchos_CommandLineProcessor.cpp.
|
inlineprivate |
Definition at line 723 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 810 of file Teuchos_CommandLineProcessor.cpp.
|
static |
Definition at line 832 of file Teuchos_CommandLineProcessor.cpp.
|
static |
Definition at line 840 of file Teuchos_CommandLineProcessor.cpp.
|
staticprivate |
Definition at line 847 of file Teuchos_CommandLineProcessor.cpp.
|
related |
Set a verbosity level parameter on a CommandLineProcessor object..
|
private |
Definition at line 494 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 495 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 496 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 497 of file Teuchos_CommandLineProcessor.hpp.
|
mutableprivate |
Definition at line 504 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 505 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 506 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 511 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 512 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 513 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 514 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 515 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 516 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 517 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 519 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 521 of file Teuchos_CommandLineProcessor.hpp.
|
private |
Definition at line 522 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 524 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 525 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 526 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 527 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 528 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 529 of file Teuchos_CommandLineProcessor.hpp.
|
staticprivate |
Definition at line 530 of file Teuchos_CommandLineProcessor.hpp.