Hello, I am using boost::program_options and need to load custom config files. So I think I need to write a parser, right? But I did not find any tutorials or something like that where I can learn how to write and usea parser with program options. Can anybody help me out og this problem? Thx in advance
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
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?
Hi! Stefan Bradl schrieb:
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?
The serialization library of boost can produce xml files from data structures and read them back in. But I guess they won't match up on your expectations of a config file. Other than that I currently have no idea. Frank
participants (2)
-
Frank Birbacher
-
Stefan Bradl