Teuchos::CommandLineProcessor Class Reference

Class that helps parse command line input arguments from (argc,argv[]) and set options. More...

#include <Teuchos_CommandLineProcessor.hpp>

Collaboration diagram for Teuchos::CommandLineProcessor:

[legend]
List of all members.

Public Types

enum  EParseCommandLineReturn { PARSE_SUCCESSFUL = 0, PARSE_HELP_PRINTED = 1, PARSE_UNRECOGNIZED_OPTION = -1 }
 Return value for CommandLineProcessor::parse(). More...
enum  EOptType {
  OPT_NONE, OPT_BOOL_TRUE, OPT_BOOL_FALSE, OPT_INT,
  OPT_DOUBLE, OPT_STRING
}

Public Member Functions

Constructors
 CommandLineProcessor (bool throwExceptions=true, bool recogniseAllOptions=true)
 Default Constructor.
Set up options
void setOption (const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
 Set a boolean option.
void setOption (const char option_name[], int *option_val, const char documentation[]=NULL)
 Set an integer option.
void setOption (const char option_name[], double *option_val, const char documentation[]=NULL)
 Set a floating-point option.
void setOption (const char option_name[], std::string *option_val, const char documentation[]=NULL)
 Set a string option.
Parse methods
EParseCommandLineReturn parse (int argc, char *argv[], std::ostream *errout=&std::cerr) const
 Parse a command line.
Behavior modes
void throwExceptions (const bool &throwExceptions)
 Set if an exception is thrown, there is a parse error, or help is printed.
const bool & throwExceptions () const
 Return true if an exception is thrown, there is a parse error, or help is printed.
void recogniseAllOptions (const bool &recogniseAllOptions)
 Set if all options must be recognized or not.
const bool & recogniseAllOptions () const
 Return true if all options are being recognized by the parser.

Private Types

typedef Teuchos::map< std::string,
opt_val_val_t
options_list_t
typedef std::vector< opt_doc_toptions_documentation_list_t

Private Member Functions

bool get_opt_val (const char str[], std::string *opt_name, std::string *opt_val_str) const
void print_help_msg (int argc, char *argv[], std::ostream *errout) const
std::string opt_type_str (EOptType) const
void print_bad_opt (int argv_i, char *argv[], std::ostream *errout) const

Private Attributes

bool throwExceptions_
bool recogniseAllOptions_
options_list_t options_list_
options_documentation_list_t options_documentation_list_

Detailed Description

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.

Examples:

CommandLineProcessor/cxx_main.cpp.

Definition at line 62 of file Teuchos_CommandLineProcessor.hpp.


Member Typedef Documentation

typedef Teuchos::map<std::string,opt_val_val_t> Teuchos::CommandLineProcessor::options_list_t [private]
 

Definition at line 265 of file Teuchos_CommandLineProcessor.hpp.

typedef std::vector<opt_doc_t> Teuchos::CommandLineProcessor::options_documentation_list_t [private]
 

Definition at line 285 of file Teuchos_CommandLineProcessor.hpp.


Member Enumeration Documentation

enum Teuchos::CommandLineProcessor::EParseCommandLineReturn
 

Return value for CommandLineProcessor::parse().

Enumeration values:
PARSE_SUCCESSFUL  Parsing the command line was successful.
PARSE_HELP_PRINTED  The help statement was printed for the command line parser.
PARSE_UNRECOGNIZED_OPTION  The command line parser encountered an unrecognized option.

Definition at line 68 of file Teuchos_CommandLineProcessor.hpp.

enum Teuchos::CommandLineProcessor::EOptType
 

Enumeration values:
OPT_NONE 
OPT_BOOL_TRUE 
OPT_BOOL_FALSE 
OPT_INT 
OPT_DOUBLE 
OPT_STRING 

Definition at line 241 of file Teuchos_CommandLineProcessor.hpp.


Constructor & Destructor Documentation

Teuchos::CommandLineProcessor::CommandLineProcessor bool  throwExceptions = true,
bool  recogniseAllOptions = true
 

Default Constructor.

Parameters:
throwExceptions [in] If true then this->parse() with throw exceptions instead of returning !=PARSE_SUCCESSFUL.
recogniseAllOptions [in] If true then this->parse() with simply ignore options that it does not recognize.

Definition at line 61 of file Teuchos_CommandLineProcessor.cpp.


Member Function Documentation

void Teuchos::CommandLineProcessor::setOption const char  option_true[],
const char  option_false[],
bool *  option_val,
const char  documentation[] = NULL
 

Set a boolean option.

Parameters:
option_true [in] (null terminated string) If this option is found then *option_val = true will be set.
option_false [in] (null terminated 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 string gives the documentation for the option.
Examples:
CommandLineProcessor/cxx_main.cpp.

Definition at line 71 of file Teuchos_CommandLineProcessor.cpp.

void Teuchos::CommandLineProcessor::setOption const char  option_name[],
int *  option_val,
const char  documentation[] = NULL
 

Set an integer option.

Parameters:
option_name [in] (null terminated 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 string gives the documentation for the option.

Definition at line 87 of file Teuchos_CommandLineProcessor.cpp.

void Teuchos::CommandLineProcessor::setOption const char  option_name[],
double *  option_val,
const char  documentation[] = NULL
 

Set a floating-point option.

Parameters:
option_name [in] (null terminated 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 string gives the documentation for the option.

Definition at line 100 of file Teuchos_CommandLineProcessor.cpp.

void Teuchos::CommandLineProcessor::setOption const char  option_name[],
std::string *  option_val,
const char  documentation[] = NULL
 

Set a string option.

Parameters:
option_name [in] (null terminated 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 string gives the documentation for the option.

Definition at line 113 of file Teuchos_CommandLineProcessor.cpp.

CommandLineProcessor::EParseCommandLineReturn Teuchos::CommandLineProcessor::parse int  argc,
char *  argv[],
std::ostream *  errout = &std::cerr
const
 

Parse a command line.

Parameters:
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:
  • If an unrecognized option if found
  • Else if the option --help is found
  • Else
    • This method will return PARSE_SUCCESSFUL
Examples:
CommandLineProcessor/cxx_main.cpp.

Definition at line 129 of file Teuchos_CommandLineProcessor.cpp.

void Teuchos::CommandLineProcessor::throwExceptions const bool &  throwExceptions  )  [inline]
 

Set if an exception is thrown, there is a parse error, or help is printed.

Examples:
CommandLineProcessor/cxx_main.cpp.

Definition at line 210 of file Teuchos_CommandLineProcessor.hpp.

const bool& Teuchos::CommandLineProcessor::throwExceptions  )  const [inline]
 

Return true if an exception is thrown, there is a parse error, or help is printed.

Definition at line 213 of file Teuchos_CommandLineProcessor.hpp.

void Teuchos::CommandLineProcessor::recogniseAllOptions const bool &  recogniseAllOptions  )  [inline]
 

Set if all options must be recognized or not.

Examples:
CommandLineProcessor/cxx_main.cpp.

Definition at line 216 of file Teuchos_CommandLineProcessor.hpp.

const bool& Teuchos::CommandLineProcessor::recogniseAllOptions  )  const [inline]
 

Return true if all options are being recognized by the parser.

Definition at line 219 of file Teuchos_CommandLineProcessor.hpp.

bool Teuchos::CommandLineProcessor::get_opt_val const char  str[],
std::string *  opt_name,
std::string *  opt_val_str
const [private]
 

Definition at line 209 of file Teuchos_CommandLineProcessor.cpp.

void Teuchos::CommandLineProcessor::print_help_msg int  argc,
char *  argv[],
std::ostream *  errout
const [private]
 

Definition at line 235 of file Teuchos_CommandLineProcessor.cpp.

std::string Teuchos::CommandLineProcessor::opt_type_str EOptType   )  const [inline, private]
 

Definition at line 330 of file Teuchos_CommandLineProcessor.hpp.

void Teuchos::CommandLineProcessor::print_bad_opt int  argv_i,
char *  argv[],
std::ostream *  errout
const [private]
 

Definition at line 347 of file Teuchos_CommandLineProcessor.cpp.


Member Data Documentation

bool Teuchos::CommandLineProcessor::throwExceptions_ [private]
 

Definition at line 290 of file Teuchos_CommandLineProcessor.hpp.

bool Teuchos::CommandLineProcessor::recogniseAllOptions_ [private]
 

Definition at line 291 of file Teuchos_CommandLineProcessor.hpp.

options_list_t Teuchos::CommandLineProcessor::options_list_ [private]
 

Definition at line 292 of file Teuchos_CommandLineProcessor.hpp.

options_documentation_list_t Teuchos::CommandLineProcessor::options_documentation_list_ [private]
 

Definition at line 293 of file Teuchos_CommandLineProcessor.hpp.


The documentation for this class was generated from the following files:
Generated on Thu Sep 18 12:42:52 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1