Am Mittwoch, 22. August 2007 15:03 schrieb Frank Birbacher:
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Yeah I know that boost already can handle config files but I would like to use for example an xml file as config file. Or does boost also provides a feature for this?