tlx
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CmdlineParser Class Reference

Command line parser which automatically fills variables and prints nice usage messages. More...

#include <cmdline_parser.hpp>

Classes

struct  Argument
 base class of all options and parameters More...
 
struct  ArgumentBool
 specialization of argument for boolean flags (can only be set to true). More...
 
struct  ArgumentBytes32
 specialization of argument for SI/IEC suffixes byte size options or parameters More...
 
struct  ArgumentBytes64
 specialization of argument for SI/IEC suffixes byte size options or parameters More...
 
struct  ArgumentDouble
 specialization of argument for double options or parameters More...
 
struct  ArgumentFloat
 specialization of argument for float options or parameters More...
 
struct  ArgumentInt
 specialization of argument for integer options or parameters More...
 
struct  ArgumentSizeT
 specialization of argument for size_t options or parameters More...
 
struct  ArgumentString
 specialization of argument for string options or parameters More...
 
struct  ArgumentStringlist
 specialization of argument for multiple string options or parameters More...
 
struct  ArgumentUnsigned
 specialization of argument for unsigned integer options or parameters More...
 

Public Member Functions

 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 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...
 
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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] 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 [keytype] and store to dest More...
 
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...
 
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...
 
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...
 
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...
 

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...
 

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...
 

Detailed Description

Command line parser which automatically fills variables and prints nice usage messages.

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.

#include <iostream>
#include <string>
int main(int argc, char* argv[]) {
// add description and author
cp.set_description("This may some day be a useful program, which solves "
"many serious problems of the real world and achives "
"global peace.");
cp.set_author("Timo Bingmann <tb@panthema.net>");
// add an unsigned integer option --rounds <N>
unsigned rounds = 0;
cp.add_unsigned('r', "rounds", "N", rounds,
"Run N rounds of the experiment.");
// add a byte size argument which the user can enter like '1gi'
uint64_t a_size = 0;
cp.add_bytes('s', "size", a_size,
"Number of bytes to process.");
// add a required parameter
std::string a_filename;
cp.add_param_string("filename", a_filename,
"A filename to process");
// process command line
if (!cp.process(argc, argv))
return -1; // some error occurred and help was always written to user.
std::cout << "Command line parsed okay." << std::endl;
// output for debugging
// do something useful
return 0;
}

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 77 of file cmdline_parser.hpp.

Member Typedef Documentation

using ArgumentList = std::vector<Argument*>
private

option and parameter list type

Definition at line 95 of file cmdline_parser.hpp.

Constructor & Destructor Documentation

Constructor.

Definition at line 446 of file cmdline_parser.cpp.

Delete all added arguments.

Definition at line 448 of file cmdline_parser.cpp.

Member Function Documentation

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 472 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 568 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 532 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 540 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 [keytype] and store to 32-bit dest

Definition at line 608 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 [keytype] and store to 64-bit dest

Definition at line 613 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 524 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 [keytype] with description and store to dest

Definition at line 603 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 480 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 573 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 516 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 [keytype] with description and store to dest

Definition at line 598 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 486 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 578 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 734 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 741 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 727 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 721 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 697 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 715 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 748 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

Warning
this parameter must be last, as it will gobble all non-option arguments!

Definition at line 755 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 710 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 703 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 667 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 674 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 661 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 655 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 631 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 649 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 681 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.

Warning
this parameter must be last, as it will gobble all non-option arguments!

Definition at line 687 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 644 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 637 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 508 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 [keytype] with description and store to dest

Definition at line 593 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 548 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 [keytype] and store to dest

Definition at line 618 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 556 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 [keytype] and store to dest

Definition at line 623 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 502 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 [keytype] with description and store to dest.

identical to add_unsigned()

Definition at line 588 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 494 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 [keytype] with description and store to dest

Definition at line 583 of file cmdline_parser.cpp.

void calc_option_max ( const Argument arg)
private

update maximum formatting width for new option

Definition at line 393 of file cmdline_parser.cpp.

void calc_param_max ( const Argument arg)
private

update maximum formatting width for new parameter

Definition at line 398 of file cmdline_parser.cpp.

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 
)
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 405 of file cmdline_parser.cpp.

void print_option_error ( int  argc,
const char *const *  argv,
const Argument arg,
std::ostream &  os 
)
private

print error about option.

Definition at line 827 of file cmdline_parser.cpp.

void print_param_error ( int  argc,
const char *const *  argv,
const Argument arg,
std::ostream &  os 
)
private

print error about parameter.

Definition at line 840 of file cmdline_parser.cpp.

void print_result ( std::ostream &  os)

print nicely formatted result of processing

Definition at line 999 of file cmdline_parser.cpp.

void print_result ( )

print nicely formatted result of processing to std::cout

Definition at line 1045 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 765 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 823 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.

Returns
true if command line is okay and all required parameters are present.

Definition at line 853 of file cmdline_parser.cpp.

bool process ( int  argc,
const char *const *  argv 
)

parse command line options as specified by the options and parameters added.

Returns
true if command line is okay and all required parameters are present.

Definition at line 995 of file cmdline_parser.cpp.

void set_author ( const std::string &  author)

Set author of program, will be wrapped.

Definition at line 462 of file cmdline_parser.cpp.

void set_description ( const std::string &  description)

Set description of program, text will be wrapped.

Definition at line 458 of file cmdline_parser.cpp.

void set_verbose_process ( bool  verbose_process)

Set verbose processing of command line arguments.

Definition at line 466 of file cmdline_parser.cpp.

Member Data Documentation

std::string author_
private

user set author of program, will be wrapped

Definition at line 116 of file cmdline_parser.hpp.

std::string description_
private

user set description of program, will be wrapped

Definition at line 114 of file cmdline_parser.hpp.

unsigned int line_wrap_
private

set line wrap length

Definition at line 119 of file cmdline_parser.hpp.

constexpr int max_type_name_
staticprivate

maximum length of a type_name() result

Definition at line 122 of file cmdline_parser.hpp.

ArgumentList option_list_
private

list of options available

Definition at line 98 of file cmdline_parser.hpp.

size_t option_max_width_
private

formatting width for options, '-s, –switch <#>'

Definition at line 103 of file cmdline_parser.hpp.

ArgumentList param_list_
private

list of parameters, both required and optional

Definition at line 100 of file cmdline_parser.hpp.

size_t param_max_width_
private

formatting width for parameters, 'param <#>'

Definition at line 105 of file cmdline_parser.hpp.

const char* program_name_
private

argv[0] for usage.

Definition at line 108 of file cmdline_parser.hpp.

bool verbose_process_
private

verbose processing of arguments

Definition at line 111 of file cmdline_parser.hpp.


The documentation for this class was generated from the following files: