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;
46 Option(
OptionType _type,
void *_var_ptr,
const char *_short_name,
47 const char *_long_name,
const char *_description,
bool req)
48 : type(_type), var_ptr(_var_ptr), short_name(_short_name),
49 long_name(_long_name), description(_description), required(req) { }
54 Array<Option> options;
55 Array<int> option_check;
64 int error_type, error_idx;
66 static void WriteValue(
const Option &opt, std::ostream &
out);
70 : argc(_argc), argv(_argv)
72 error_type = error_idx = 0;
74 void AddOption(
bool *var,
const char *enable_short_name,
75 const char *enable_long_name,
const char *disable_short_name,
76 const char *disable_long_name,
const char *description,
77 bool required =
false)
79 options.
Append(Option(
ENABLE, var, enable_short_name, enable_long_name,
80 description, required));
81 options.
Append(Option(
DISABLE, var, disable_short_name, disable_long_name,
82 description, required));
84 void AddOption(
int *var,
const char *short_name,
const char *long_name,
85 const char *description,
bool required =
false)
87 options.
Append(Option(
INT, var, short_name, long_name, description,
90 void AddOption(
double *var,
const char *short_name,
const char *long_name,
91 const char *description,
bool required =
false)
93 options.
Append(Option(
DOUBLE, var, short_name, long_name, description,
96 void AddOption(
const char **var,
const char *short_name,
97 const char *long_name,
const char *description,
98 bool required =
false)
100 options.
Append(Option(
STRING, var, short_name, long_name, description,
104 const char *long_name,
const char *description,
105 bool required =
false)
107 options.
Append(Option(
ARRAY, var, short_name, long_name, description,
111 const char *long_name,
const char *description,
112 bool required =
false)
114 options.
Append(Option(
VECTOR, var, short_name, long_name, description,
120 bool Good()
const {
return (error_type == 0); }
121 bool Help()
const {
return (error_type == 1); }
void AddOption(int *var, const char *short_name, const char *long_name, const char *description, bool required=false)
void PrintHelp(std::ostream &out) const
void AddOption(const char **var, const char *short_name, const char *long_name, const char *description, bool required=false)
int Append(const T &el)
Append element 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
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)
void PrintError(std::ostream &out) const
void PrintOptions(std::ostream &out) const
void AddOption(double *var, const char *short_name, const char *long_name, const char *description, bool required=false)
OptionsParser(int _argc, char *_argv[])
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...