geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
Classes | Public Member Functions | List of all members
geopm::OptionParser Class Reference

#include <OptionParser.hpp>

Public Member Functions

 OptionParser (const std::string &prog_name, std::ostream &std_out, std::ostream &err_out)
 
 OptionParser (const std::string &prog_name, std::ostream &std_out, std::ostream &err_out, const std::string &custom_help)
 
void add_option (const std::string &name, char short_form, const std::string &long_form, const std::string &default_val, const std::string &description)
 Add an option with a string argument. More...
 
void add_option (const std::string &name, char short_form, const std::string &long_form, const char *default_val, const std::string &description)
 
void add_option (const std::string &name, char short_form, const std::string &long_form, bool default_val, const std::string &description)
 Add a boolean flag option. More...
 
bool parse (int argc, const char *const argv[])
 Parse and save option values. Returns whether program should exit because -h or -v was passed. More...
 
bool is_set (const std::string &name)
 Check the value of a boolean option. More...
 
std::string get_value (const std::string &name)
 Look up value of a string option by name. More...
 
std::vector< std::string > get_positional_args (void)
 Returns all positional arguments after parsed options. More...
 
void add_example_usage (const std::string &example)
 Add an example to the usage output. The program name and indentation should be omitted. More...
 
std::string format_help (void)
 Returns the usage string containing description of all options. More...
 

Constructor & Destructor Documentation

◆ OptionParser() [1/2]

geopm::OptionParser::OptionParser ( const std::string &  prog_name,
std::ostream &  std_out,
std::ostream &  err_out 
)

◆ OptionParser() [2/2]

geopm::OptionParser::OptionParser ( const std::string &  prog_name,
std::ostream &  std_out,
std::ostream &  err_out,
const std::string &  custom_help 
)

Member Function Documentation

◆ add_example_usage()

void geopm::OptionParser::add_example_usage ( const std::string &  example)

Add an example to the usage output. The program name and indentation should be omitted.

◆ add_option() [1/3]

void geopm::OptionParser::add_option ( const std::string &  name,
char  short_form,
const std::string &  long_form,
bool  default_val,
const std::string &  description 
)

Add a boolean flag option.

◆ add_option() [2/3]

void geopm::OptionParser::add_option ( const std::string &  name,
char  short_form,
const std::string &  long_form,
const char *  default_val,
const std::string &  description 
)

◆ add_option() [3/3]

void geopm::OptionParser::add_option ( const std::string &  name,
char  short_form,
const std::string &  long_form,
const std::string &  default_val,
const std::string &  description 
)

Add an option with a string argument.

◆ format_help()

std::string geopm::OptionParser::format_help ( void  )

Returns the usage string containing description of all options.

◆ get_positional_args()

std::vector< std::string > geopm::OptionParser::get_positional_args ( void  )

Returns all positional arguments after parsed options.

◆ get_value()

std::string geopm::OptionParser::get_value ( const std::string &  name)

Look up value of a string option by name.

◆ is_set()

bool geopm::OptionParser::is_set ( const std::string &  name)

Check the value of a boolean option.

◆ parse()

bool geopm::OptionParser::parse ( int  argc,
const char *const  argv[] 
)

Parse and save option values. Returns whether program should exit because -h or -v was passed.


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