Boost logo

Boost Users :

From: Frank Birbacher (bloodymir.crap_at_[hidden])
Date: 2007-08-22 09:03:16


Hi!

Stefan Bradl schrieb:
> Hello,
>
> I am using boost::program_options and need to load custom config files.
> So I think I need to write a parser, right?

The program_options library already supports config files. Here is a
snippet of my custom options class, which reads commandline options and
an optional config file:

OptionManager(const int argc, char* argv[])
{
options_description descriptions("Allowed Options");
init_options(descriptions);

store(parse_command_line(argc, argv, descriptions), varmap);

if(varmap.count("config"))
{
std::ifstream configFile(varmap["config"].as<string>().c_str());
store(parse_config_file(configFile, descriptions), varmap);
}

notify(varmap);
}

where "init_options" is a function written by me. It adds all available
option descriptions via options_description::add_option. Note the use of
"parse_config_file" which is supplied by boost. See
http://www.boost.org/doc/html/program_options/overview.html#id1592208
for a parser overview.

Frank


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net