carl
24.04
Computer ARithmetic Library
|
Base class for a settings parser. More...
#include <SettingsParser.h>
Public Member Functions | |
virtual | ~SettingsParser ()=default |
Virtual destructor. More... | |
void | finalize () |
Finalizes the parser. More... | |
po::options_description & | add (const std::string &title) |
Adds a new options_description with a title and a reference to the settings object. More... | |
template<typename F > | |
void | add_finalizer (F &&f) |
Adds a finalizer function to be called after parsing. More... | |
void | parse_options (int argc, char *argv[], bool allow_unregistered=true) |
Parse the options. More... | |
OptionPrinter | print_help () const |
Print a help page. More... | |
SettingsPrinter | print_options () const |
Print the parsed settings. More... | |
Protected Member Functions | |
void | warn_for_unrecognized (const po::parsed_options &parsed) const |
Checks for unrecognized options that were found. More... | |
void | parse_command_line (int argc, char *argv[], bool allow_unregistered) |
Parses the command line. More... | |
void | parse_config_file (bool allow_unregistered) |
Parses the config file if one was configured. More... | |
bool | finalize_settings () |
Calls the finalizer functions. More... | |
virtual void | warn_for_unrecognized_option (const std::string &s) const |
Prints a warning if an option was unrecognized. Can be overridden. More... | |
virtual void | warn_config_file (const std::string &file) const |
Prints a warning if loading the config file failed. Can be overridden. More... | |
virtual std::string | name_of_config_file () const |
Gives the option name for the config file name. Can be overridden. More... | |
Protected Attributes | |
char * | argv_zero = nullptr |
Stores the name of the current binary. More... | |
po::positional_options_description | mPositional |
Stores the positional arguments. More... | |
po::options_description | mAllOptions |
Accumulates all available options. More... | |
po::variables_map | mValues |
Stores the parsed values. More... | |
std::vector< po::options_description > | mOptions |
Stores the individual options until the parser is finalized. More... | |
std::vector< std::function< bool()> > | mFinalizer |
Stores hooks for setting object finalizer functions. More... | |
Friends | |
std::ostream & | settings::operator<< (std::ostream &os, settings::OptionPrinter op) |
std::ostream & | settings::operator<< (std::ostream &os, settings::SettingsPrinter sp) |
Base class for a settings parser.
Definition at line 81 of file SettingsParser.h.
|
virtualdefault |
Virtual destructor.
|
inline |
Adds a new options_description with a title and a reference to the settings object.
The settings object is needed to pass it to the finalizer function.
Definition at line 130 of file SettingsParser.h.
|
inline |
Adds a finalizer function to be called after parsing.
boost::program_options::notify() is called before running the finalizer functions. The finalizer function should accept a boost::program_options::variables_map as its only argument and should return a bool indicating whether it changed the variables map. If any finalizer changed the variables map, boost::program_options::notify() is called again afterwards.
Definition at line 140 of file SettingsParser.h.
void carl::settings::SettingsParser::finalize | ( | ) |
Finalizes the parser.
Definition at line 95 of file SettingsParser.cpp.
|
protected |
Calls the finalizer functions.
Definition at line 89 of file SettingsParser.cpp.
|
inlineprotectedvirtual |
Gives the option name for the config file name. Can be overridden.
Definition at line 116 of file SettingsParser.h.
|
protected |
Parses the command line.
Definition at line 64 of file SettingsParser.cpp.
|
protected |
Parses the config file if one was configured.
Definition at line 76 of file SettingsParser.cpp.
void carl::settings::SettingsParser::parse_options | ( | int | argc, |
char * | argv[], | ||
bool | allow_unregistered = true |
||
) |
Parse the options.
If allow_unregistered is set to true, we allow them but call warn_for_unrecognized_option() for each one. Otherwise an exception is raised when an unrecognized option is encountered.
Definition at line 101 of file SettingsParser.cpp.
|
inline |
Print a help page.
Returns a helper object so that it can be used as follows: std::cout << parser.print_help() << std::endl;
Definition at line 156 of file SettingsParser.h.
|
inline |
Print the parsed settings.
Returns a helper object so that it can be used as follows: std::cout << parser.print_options() << std::endl;
Definition at line 165 of file SettingsParser.h.
|
inlineprotectedvirtual |
Prints a warning if loading the config file failed. Can be overridden.
Definition at line 112 of file SettingsParser.h.
|
protected |
Checks for unrecognized options that were found.
Definition at line 57 of file SettingsParser.cpp.
|
inlineprotectedvirtual |
Prints a warning if an option was unrecognized. Can be overridden.
Definition at line 108 of file SettingsParser.h.
|
friend |
|
friend |
|
protected |
Stores the name of the current binary.
Definition at line 86 of file SettingsParser.h.
|
protected |
Accumulates all available options.
Definition at line 90 of file SettingsParser.h.
|
protected |
Stores hooks for setting object finalizer functions.
Definition at line 96 of file SettingsParser.h.
|
protected |
Stores the individual options until the parser is finalized.
Definition at line 94 of file SettingsParser.h.
|
protected |
Stores the positional arguments.
Definition at line 88 of file SettingsParser.h.
|
protected |
Stores the parsed values.
Definition at line 92 of file SettingsParser.h.