5 #include <boost/any.hpp>
6 #if __has_include(<filesystem>)
8 namespace fs = std::filesystem;
10 #include <experimental/filesystem>
11 namespace fs = std::experimental::filesystem;
17 std::ostream&
operator<<(std::ostream& os,
const boost::any& val) {
19 return os <<
"<empty>";
20 }
else if (boost::any_cast<bool>(&val) !=
nullptr) {
21 return os << std::boolalpha << boost::any_cast<bool>(val);
22 }
else if (boost::any_cast<std::size_t>(&val) !=
nullptr) {
23 return os << boost::any_cast<std::size_t>(val);
24 }
else if (boost::any_cast<std::string>(&val) !=
nullptr) {
25 return os << boost::any_cast<std::string>(val);
26 }
else if (boost::any_cast<carl::settings::duration>(&val) !=
nullptr) {
27 return os << boost::any_cast<carl::settings::duration>(val);
28 }
else if (boost::any_cast<carl::settings::binary_quantity>(&val) !=
nullptr) {
29 return os << boost::any_cast<carl::settings::binary_quantity>(val);
30 }
else if (boost::any_cast<carl::settings::metric_quantity>(&val) !=
nullptr) {
31 return os << boost::any_cast<carl::settings::metric_quantity>(val);
33 return os <<
"Unknown type";
39 os <<
"Usage: <binary> [options]";
51 auto value = sp.
parser.
mValues[option->canonical_display_name()];
52 os << option->canonical_display_name() <<
" = " << value.value() << std::endl;
58 auto res = po::collect_unrecognized(parsed.options, po::exclude_positional);
59 for (
const auto& s: res) {
66 if (allow_unregistered) {
67 parser.allow_unregistered();
69 auto parsed = parser.run();
70 if (allow_unregistered) {
78 if (fs::is_regular_file(configfile)) {
79 auto parsed = po::parse_config_file<char>(configfile.c_str(),
mAllOptions, allow_unregistered);
80 if (allow_unregistered) {
91 [](
const auto& f){ return f(); }
104 if (
mValues.count(this->name_of_config_file()) != 0) {
std::ostream & operator<<(std::ostream &os, const duration &d)
Streaming operator for duration. Auto-detects proper time suffix.
Helper class to nicely print the options that are available.
const SettingsParser & parser
Reference to parser.
Helper class to nicely print the settings that were parsed.
const SettingsParser & parser
Reference to parser.
void parse_options(int argc, char *argv[], bool allow_unregistered=true)
Parse the options.
void finalize()
Finalizes the parser.
bool finalize_settings()
Calls the finalizer functions.
std::vector< po::options_description > mOptions
Stores the individual options until the parser is finalized.
void parse_config_file(bool allow_unregistered)
Parses the config file if one was configured.
virtual void warn_config_file(const std::string &file) const
Prints a warning if loading the config file failed. Can be overridden.
po::options_description mAllOptions
Accumulates all available options.
po::positional_options_description mPositional
Stores the positional arguments.
virtual void warn_for_unrecognized_option(const std::string &s) const
Prints a warning if an option was unrecognized. Can be overridden.
virtual std::string name_of_config_file() const
Gives the option name for the config file name. Can be overridden.
po::variables_map mValues
Stores the parsed values.
void warn_for_unrecognized(const po::parsed_options &parsed) const
Checks for unrecognized options that were found.
void parse_command_line(int argc, char *argv[], bool allow_unregistered)
Parses the command line.
std::vector< std::function< bool()> > mFinalizer
Stores hooks for setting object finalizer functions.
char * argv_zero
Stores the name of the current binary.