MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Classes | Public Types | Public Member Functions | List of all members
mfem::OptionsParser Class Reference

#include <optparser.hpp>

Public Types

enum  OptionType {
  INT, DOUBLE, STRING, ENABLE,
  DISABLE, ARRAY, VECTOR
}
 

Public Member Functions

 OptionsParser (int argc_, char *argv_[])
 Construct a command line option parser with 'argc_' and 'argv_'. More...
 
void AddOption (bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
 Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool to true/false respectively. More...
 
void AddOption (int *var, const char *short_name, const char *long_name, const char *description, bool required=false)
 Add an integer option and set 'var' to receive the value. More...
 
void AddOption (double *var, const char *short_name, const char *long_name, const char *description, bool required=false)
 Add a double option and set 'var' to receive the value. More...
 
void AddOption (const char **var, const char *short_name, const char *long_name, const char *description, bool required=false)
 Add a string (char*) option and set 'var' to receive the value. More...
 
void AddOption (Array< int > *var, const char *short_name, const char *long_name, const char *description, bool required=false)
 
void AddOption (Vector *var, const char *short_name, const char *long_name, const char *description, bool required=false)
 
void Parse ()
 Parse the command-line options. Note that this function expects all the options provided through the command line to have a corresponding AddOption. In particular, this function cannot be used for partial parsing. More...
 
void ParseCheck (std::ostream &out=mfem::out)
 
bool Good () const
 Return true if the command line options were parsed successfully. More...
 
bool Help () const
 Return true if we are flagged to print the help message. More...
 
void PrintOptions (std::ostream &out) const
 Print the options. More...
 
void PrintError (std::ostream &out) const
 Print the error message. More...
 
void PrintHelp (std::ostream &out) const
 Print the help message. More...
 
void PrintUsage (std::ostream &out) const
 Print the usage message. More...
 

Detailed Description

Class for parsing command-line options.

The class is initialized with argc and argv, and new options are added with the AddOption method. Currently options of type bool, int, double, char*, mfem::Array<int>, and mfem::Vector are supported.

See the MFEM examples for sample use.

Definition at line 31 of file optparser.hpp.

Member Enumeration Documentation

Enumerator
INT 
DOUBLE 
STRING 
ENABLE 
DISABLE 
ARRAY 
VECTOR 

Definition at line 34 of file optparser.hpp.

Constructor & Destructor Documentation

mfem::OptionsParser::OptionsParser ( int  argc_,
char *  argv_[] 
)
inline

Construct a command line option parser with 'argc_' and 'argv_'.

Definition at line 73 of file optparser.hpp.

Member Function Documentation

void mfem::OptionsParser::AddOption ( bool *  var,
const char *  enable_short_name,
const char *  enable_long_name,
const char *  disable_short_name,
const char *  disable_long_name,
const char *  description,
bool  required = false 
)
inline

Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool to true/false respectively.

Definition at line 82 of file optparser.hpp.

void mfem::OptionsParser::AddOption ( int *  var,
const char *  short_name,
const char *  long_name,
const char *  description,
bool  required = false 
)
inline

Add an integer option and set 'var' to receive the value.

Definition at line 94 of file optparser.hpp.

void mfem::OptionsParser::AddOption ( double *  var,
const char *  short_name,
const char *  long_name,
const char *  description,
bool  required = false 
)
inline

Add a double option and set 'var' to receive the value.

Definition at line 102 of file optparser.hpp.

void mfem::OptionsParser::AddOption ( const char **  var,
const char *  short_name,
const char *  long_name,
const char *  description,
bool  required = false 
)
inline

Add a string (char*) option and set 'var' to receive the value.

Definition at line 110 of file optparser.hpp.

void mfem::OptionsParser::AddOption ( Array< int > *  var,
const char *  short_name,
const char *  long_name,
const char *  description,
bool  required = false 
)
inline

Add an integer array (separated by spaces) option and set 'var' to receive the values.

Definition at line 120 of file optparser.hpp.

void mfem::OptionsParser::AddOption ( Vector var,
const char *  short_name,
const char *  long_name,
const char *  description,
bool  required = false 
)
inline

Add a vector (doubles separated by spaces) option and set 'var' to receive the values.

Definition at line 130 of file optparser.hpp.

bool mfem::OptionsParser::Good ( ) const
inline

Return true if the command line options were parsed successfully.

Definition at line 150 of file optparser.hpp.

bool mfem::OptionsParser::Help ( ) const
inline

Return true if we are flagged to print the help message.

Definition at line 153 of file optparser.hpp.

void mfem::OptionsParser::Parse ( )

Parse the command-line options. Note that this function expects all the options provided through the command line to have a corresponding AddOption. In particular, this function cannot be used for partial parsing.

Definition at line 150 of file optparser.cpp.

void mfem::OptionsParser::ParseCheck ( std::ostream &  out = mfem::out)

Parse the command line options, and exit with an error if the options cannot be parsed successfully. The selected options are printed to the given stream (defaulting to mfem::out).

Definition at line 251 of file optparser.cpp.

void mfem::OptionsParser::PrintError ( std::ostream &  out) const

Print the error message.

Definition at line 358 of file optparser.cpp.

void mfem::OptionsParser::PrintHelp ( std::ostream &  out) const

Print the help message.

Definition at line 401 of file optparser.cpp.

void mfem::OptionsParser::PrintOptions ( std::ostream &  out) const

Print the options.

Definition at line 327 of file optparser.cpp.

void mfem::OptionsParser::PrintUsage ( std::ostream &  out) const

Print the usage message.

Definition at line 457 of file optparser.cpp.


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