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);
72 : argc(_argc), argv(_argv)
74 error_type = error_idx = 0;
76 void AddOption(
bool *var,
const char *enable_short_name,
77 const char *enable_long_name,
const char *disable_short_name,
78 const char *disable_long_name,
const char *description,
79 bool required =
false)
81 options.
Append(Option(
ENABLE, var, enable_short_name, enable_long_name,
82 description, required));
83 options.
Append(Option(
DISABLE, var, disable_short_name, disable_long_name,
84 description, required));
86 void AddOption(
int *var,
const char *short_name,
const char *long_name,
87 const char *description,
bool required =
false)
89 options.
Append(Option(
INT, var, short_name, long_name, description,
92 void AddOption(
double *var,
const char *short_name,
const char *long_name,
93 const char *description,
bool required =
false)
95 options.
Append(Option(
DOUBLE, var, short_name, long_name, description,
98 void AddOption(
const char **var,
const char *short_name,
99 const char *long_name,
const char *description,
100 bool required =
false)
102 options.
Append(Option(
STRING, var, short_name, long_name, description,
106 const char *long_name,
const char *description,
107 bool required =
false)
109 options.
Append(Option(
ARRAY, var, short_name, long_name, description,
113 const char *long_name,
const char *description,
114 bool required =
false)
116 options.
Append(Option(
VECTOR, var, short_name, long_name, description,
125 bool Good()
const {
return (error_type == 0); }
126 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...