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.
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-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With