12 #ifndef MFEM_OPTPARSER
13 #define MFEM_OPTPARSER
15 #include "../config/config.hpp"
41 const char *short_name;
42 const char *long_name;
43 const char *description;
48 Option(
OptionType type_,
void *var_ptr_,
const char *short_name_,
49 const char *long_name_,
const char *description_,
bool req)
50 : type(type_), var_ptr(var_ptr_), short_name(short_name_),
51 long_name(long_name_), description(description_), required(req) { }
56 Array<Option> options;
57 Array<int> option_check;
66 int error_type, error_idx;
68 static void WriteValue(
const Option &opt, std::ostream &
out);
74 : argc(argc_), argv(argv_)
76 error_type = error_idx = 0;
82 void AddOption(
bool *var,
const char *enable_short_name,
83 const char *enable_long_name,
const char *disable_short_name,
84 const char *disable_long_name,
const char *description,
85 bool required =
false)
87 options.
Append(Option(
ENABLE, var, enable_short_name, enable_long_name,
88 description, required));
89 options.
Append(Option(
DISABLE, var, disable_short_name, disable_long_name,
90 description, required));
94 void AddOption(
int *var,
const char *short_name,
const char *long_name,
95 const char *description,
bool required =
false)
97 options.
Append(Option(
INT, var, short_name, long_name, description,
102 void AddOption(
double *var,
const char *short_name,
const char *long_name,
103 const char *description,
bool required =
false)
105 options.
Append(Option(
DOUBLE, var, short_name, long_name, description,
110 void AddOption(
const char **var,
const char *short_name,
111 const char *long_name,
const char *description,
112 bool required =
false)
114 options.
Append(Option(
STRING, var, short_name, long_name, description,
121 const char *long_name,
const char *description,
122 bool required =
false)
124 options.
Append(Option(
ARRAY, var, short_name, long_name, description,
131 const char *long_name,
const char *description,
132 bool required =
false)
134 options.
Append(Option(
VECTOR, var, short_name, long_name, description,
150 bool Good()
const {
return (error_type == 0); }
153 bool Help()
const {
return (error_type == 1); }
bool Help() const
Return true if we are flagged to print the help message.
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 PrintHelp(std::ostream &out) const
Print the help message.
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.
OptionsParser(int argc_, char *argv_[])
Construct a command line option parser with 'argc_' and 'argv_'.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
int Append(const T &el)
Append element 'el' to array, resize if necessary.
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 PrintUsage(std::ostream &out) const
Print the usage message.
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...
void PrintError(std::ostream &out) const
Print the error message.
void PrintOptions(std::ostream &out) const
Print the options.
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.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
void ParseCheck(std::ostream &out=mfem::out)
bool Good() const
Return true if the command line options were parsed successfully.