TriUtils  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members
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:
Inheritance graph
[legend]
Collaboration diagram for Trilinos_Util::CommandLineParser:
Collaboration graph
[legend]

Public Member Functions

 CommandLineParser (int argc, char *argv[])
 Trilinos_Util_ShellOptions constructor using the options given at the shell line. More...
 
virtual std::string GetProgramName (void)
 Returns the name of the program as a C++ std::string. More...
 
virtual int GetIntShellVariable (const char *str)
 Returns the value of the environmenta variable str as an integer. More...
 
virtual double GetDoubleShellVariable (const char *str)
 Returns the value of the environmenta variable str as an double. More...
 
virtual std::string GetStringShellVariable (const char *str)
 Returns the value of the environmenta variable str as a C++ std::string. More...
 
- Public Member Functions inherited from Trilinos_Util_Map
 Trilinos_Util_Map ()
 
virtual ~Trilinos_Util_Map ()
 
virtual int Get (const std::string input, const int def_value)
 Gets the value of the specified option as an integer. If not found, returns the specified default value. More...
 
virtual double Get (const std::string input, const double def_value)
 Gets the value of the specified option as a double. If not found, returns the specified default value. More...
 
virtual std::string Get (const std::string input, const std::string def_value)
 Gets the value of the specified option as a std::string. If not found, returns the specified default value. More...
 
virtual bool Set (const std::string input, const char *value)
 Modify the value of a database entry. More...
 
virtual bool Set (const std::string input, const std::string value)
 
virtual bool Set (const std::string input, const int value)
 
virtual bool Set (const std::string input, const double value)
 
virtual bool Add (const std::string input, const std::string value)
 Add an entry to the databse. More...
 
bool SetLabel (std::string Label)
 
std::string GetLabel (std::string)
 
virtual bool Has (const std::string input)
 Check wheter an option is in the database or not. More...
 
virtual void ShowAll () const
 Show all the databse entries. More...
 
virtual void ShowReallyAll () const
 Show all the databse entries, including entries beginning with "_". More...
 
virtual void Reset (void)
 

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 variables. 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);
  std::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 std::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 std::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++ std::string.

string Trilinos_Util::CommandLineParser::GetStringShellVariable ( const char *  str)
virtual

Returns the value of the environmenta variable str as a C++ std::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: