MFEM  v4.6.0
Finite element discretization library
Classes | Public Types | Public Member Functions | List of all members
mfem::OptionsParser Class Reference

#include <optparser.hpp>

Public Types

enum  OptionType {
  INT, DOUBLE, STRING, STD_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 (std::string *var, const char *short_name, const char *long_name, const char *description, bool required=false)
 Add a string (std::string) 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

◆ OptionType

Enumerator
INT 
DOUBLE 
STRING 
STD_STRING 
ENABLE 
DISABLE 
ARRAY 
VECTOR 

Definition at line 34 of file optparser.hpp.

Constructor & Destructor Documentation

◆ OptionsParser()

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

◆ AddOption() [1/7]

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.

◆ AddOption() [2/7]

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.

◆ AddOption() [3/7]

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.

◆ AddOption() [4/7]

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.

◆ AddOption() [5/7]

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

Add a string (std::string) option and set 'var' to receive the value.

Definition at line 119 of file optparser.hpp.

◆ AddOption() [6/7]

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 129 of file optparser.hpp.

◆ AddOption() [7/7]

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 139 of file optparser.hpp.

◆ Good()

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

Return true if the command line options were parsed successfully.

Definition at line 159 of file optparser.hpp.

◆ Help()

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

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

Definition at line 162 of file optparser.hpp.

◆ Parse()

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 151 of file optparser.cpp.

◆ ParseCheck()

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 255 of file optparser.cpp.

◆ PrintError()

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

Print the error message.

Definition at line 362 of file optparser.cpp.

◆ PrintHelp()

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

Print the help message.

Definition at line 405 of file optparser.cpp.

◆ PrintOptions()

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

Print the options.

Definition at line 331 of file optparser.cpp.

◆ PrintUsage()

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

Print the usage message.

Definition at line 462 of file optparser.cpp.


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