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,
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,
119 void AddOption(std::string *var,
const char *short_name,
120 const char *long_name,
const char *description,
121 bool required =
false)
123 options.Append(Option(
STD_STRING, var, short_name, long_name, description,
130 const char *long_name,
const char *description,
131 bool required =
false)
133 options.Append(Option(
ARRAY, var, short_name, long_name, description,
140 const char *long_name,
const char *description,
141 bool required =
false)
143 options.Append(Option(
VECTOR, var, short_name, long_name, description,
159 bool Good()
const {
return (error_type == 0); }
162 bool Help()
const {
return (error_type == 1); }
void ParseCheck(std::ostream &out=mfem::out)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void PrintHelp(std::ostream &out) const
Print the help message.
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(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 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.
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 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(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(Vector *var, const char *short_name, const char *long_name, const char *description, bool required=false)
OptionsParser(int argc_, char *argv_[])
Construct a command line option parser with 'argc_' and 'argv_'.
void PrintError(std::ostream &out) const
Print the error message.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...