tlx
|
base class of all options and parameters More...
#include <cmdline_parser.hpp>
Public Member Functions | |
Argument (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required) | |
contructor filling most attributes More... | |
virtual | ~Argument ()=default |
empty virtual destructor More... | |
virtual const char * | type_name () const =0 |
return formatted type name to user More... | |
virtual bool | process (int &argc, const char *const *&argv)=0 |
process one item from command line for this argument More... | |
virtual void | print_value (std::ostream &os) const =0 |
format value to ostream More... | |
std::string | param_text () const |
return 'longkey [keytype]' More... | |
std::string | option_text () const |
return '-s, –longkey [keytype]' More... | |
ArgumentBool (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, bool &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
"process" argument: just set to true, no argument is used. More... | |
void | print_value (std::ostream &os) const final |
ArgumentInt (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, int &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse signed integer using sscanf. More... | |
void | print_value (std::ostream &os) const final |
ArgumentUnsigned (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, unsigned int &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse unsigned integer using sscanf. More... | |
void | print_value (std::ostream &os) const final |
ArgumentSizeT (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, size_t &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse size_t using sscanf. More... | |
void | print_value (std::ostream &os) const final |
ArgumentFloat (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, float &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse unsigned integer using sscanf. More... | |
void | print_value (std::ostream &os) const final |
ArgumentDouble (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, double &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse unsigned integer using sscanf. More... | |
void | print_value (std::ostream &os) const final |
ArgumentBytes32 (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, uint32_t &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse byte size using SI/IEC parser. More... | |
void | print_value (std::ostream &os) const final |
ArgumentBytes64 (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, uint64_t &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
parse byte size using SI/IEC parser. More... | |
void | print_value (std::ostream &os) const final |
ArgumentString (char key, const std::string &longkey, const std::string &keytype, const std::string &desc, bool required, std::string &dest) | |
contructor filling most attributes More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
"process" string argument just by storing it. More... | |
void | print_value (std::ostream &os) const final |
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 More... | |
const char * | type_name () const final |
bool | process (int &argc, const char *const *&argv) final |
"process" string argument just by storing it in vector. More... | |
void | print_value (std::ostream &os) const final |
CmdlineParser () | |
Constructor. More... | |
~CmdlineParser () | |
Delete all added arguments. More... | |
void | set_description (const std::string &description) |
Set description of program, text will be wrapped. More... | |
void | set_author (const std::string &author) |
Set author of program, will be wrapped. More... | |
void | set_verbose_process (bool verbose_process) |
Set verbose processing of command line arguments. More... | |
void | print_usage (std::ostream &os) |
output nicely formatted usage information including description of all parameters and options. More... | |
void | print_usage () |
output to std::cout nicely formatted usage information including description of all parameters and options. More... | |
CmdlineParser & | sort () |
sort options by key (but not the positional parameters) More... | |
bool | process (int argc, const char *const *argv, std::ostream &os) |
parse command line options as specified by the options and parameters added. More... | |
bool | process (int argc, const char *const *argv) |
parse command line options as specified by the options and parameters added. More... | |
void | print_result (std::ostream &os) |
print nicely formatted result of processing More... | |
void | print_result () |
print nicely formatted result of processing to std::cout More... | |
Add Option with short -k, –longkey, and description. | |
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 More... | |
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. More... | |
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 More... | |
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 More... | |
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. More... | |
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 More... | |
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 More... | |
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 More... | |
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 More... | |
void | add_bytes (char key, const std::string &longkey, uint64_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option -key, –longkey and store to 64-bit dest More... | |
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 More... | |
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 More... | |
Add Option with –longkey and description. | |
void | add_bool (const std::string &longkey, bool &dest, const std::string &desc) |
add boolean option flag –longkey with description and store to dest More... | |
void | add_flag (const std::string &longkey, bool &dest, const std::string &desc) |
add boolean option flag –longkey with description and store to dest. More... | |
void | add_int (const std::string &longkey, int &dest, const std::string &desc) |
add signed integer option –longkey with description and store to dest More... | |
void | add_unsigned (const std::string &longkey, unsigned int &dest, const std::string &desc) |
add unsigned integer option –longkey with description and store to dest More... | |
void | add_uint (const std::string &longkey, unsigned int &dest, const std::string &desc) |
add unsigned integer option –longkey with description and store to dest. More... | |
void | add_size_t (const std::string &longkey, size_t &dest, const std::string &desc) |
add size_t option –longkey with description and store to dest More... | |
void | add_float (const std::string &longkey, float &dest, const std::string &desc) |
add float option –longkey with description and store to dest More... | |
void | add_double (const std::string &longkey, double &dest, const std::string &desc) |
add double option –longkey with description and store to dest More... | |
void | add_bytes (const std::string &longkey, uint32_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option –longkey and store to 32-bit dest More... | |
void | add_bytes (const std::string &longkey, uint64_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option –longkey and store to 64-bit dest More... | |
void | add_string (const std::string &longkey, std::string &dest, const std::string &desc) |
add string option –longkey and store to dest More... | |
void | add_stringlist (const std::string &longkey, std::vector< std::string > &dest, const std::string &desc) |
add string list option –longkey and store to dest More... | |
Add Option with short -k, –longkey, [keytype], and description. | |
void | add_bool (char key, const std::string &longkey, const std::string &keytype, bool &dest, const std::string &desc) |
add boolean option flag -key, –longkey [keytype] with description and store to dest More... | |
void | add_flag (char key, const std::string &longkey, const std::string &keytype, bool &dest, const std::string &desc) |
add boolean option flag -key, –longkey [keytype] with description and store to dest. More... | |
void | add_int (char key, const std::string &longkey, const std::string &keytype, int &dest, const std::string &desc) |
add signed integer option -key, –longkey [keytype] with description and store to dest More... | |
void | add_unsigned (char key, const std::string &longkey, const std::string &keytype, unsigned int &dest, const std::string &desc) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest More... | |
void | add_uint (char key, const std::string &longkey, const std::string &keytype, unsigned int &dest, const std::string &desc) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest. More... | |
void | add_size_t (char key, const std::string &longkey, const std::string &keytype, size_t &dest, const std::string &desc) |
add size_t option -key, –longkey [keytype] with description and store to dest More... | |
void | add_float (char key, const std::string &longkey, const std::string &keytype, float &dest, const std::string &desc) |
add float option -key, –longkey [keytype] with description and store to dest More... | |
void | add_double (char key, const std::string &longkey, const std::string &keytype, double &dest, const std::string &desc) |
add double option -key, –longkey [keytype] with description and store to dest More... | |
void | add_bytes (char key, const std::string &longkey, const std::string &keytype, uint32_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest More... | |
void | add_bytes (char key, const std::string &longkey, const std::string &keytype, uint64_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest More... | |
void | add_string (char key, const std::string &longkey, const std::string &keytype, std::string &dest, const std::string &desc) |
add string option -key, –longkey [keytype] and store to dest More... | |
void | add_stringlist (char key, const std::string &longkey, const std::string &keytype, std::vector< std::string > &dest, const std::string &desc) |
add string list option -key, –longkey [keytype] and store to dest More... | |
Add Required Parameter [name] with description. | |
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 More... | |
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 More... | |
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. More... | |
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 More... | |
void | add_param_float (const std::string &name, float &dest, const std::string &desc) |
add float parameter [name] with description and store to dest More... | |
void | add_param_double (const std::string &name, double &dest, const std::string &desc) |
add double parameter [name] with description and store to dest More... | |
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 More... | |
void | add_param_bytes (const std::string &name, uint64_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size parameter [name] with description and store to dest More... | |
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 More... | |
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. More... | |
Add Optional Parameter [name] with description. | |
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 More... | |
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 More... | |
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. More... | |
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 More... | |
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 More... | |
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 More... | |
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 More... | |
void | add_opt_param_bytes (const std::string &name, uint64_t &dest, const std::string &desc) |
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest More... | |
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 More... | |
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 More... | |
Static Public Member Functions | |
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. More... | |
Public Attributes | |
char | key_ |
single letter short option, or 0 is none More... | |
std::string | longkey_ |
long option key or name for parameters More... | |
std::string | keytype_ |
option type description, e.g. "<#>" to indicate numbers More... | |
std::string | desc_ |
longer description, which will be wrapped More... | |
bool | required_ |
required, process() fails if the option/parameter is not found. More... | |
bool | found_ |
found during processing of command line More... | |
bool | repeated_ |
repeated argument, i.e. std::vector<std::string> More... | |
Protected Attributes | |
bool & | dest_ |
reference to boolean to set to true More... | |
int & | dest_ |
unsigned int & | dest_ |
size_t & | dest_ |
float & | dest_ |
double & | dest_ |
uint32_t & | dest_ |
uint64_t & | dest_ |
std::string & | dest_ |
std::vector< std::string > & | dest_ |
Private Types | |
using | ArgumentList = std::vector< Argument * > |
option and parameter list type More... | |
Private Member Functions | |
void | calc_option_max (const Argument *arg) |
update maximum formatting width for new option More... | |
void | calc_param_max (const Argument *arg) |
update maximum formatting width for new parameter More... | |
void | print_option_error (int argc, const char *const *argv, const Argument *arg, std::ostream &os) |
print error about option. More... | |
void | print_param_error (int argc, const char *const *argv, const Argument *arg, std::ostream &os) |
print error about parameter. More... | |
Private Attributes | |
ArgumentList | option_list_ |
list of options available More... | |
ArgumentList | param_list_ |
list of parameters, both required and optional More... | |
size_t | option_max_width_ |
formatting width for options, '-s, –switch <#>' More... | |
size_t | param_max_width_ |
formatting width for parameters, 'param <#>' More... | |
const char * | program_name_ |
argv[0] for usage. More... | |
bool | verbose_process_ |
verbose processing of arguments More... | |
std::string | description_ |
user set description of program, will be wrapped More... | |
std::string | author_ |
user set author of program, will be wrapped More... | |
unsigned int | line_wrap_ |
set line wrap length More... | |
Static Private Attributes | |
static constexpr int | max_type_name_ |
maximum length of a type_name() result More... | |
base class of all options and parameters
Command line parser which automatically fills variables and prints nice usage messages.
specialization of argument for multiple string options or parameters
specialization of argument for string options or parameters
specialization of argument for SI/IEC suffixes byte size options or parameters
specialization of argument for double options or parameters
specialization of argument for float options or parameters
specialization of argument for size_t options or parameters
specialization of argument for unsigned integer options or parameters
specialization of argument for integer options or parameters
specialization of argument for boolean flags (can only be set to true).
This is a straightforward command line parser in C++, which will recognize short options -s, long options –long and parameters, both required and optional. It will automatically parse integers and byte sizes with SI/IEC suffixes (e.g. 1 GiB). It also works with lists of strings, e.g. multiple filenames.
When running the program above without arguments, it will print:
$ ./tlx_cmdline_parser_example Missing required argument for parameter 'filename' Usage: ./tlx_cmdline_parser_example [options] <filename> This may some day be a useful program, which solves many serious problems of the real world and achives global peace. Author: Timo Bingmann <tb@panthema.net> Parameters: filename A filename to process Options: -r, --rounds N Run N rounds of the experiment. -s, --size Number of bytes to process.
Nice output, notice the line wrapping of the description and formatting of parameters and arguments. These too are wrapped if the description is too long.
We now try to give the program some arguments:
$ ./tlx_cmdline_parser_example -s 2GiB -r 42 /dev/null Option -s, --size set to 2147483648. Option -r, --rounds N set to 42. Parameter filename set to "/dev/null". Command line parsed okay. Parameters: filename (string) "/dev/null" Options: -r, --rounds N (unsigned integer) 42 -s, --size (bytes) 2147483648
The output shows pretty much what happens. The command line parser is by default in a verbose mode outputting all arguments and values parsed. The debug summary shows to have values the corresponding variables were set.
One feature worth naming is that the parser also supports lists of strings, i.e. std::vector<std::string>
via CmdlineParser::add_param_stringlist() and similar.
Definition at line 40 of file cmdline_parser.cpp.
|
private |
option and parameter list type
Definition at line 111 of file cmdline_parser.hpp.
|
virtualdefault |
empty virtual destructor
CmdlineParser | ( | ) |
Constructor.
Definition at line 498 of file cmdline_parser.cpp.
~CmdlineParser | ( | ) |
Delete all added arguments.
Definition at line 500 of file cmdline_parser.cpp.
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
Definition at line 620 of file cmdline_parser.cpp.
void add_bool | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey [keytype] with description and store to dest
Definition at line 524 of file cmdline_parser.cpp.
void add_bool | ( | const std::string & | longkey, |
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag –longkey with description and store to dest
Definition at line 683 of file cmdline_parser.cpp.
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest
Definition at line 584 of file cmdline_parser.cpp.
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest
Definition at line 592 of file cmdline_parser.cpp.
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
Definition at line 660 of file cmdline_parser.cpp.
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey and store to 64-bit dest
Definition at line 665 of file cmdline_parser.cpp.
void add_bytes | ( | const std::string & | longkey, |
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option –longkey and store to 32-bit dest
Definition at line 723 of file cmdline_parser.cpp.
void add_bytes | ( | const std::string & | longkey, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option –longkey and store to 64-bit dest
Definition at line 728 of file cmdline_parser.cpp.
void add_double | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
double & | dest, | ||
const std::string & | desc | ||
) |
add double option -key, –longkey [keytype] with description and store to dest
Definition at line 576 of file cmdline_parser.cpp.
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
Definition at line 655 of file cmdline_parser.cpp.
void add_double | ( | const std::string & | longkey, |
double & | dest, | ||
const std::string & | desc | ||
) |
add double option –longkey with description and store to dest
Definition at line 718 of file cmdline_parser.cpp.
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.
identical to add_bool()
Definition at line 625 of file cmdline_parser.cpp.
void add_flag | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey [keytype] with description and store to dest.
identical to add_bool()
Definition at line 532 of file cmdline_parser.cpp.
void add_flag | ( | const std::string & | longkey, |
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag –longkey with description and store to dest.
identical to add_bool()
Definition at line 688 of file cmdline_parser.cpp.
void add_float | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
float & | dest, | ||
const std::string & | desc | ||
) |
add float option -key, –longkey [keytype] with description and store to dest
Definition at line 568 of file cmdline_parser.cpp.
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
Definition at line 650 of file cmdline_parser.cpp.
void add_float | ( | const std::string & | longkey, |
float & | dest, | ||
const std::string & | desc | ||
) |
add float option –longkey with description and store to dest
Definition at line 713 of file cmdline_parser.cpp.
void add_int | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer option -key, –longkey [keytype] with description and store to dest
Definition at line 538 of file cmdline_parser.cpp.
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
Definition at line 630 of file cmdline_parser.cpp.
void add_int | ( | const std::string & | longkey, |
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer option –longkey with description and store to dest
Definition at line 693 of file cmdline_parser.cpp.
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
Definition at line 849 of file cmdline_parser.cpp.
void add_opt_param_bytes | ( | const std::string & | name, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 856 of file cmdline_parser.cpp.
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
Definition at line 842 of file cmdline_parser.cpp.
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
Definition at line 836 of file cmdline_parser.cpp.
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
Definition at line 812 of file cmdline_parser.cpp.
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
Definition at line 830 of file cmdline_parser.cpp.
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
Definition at line 863 of file cmdline_parser.cpp.
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
Definition at line 870 of file cmdline_parser.cpp.
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.
identical to add_unsigned()
Definition at line 825 of file cmdline_parser.cpp.
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
Definition at line 818 of file cmdline_parser.cpp.
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
Definition at line 782 of file cmdline_parser.cpp.
void add_param_bytes | ( | const std::string & | name, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 789 of file cmdline_parser.cpp.
void add_param_double | ( | const std::string & | name, |
double & | dest, | ||
const std::string & | desc | ||
) |
add double parameter [name] with description and store to dest
Definition at line 776 of file cmdline_parser.cpp.
void add_param_float | ( | const std::string & | name, |
float & | dest, | ||
const std::string & | desc | ||
) |
add float parameter [name] with description and store to dest
Definition at line 770 of file cmdline_parser.cpp.
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
Definition at line 746 of file cmdline_parser.cpp.
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
Definition at line 764 of file cmdline_parser.cpp.
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
Definition at line 796 of file cmdline_parser.cpp.
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.
Definition at line 802 of file cmdline_parser.cpp.
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.
identical to add_unsigned()
Definition at line 759 of file cmdline_parser.cpp.
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
Definition at line 752 of file cmdline_parser.cpp.
void add_size_t | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t option -key, –longkey [keytype] with description and store to dest
Definition at line 560 of file cmdline_parser.cpp.
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
Definition at line 645 of file cmdline_parser.cpp.
void add_size_t | ( | const std::string & | longkey, |
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t option –longkey with description and store to dest
Definition at line 708 of file cmdline_parser.cpp.
void add_string | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string option -key, –longkey [keytype] and store to dest
Definition at line 600 of file cmdline_parser.cpp.
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
Definition at line 670 of file cmdline_parser.cpp.
void add_string | ( | const std::string & | longkey, |
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string option –longkey and store to dest
Definition at line 733 of file cmdline_parser.cpp.
void add_stringlist | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list option -key, –longkey [keytype] and store to dest
Definition at line 608 of file cmdline_parser.cpp.
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
Definition at line 675 of file cmdline_parser.cpp.
void add_stringlist | ( | const std::string & | longkey, |
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list option –longkey and store to dest
Definition at line 738 of file cmdline_parser.cpp.
void add_uint | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest.
identical to add_unsigned()
Definition at line 554 of file cmdline_parser.cpp.
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.
identical to add_unsigned()
Definition at line 640 of file cmdline_parser.cpp.
void add_uint | ( | const std::string & | longkey, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option –longkey with description and store to dest.
identical to add_unsigned()
Definition at line 703 of file cmdline_parser.cpp.
void add_unsigned | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest
Definition at line 546 of file cmdline_parser.cpp.
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
Definition at line 635 of file cmdline_parser.cpp.
void add_unsigned | ( | const std::string & | longkey, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option –longkey with description and store to dest
Definition at line 698 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 68 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 113 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 317 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 352 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 282 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 249 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 141 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 213 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 384 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 414 of file cmdline_parser.cpp.
|
inline |
contructor filling most attributes
Definition at line 177 of file cmdline_parser.cpp.
|
private |
update maximum formatting width for new option
Definition at line 445 of file cmdline_parser.cpp.
|
private |
update maximum formatting width for new parameter
Definition at line 450 of file cmdline_parser.cpp.
|
inline |
return '-s, –longkey [keytype]'
Definition at line 95 of file cmdline_parser.cpp.
|
static |
Wrap a long string at spaces into lines.
Prefix is added unconditionally to each line. Lines are wrapped after wraplen characters if possible.
Definition at line 457 of file cmdline_parser.cpp.
|
inline |
return 'longkey [keytype]'
Definition at line 86 of file cmdline_parser.cpp.
|
private |
print error about option.
Definition at line 950 of file cmdline_parser.cpp.
|
private |
print error about parameter.
Definition at line 963 of file cmdline_parser.cpp.
void print_result | ( | ) |
print nicely formatted result of processing to std::cout
Definition at line 1168 of file cmdline_parser.cpp.
void print_result | ( | std::ostream & | os | ) |
print nicely formatted result of processing
Definition at line 1122 of file cmdline_parser.cpp.
void print_usage | ( | ) |
output to std::cout nicely formatted usage information including description of all parameters and options.
Definition at line 946 of file cmdline_parser.cpp.
void print_usage | ( | std::ostream & | os | ) |
output nicely formatted usage information including description of all parameters and options.
Definition at line 888 of file cmdline_parser.cpp.
|
pure virtual |
format value to ostream
|
inlinefinal |
Definition at line 127 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 165 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 201 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 237 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 271 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 304 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 340 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 372 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 400 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 432 of file cmdline_parser.cpp.
|
inlinefinal |
"process" argument: just set to true, no argument is used.
Definition at line 121 of file cmdline_parser.cpp.
|
inlinefinal |
parse signed integer using sscanf.
Definition at line 149 of file cmdline_parser.cpp.
|
inlinefinal |
parse unsigned integer using sscanf.
Definition at line 185 of file cmdline_parser.cpp.
|
inlinefinal |
parse size_t using sscanf.
Definition at line 221 of file cmdline_parser.cpp.
|
inlinefinal |
parse unsigned integer using sscanf.
Definition at line 257 of file cmdline_parser.cpp.
|
inlinefinal |
parse unsigned integer using sscanf.
Definition at line 290 of file cmdline_parser.cpp.
|
inlinefinal |
parse byte size using SI/IEC parser.
Definition at line 325 of file cmdline_parser.cpp.
|
inlinefinal |
parse byte size using SI/IEC parser.
Definition at line 360 of file cmdline_parser.cpp.
|
inlinefinal |
"process" string argument just by storing it.
Definition at line 392 of file cmdline_parser.cpp.
|
inlinefinal |
"process" string argument just by storing it in vector.
Definition at line 424 of file cmdline_parser.cpp.
|
pure virtual |
process one item from command line for this argument
bool process | ( | int | argc, |
const char *const * | argv | ||
) |
parse command line options as specified by the options and parameters added.
Definition at line 1118 of file cmdline_parser.cpp.
bool process | ( | int | argc, |
const char *const * | argv, | ||
std::ostream & | os | ||
) |
parse command line options as specified by the options and parameters added.
Definition at line 976 of file cmdline_parser.cpp.
void set_author | ( | const std::string & | author | ) |
Set author of program, will be wrapped.
Definition at line 514 of file cmdline_parser.cpp.
void set_description | ( | const std::string & | description | ) |
Set description of program, text will be wrapped.
Definition at line 510 of file cmdline_parser.cpp.
void set_verbose_process | ( | bool | verbose_process | ) |
Set verbose processing of command line arguments.
Definition at line 518 of file cmdline_parser.cpp.
CmdlineParser & sort | ( | ) |
sort options by key (but not the positional parameters)
Definition at line 880 of file cmdline_parser.cpp.
|
pure virtual |
return formatted type name to user
|
inlinefinal |
Definition at line 118 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 146 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 182 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 218 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 254 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 287 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 322 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 357 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 389 of file cmdline_parser.cpp.
|
inlinefinal |
Definition at line 421 of file cmdline_parser.cpp.
|
private |
user set author of program, will be wrapped
Definition at line 132 of file cmdline_parser.hpp.
std::string desc_ |
longer description, which will be wrapped
Definition at line 58 of file cmdline_parser.cpp.
|
private |
user set description of program, will be wrapped
Definition at line 130 of file cmdline_parser.hpp.
|
protected |
reference to boolean to set to true
Definition at line 109 of file cmdline_parser.cpp.
|
protected |
Definition at line 137 of file cmdline_parser.cpp.
|
protected |
Definition at line 173 of file cmdline_parser.cpp.
|
protected |
Definition at line 209 of file cmdline_parser.cpp.
|
protected |
Definition at line 245 of file cmdline_parser.cpp.
|
protected |
Definition at line 278 of file cmdline_parser.cpp.
|
protected |
Definition at line 313 of file cmdline_parser.cpp.
|
protected |
Definition at line 348 of file cmdline_parser.cpp.
|
protected |
Definition at line 380 of file cmdline_parser.cpp.
|
protected |
Definition at line 410 of file cmdline_parser.cpp.
bool found_ |
found during processing of command line
Definition at line 62 of file cmdline_parser.cpp.
char key_ |
single letter short option, or 0 is none
Definition at line 52 of file cmdline_parser.cpp.
std::string keytype_ |
option type description, e.g. "<#>" to indicate numbers
Definition at line 56 of file cmdline_parser.cpp.
|
private |
set line wrap length
Definition at line 135 of file cmdline_parser.hpp.
std::string longkey_ |
long option key or name for parameters
Definition at line 54 of file cmdline_parser.cpp.
|
staticconstexprprivate |
maximum length of a type_name() result
Definition at line 138 of file cmdline_parser.hpp.
|
private |
list of options available
Definition at line 114 of file cmdline_parser.hpp.
|
private |
formatting width for options, '-s, –switch <#>'
Definition at line 119 of file cmdline_parser.hpp.
|
private |
list of parameters, both required and optional
Definition at line 116 of file cmdline_parser.hpp.
|
private |
formatting width for parameters, 'param <#>'
Definition at line 121 of file cmdline_parser.hpp.
|
private |
argv[0] for usage.
Definition at line 124 of file cmdline_parser.hpp.
bool repeated_ |
repeated argument, i.e. std::vector<std::string>
Definition at line 64 of file cmdline_parser.cpp.
bool required_ |
required, process() fails if the option/parameter is not found.
Definition at line 60 of file cmdline_parser.cpp.
|
private |
verbose processing of arguments
Definition at line 127 of file cmdline_parser.hpp.