views:

342

answers:

2

I have an application that uses Boost.Program_options to store and manage its configuration options. We are currently moving away from configuration files and using database loaded configuration instead. I've written an API that reads configuration options from the database by hostname and instance name. (cool!) However, as far as I can see there is no way to manually insert these options into the boost Program_options. Has anyone used this before, any ideas? The docs from boost seem to indicate the only way to get stuff in that map is by the store function, which either reads from the command line or config file (not what I want). Basically looking for a way to manually insert the DB read values in to the map.

+3  A: 

Have you looked at the extra_parser or allow_unregistered functions of Boost::Program_Options? Depending on exactly how your program operates, one or both of them should be able to support what you want.

Head Geek
A: 

My answer comes a little too late, but I spent some time trying to do something similar and found an annoyingly obvious solution (incase anyone else is looking for this)...

Recalling that boost::program_options::variables_map derives from std::map<std::string, boost::program_options::variable_value>, you can do perfectly legal STL map processing including an insert...

namespace po = boost::program_options;
po::variables_map vm;
vm.insert(std::make_pair("MyNewEmptyOption", po::variable_value());
vm.insert(std::make_pair("MyNewIntOption", po::variable_value(32, false));
po::notify(vm);

-Edmond-

Edmond Begumisa
Doesn't look like program_options inherits from std::map to me. I see it derived from: abstract_variables_map. Haven't checked out if that is an re-engineered std::map yet.
windfinder