MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
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_'.
 
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.
 
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.
 
void AddOption (real_t *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.
 
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.
 
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.
 
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.
 
void ParseCheck (std::ostream &out=mfem::out)
 
bool Good () const
 Return true if the command line options were parsed successfully.
 
bool Help () const
 Return true if we are flagged to print the help message.
 
void PrintOptions (std::ostream &out) const
 Print the options.
 
void PrintError (std::ostream &out) const
 Print the error message.
 
void PrintHelp (std::ostream &out) const
 Print the help message.
 
void PrintUsage (std::ostream &out) const
 Print the usage message.
 

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 ( 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() [2/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() [3/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() [4/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() [5/7]

void mfem::OptionsParser::AddOption ( real_t * 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() [6/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() [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: