67 po::options_description config(
"Configuration");
69 (
"compression", var<int>(),
"set compression level")
70 (
"optimization", var<int>(10, &opt),
"optimization level")
71 (
"test-def", var<int>(42),
"optimization level")
72 (
"include-path,I", vars<string>(),
"include path")
73 (
"test,T", vars<string>(),
"include path")
74 (
"file1", vars<string>(),
"include path")
75 (
"int1", var<int>(),
"include path")
76 (
"Int2", var<int>(),
"include path")
77 (
"Int1", var<int>(),
"include path")
78 (
"test-db", var<string>(
"database"),
"include path")
79 (
"float1", var<double>(),
"include path")
81 (
"radec", po::value<vector<double>>(),
"include path")
83 (
"bool", var<bool>()->implicit_value(
true),
"include path")
89 po::options_description sections(
"Sections");
91 (
"unregistered", var<string>(),
"include path")
92 (
"Section1.unregistered", var<string>(),
"include path")
99 po::options_description hidden(
"Hidden options");
101 (
"input-file", vars<string>(),
"input file")
102 (
"output-file", vars<string>(),
"output file")
103 (
"test-file", vars<string>(),
"test file")
106 po::options_description env(
"Environment options");
108 (
"linux", var<string>(),
"LINUX env")
109 (
"path", var<string>(),
"PATH env")
110 (
"dns", var<string>(),
"DIM_DNS_SERVER env")
113 conf.
AddEnv(
"linux",
"LINUX");
114 conf.
AddEnv(
"path",
"PATH");
115 conf.
AddEnv(
"dns",
"DIM_DNS_SERVER");
118 po::positional_options_description p;
119 p.add(
"output-file", 2);
120 p.add(
"test-file", 3);
121 p.add(
"input-file", -1);
139 int main(
int argc,
const char **argv)
146 po::variables_map vm;
149 vm = conf.
Parse(argc, argv);
151 catch (std::exception &e)
153 #if BOOST_VERSION > 104000 154 po::multiple_occurrences *MO =
dynamic_cast<po::multiple_occurrences*
>(&e);
156 cout <<
"Error: " << e.what() <<
" of '" << MO->get_option_name() <<
"' option." << endl;
159 cout <<
"Error: " << e.what() << endl;
168 cout <<
"------------------------------" << endl;
170 cout <<
"Program " << argv[0] <<
" started successfully." << endl;
172 cout << conf.
Has(
"switch") <<
" " << conf.
Get<
bool>(
"switch") << endl;
173 cout << conf.
Has(
"bool") <<
" " << conf.
Get<
bool>(
"bool") << endl;
void AddOptionsEnvironment(const po::options_description &env, bool visible=true)
void AddOptionsConfigfile(const po::options_description &cf, bool visible=true)
T Get(const std::string &var)
po::typed_value< bool > * po_switch()
void AddEnv(const std::string &conf, const std::string &env)
void SetArgumentPositions(const po::positional_options_description &desc)
void AddOptionsDatabase(const po::options_description &db, bool visible=true)
bool Has(const std::string &var)
void SetupConfiguration(Configuration &conf, int &opt)
void AddOptionsCommandline(const po::options_description &cl, bool visible=true)
Commandline parsing, resource file parsing and database access.
const po::variables_map & Parse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
int main(int argc, const char **argv)