Hi Rodolfo,
Hi, I wonder if it's possible to handle dynamically created program options with boost::program_options. For instance: I have a config file that specifies configure options for dynamic loaded modules in my project. So the cfg file would be:
[module.foo1] module_file = foo.so listen_port = 564 enabled = true
As can be seen, foo1, foo2 and bar1 names are defined by the user in the configure file, and the program doesn't know about them before parsing the configuration. But if we parse that (somehow), an exception saying that the option "module.foo1.module_file" is invalid will be thrown. Can I manage the options_description "on the fly"?
Not exactly "on the fly". In program_options, parsing is separated from any semantic work, so it's not possible to add new items to options_description while the file is being parsed. You'd need to "prescan" the config file and then declare the necessary options. Luckily, to "prescan" the config file you can use "*" in option names. If you declare "module.*" option, which will catch everything. The problem is that all options will have the same time. So, after this "prescan" parsing you can collect the list of modules, and declare "real" options: "module_file", "listen_port" and so on. I attach the example and a config file which produce this: bar : bar.so : 500 foo : foo.so : 400 HTH, Volodya