Trilinos_Util::CommandLineParser Class Reference

Trilinos_Util::CommandLineParser: A class for managing the input arguments and variables. More...

#include <Trilinos_Util_CommandLineParser.h>

Inheritance diagram for Trilinos_Util::CommandLineParser:

[legend]
Collaboration diagram for Trilinos_Util::CommandLineParser:
[legend]
List of all members.

Public Member Functions

Constructors/Destructor.
 CommandLineParser (int argc, char *argv[])
 Trilinos_Util_ShellOptions constructor using the options given at the shell line.
Query methods.
virtual string GetProgramName (void)
 Returns the name of the program as a C++ string.
virtual int GetIntShellVariable (const char *str)
 Returns the value of the environmenta variable str as an integer.
virtual double GetDoubleShellVariable (const char *str)
 Returns the value of the environmenta variable str as an double.
virtual string GetStringShellVariable (const char *str)
 Returns the value of the environmenta variable str as a C++ string.

Detailed Description

Trilinos_Util::CommandLineParser: A class for managing the input arguments and variables.

Using Trilinos_Util::CommandLineParser, it is easy to handle input line arguments and shell varibles. For instance, the user can write

 $ ./a.out -nx 10 -tol 1e-6 -solver=cg
 
and then easily retrive the value of nx, tol, and solver.

A simple code using this class is as follows:

 int main(int argc, char *argv[])
  {

   Trilinos_Util::CommandLineParser CLP(argc,argv);
   int nx = CLP.GetInt("-nx", 123);
   int ny = CLP.GetInt("-ny", 145);
   double tol = CLP.GetDouble("-tol", 1e-12);
   string solver = CLP.GetInt("-solver");

   cout << "nx = " << nx << endl;
   cout << "ny = " << ny << " (default value)" << endl;
   cout << "tol = " << tol << endl;
   cout << "solver = " << solver << endl;

   return 0;
   
 }
 

Each line option can have a value or not. For options with a value, the user can specify this values as follows. Let -tolerance be the name of the option and 1e-12 its value. Both choices are valid:

Options are indentified with one or more dashes (`-'). Each option cannot have more than one value.

Note that the user can specify some values without giving them a name. This can be done as follows:

  $ ./a.out value1 value2 value 3 -nx 10 -tol 1e-6 -solver=cg
  
Here, valueX, (X=1,...,9) is stored in the database entry ARGV_X.

To use this class, the user has to build the database using the argc,argv input arguments. Then, to retrive the option value, the user has to use one of the following functions:

If option name is not found in the database, a value of 0, 0.0 or an empty string is returned. If needed, the user can also specify a default value to return when the option name is not found in the database. Method HaveOption can be used to query the database for an option.

The user can modify the database as well, using

(GetInt, GetDouble, GetString, Set and Add are derived from the base class, Trilinos_Util_Map).

Finally, the user can retrive the integer, double or string value of a shell environmental variable using:

Date:
Albuquerque, 19-Jan-04
Author:
Marzio Sala, SNL 9214


Constructor & Destructor Documentation

Trilinos_Util::CommandLineParser::CommandLineParser int  argc,
char *  argv[]
 

Trilinos_Util_ShellOptions constructor using the options given at the shell line.


Member Function Documentation

double Trilinos_Util::CommandLineParser::GetDoubleShellVariable const char *  str  )  [virtual]
 

Returns the value of the environmenta variable str as an double.

This methods returns the value of the environmenta variable str. If the variable does not exists, returns 0.0.

int Trilinos_Util::CommandLineParser::GetIntShellVariable const char *  str  )  [virtual]
 

Returns the value of the environmenta variable str as an integer.

This methods returns the value of the environmental variable str. If the variable does not exists, returns 0.

string Trilinos_Util::CommandLineParser::GetProgramName void   )  [virtual]
 

Returns the name of the program as a C++ string.

string Trilinos_Util::CommandLineParser::GetStringShellVariable const char *  str  )  [virtual]
 

Returns the value of the environmenta variable str as a C++ string.

This methods returns the value of the environmenta variable str. If the variable does not exists, returns "".


The documentation for this class was generated from the following files:
Generated on Thu Sep 18 12:38:13 2008 for TriUtils by doxygen 1.3.9.1