11 #ifndef TLX_CMDLINE_PARSER_HEADER 12 #define TLX_CMDLINE_PARSER_HEADER 136 std::ostream& os,
const std::string& text,
137 size_t wraplen,
size_t indent_first = 0,
size_t indent_rest = 0,
138 size_t current = 0,
size_t indent_newline = 0);
163 void add_bool(
char key,
const std::string& longkey,
bool& dest,
164 const std::string& desc);
168 void add_flag(
char key,
const std::string& longkey,
bool& dest,
169 const std::string& desc);
173 void add_int(
char key,
const std::string& longkey,
int& dest,
174 const std::string& desc);
179 unsigned int& dest,
const std::string& desc);
183 void add_uint(
char key,
const std::string& longkey,
184 unsigned int& dest,
const std::string& desc);
187 void add_size_t(
char key,
const std::string& longkey,
188 size_t& dest,
const std::string& desc);
191 void add_float(
char key,
const std::string& longkey,
192 float& dest,
const std::string& desc);
195 void add_double(
char key,
const std::string& longkey,
196 double& dest,
const std::string& desc);
200 void add_bytes(
char key,
const std::string& longkey,
201 uint32_t& dest,
const std::string& desc);
205 void add_bytes(
char key,
const std::string& longkey,
206 uint64_t& dest,
const std::string& desc);
209 void add_string(
char key,
const std::string& longkey,
210 std::string& dest,
const std::string& desc);
214 char key,
const std::string& longkey,
215 std::vector<std::string>& dest,
const std::string& desc);
225 void add_bool(
const std::string& longkey,
bool& dest,
226 const std::string& desc);
230 void add_flag(
const std::string& longkey,
bool& dest,
231 const std::string& desc);
234 void add_int(
const std::string& longkey,
int& dest,
235 const std::string& desc);
239 unsigned int& dest,
const std::string& desc);
243 void add_uint(
const std::string& longkey,
244 unsigned int& dest,
const std::string& desc);
248 size_t& dest,
const std::string& desc);
251 void add_float(
const std::string& longkey,
252 float& dest,
const std::string& desc);
256 double& dest,
const std::string& desc);
259 void add_bytes(
const std::string& longkey,
260 uint32_t& dest,
const std::string& desc);
263 void add_bytes(
const std::string& longkey,
264 uint64_t& dest,
const std::string& desc);
268 std::string& dest,
const std::string& desc);
272 const std::string& longkey,
273 std::vector<std::string>& dest,
const std::string& desc);
285 char key,
const std::string& longkey,
286 const std::string& keytype,
bool& dest,
287 const std::string& desc);
292 char key,
const std::string& longkey,
293 const std::string& keytype,
bool& dest,
294 const std::string& desc);
299 char key,
const std::string& longkey,
300 const std::string& keytype,
int& dest,
301 const std::string& desc);
306 char key,
const std::string& longkey,
307 const std::string& keytype,
unsigned int& dest,
308 const std::string& desc);
313 char key,
const std::string& longkey,
314 const std::string& keytype,
unsigned int& dest,
315 const std::string& desc);
320 char key,
const std::string& longkey,
321 const std::string& keytype,
size_t& dest,
322 const std::string& desc);
327 char key,
const std::string& longkey,
328 const std::string& keytype,
float& dest,
329 const std::string& desc);
334 char key,
const std::string& longkey,
335 const std::string& keytype,
double& dest,
336 const std::string& desc);
341 char key,
const std::string& longkey,
342 const std::string& keytype, uint32_t& dest,
343 const std::string& desc);
348 char key,
const std::string& longkey,
349 const std::string& keytype, uint64_t& dest,
350 const std::string& desc);
354 char key,
const std::string& longkey,
355 const std::string& keytype, std::string& dest,
356 const std::string& desc);
360 char key,
const std::string& longkey,
361 const std::string& keytype, std::vector<std::string>& dest,
362 const std::string& desc);
373 const std::string& name,
int& dest,
const std::string& desc);
377 const std::string& name,
unsigned int& dest,
378 const std::string& desc);
383 const std::string& name,
unsigned int& dest,
384 const std::string& desc);
388 const std::string& name,
size_t& dest,
389 const std::string& desc);
393 const std::string& name,
float& dest,
394 const std::string& desc);
398 const std::string& name,
double& dest,
399 const std::string& desc);
404 const std::string& name, uint32_t& dest,
405 const std::string& desc);
410 const std::string& name, uint64_t& dest,
411 const std::string& desc);
415 const std::string& name, std::string& dest,
416 const std::string& desc);
422 const std::string& name, std::vector<std::string>& dest,
423 const std::string& desc);
435 const std::string& name,
int& dest,
const std::string& desc);
440 const std::string& name,
unsigned int& dest,
441 const std::string& desc);
446 const std::string& name,
unsigned int& dest,
447 const std::string& desc);
451 const std::string& name,
size_t& dest,
452 const std::string& desc);
456 const std::string& name,
float& dest,
457 const std::string& desc);
461 const std::string& name,
double& dest,
462 const std::string& desc);
467 const std::string& name, uint32_t& dest,
468 const std::string& desc);
473 const std::string& name, uint64_t& dest,
474 const std::string& desc);
478 const std::string& name, std::string& dest,
479 const std::string& desc);
485 const std::string& name, std::vector<std::string>& dest,
486 const std::string& desc);
503 const Argument* arg, std::ostream& os);
507 const Argument* arg, std::ostream& os);
518 int argc,
const char*
const* argv, std::ostream& os);
524 bool process(
int argc,
const char*
const* argv);
535 #endif // !TLX_CMDLINE_PARSER_HEADER void add_opt_param_bytes(const std::string &name, uint32_t &dest, const std::string &desc)
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest ...
void add_unsigned(char key, const std::string &longkey, unsigned int &dest, const std::string &desc)
add unsigned integer option -key, –longkey with description and store to dest
static void output_wrap(std::ostream &os, const std::string &text, size_t wraplen, size_t indent_first=0, size_t indent_rest=0, size_t current=0, size_t indent_newline=0)
Wrap a long string at spaces into lines.
void add_uint(char key, const std::string &longkey, unsigned int &dest, const std::string &desc)
add unsigned integer option -key, –longkey with description and store to dest.
CmdlineParser & sort()
sort options by key (but not the positional parameters)
void print_usage()
output to std::cout nicely formatted usage information including description of all parameters and op...
void add_param_double(const std::string &name, double &dest, const std::string &desc)
add double parameter [name] with description and store to dest
ArgumentList option_list_
list of options available
void add_param_int(const std::string &name, int &dest, const std::string &desc)
add signed integer parameter [name] with description and store to dest
void set_description(const std::string &description)
Set description of program, text will be wrapped.
~CmdlineParser()
Delete all added arguments.
void add_opt_param_double(const std::string &name, double &dest, const std::string &desc)
add optional double parameter [name] with description and store to dest
ArgumentUnsigned(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, unsigned int &dest)
contructor filling most attributes
void print_option_error(int argc, const char *const *argv, const Argument *arg, std::ostream &os)
print error about option.
ArgumentStringlist(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, std::vector< std::string > &dest)
contructor filling most attributes
void add_opt_param_string(const std::string &name, std::string &dest, const std::string &desc)
add optional string parameter [name] with description and store to dest
bool verbose_process_
verbose processing of arguments
void add_opt_param_uint(const std::string &name, unsigned int &dest, const std::string &desc)
add optional unsigned integer parameter [name] with description and store to dest.
void calc_option_max(const Argument *arg)
update maximum formatting width for new option
void add_param_size_t(const std::string &name, size_t &dest, const std::string &desc)
add size_t parameter [name] with description and store to dest
void add_size_t(char key, const std::string &longkey, size_t &dest, const std::string &desc)
add size_t option -key, –longkey with description and store to dest
void calc_param_max(const Argument *arg)
update maximum formatting width for new parameter
void add_opt_param_unsigned(const std::string &name, unsigned int &dest, const std::string &desc)
add optional unsigned integer parameter [name] with description and store to dest ...
ArgumentInt(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, int &dest)
contructor filling most attributes
void print_result()
print nicely formatted result of processing to std::cout
ArgumentList param_list_
list of parameters, both required and optional
void add_param_bytes(const std::string &name, uint32_t &dest, const std::string &desc)
add SI/IEC suffixes byte size parameter [name] with description and store to dest ...
CmdlineParser()
Constructor.
void add_param_uint(const std::string &name, unsigned int &dest, const std::string &desc)
add unsigned integer parameter [name] with description and store to dest.
void add_bytes(char key, const std::string &longkey, uint32_t &dest, const std::string &desc)
add SI/IEC suffixes byte size option -key, –longkey and store to 32-bit dest
void add_opt_param_float(const std::string &name, float &dest, const std::string &desc)
add optional float parameter [name] with description and store to dest
ArgumentFloat(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, float &dest)
contructor filling most attributes
Argument(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required)
contructor filling most attributes
static constexpr int max_type_name_
maximum length of a type_name() result
void add_float(char key, const std::string &longkey, float &dest, const std::string &desc)
add float option -key, –longkey with description and store to dest
std::vector< Argument * > ArgumentList
option and parameter list type
const char * program_name_
argv[0] for usage.
ArgumentBytes64(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, uint64_t &dest)
contructor filling most attributes
std::string description_
user set description of program, will be wrapped
base class of all options and parameters
size_t param_max_width_
formatting width for parameters, 'param <#>'
void add_param_string(const std::string &name, std::string &dest, const std::string &desc)
add string parameter [name] with description and store to dest
void add_string(char key, const std::string &longkey, std::string &dest, const std::string &desc)
add string option -key, –longkey and store to dest
std::string author_
user set author of program, will be wrapped
unsigned int line_wrap_
set line wrap length
ArgumentString(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, std::string &dest)
contructor filling most attributes
void add_double(char key, const std::string &longkey, double &dest, const std::string &desc)
add double option -key, –longkey with description and store to dest
virtual bool process(int &argc, const char *const *&argv)=0
process one item from command line for this argument
void add_param_float(const std::string &name, float &dest, const std::string &desc)
add float parameter [name] with description and store to dest
void add_param_stringlist(const std::string &name, std::vector< std::string > &dest, const std::string &desc)
add string list parameter [name] with description and store to dest.
void add_opt_param_int(const std::string &name, int &dest, const std::string &desc)
add optional signed integer parameter [name] with description and store to dest
void set_verbose_process(bool verbose_process)
Set verbose processing of command line arguments.
ArgumentBool(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, bool &dest)
contructor filling most attributes
ArgumentBytes32(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, uint32_t &dest)
contructor filling most attributes
void add_bool(char key, const std::string &longkey, bool &dest, const std::string &desc)
add boolean option flag -key, –longkey with description and store to dest
size_t option_max_width_
formatting width for options, '-s, –switch <#>'
void add_stringlist(char key, const std::string &longkey, std::vector< std::string > &dest, const std::string &desc)
add string list option -key, –longkey and store to dest
void add_opt_param_stringlist(const std::string &name, std::vector< std::string > &dest, const std::string &desc)
add optional string parameter [name] with description and store to dest
ArgumentDouble(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, double &dest)
contructor filling most attributes
void add_opt_param_size_t(const std::string &name, size_t &dest, const std::string &desc)
add optional size_t parameter [name] with description and store to dest
void set_author(const std::string &author)
Set author of program, will be wrapped.
void add_flag(char key, const std::string &longkey, bool &dest, const std::string &desc)
add boolean option flag -key, –longkey with description and store to dest.
void add_int(char key, const std::string &longkey, int &dest, const std::string &desc)
add signed integer option -key, –longkey with description and store to dest
void add_param_unsigned(const std::string &name, unsigned int &dest, const std::string &desc)
add unsigned integer parameter [name] with description and store to dest
ArgumentSizeT(char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, size_t &dest)
contructor filling most attributes
void print_param_error(int argc, const char *const *argv, const Argument *arg, std::ostream &os)
print error about parameter.