Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you manually insert options into boost.Program_options?

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.

like image 824
Alex Avatar asked May 08 '09 19:05

Alex


1 Answers

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-

like image 121
Edmond Begumisa Avatar answered Sep 26 '22 00:09

Edmond Begumisa