[program_options] Finding out the type of the options
Hello,
I'm using program_options, and I want to be able to learn what the option type
is by manipulating an options_description object. As I illustrate in the example
below (boost 1.33), I can do this if the option has been given a default value.
Could anyone suggest a wasy to this for options without a default?
The story behind this question is that I would like to be able to build a simple
GUI parameter dialog based on the options_description, and I want to map
different types to different widgets.
Thanks, Giuseppe
#include
Hi Giuseppe,
I'm using program_options, and I want to be able to learn what the option type is by manipulating an options_description object. As I illustrate in the example below (boost 1.33), I can do this if the option has been given a default value. Could anyone suggest a wasy to this for options without a default?
It looks like there's not one. In general, an option can use arbitrary user-defined class derived from "value_semantics" to handle value, so the problem is not solvable in general. For the case of using "typed_value" template provided by the library, I can do this: - Add new class 'typed_value_base', with "typeinfo& type()" method. - Implement that method in typed_value template What do you think about this approach?
The story behind this question is that I would like to be able to build a simple GUI parameter dialog based on the options_description, and I want to map different types to different widgets.
Wow, that sound great. - Volodya
Hi
- Add new class 'typed_value_base', with "typeinfo& type()" method. - Implement that method in typed_value template
What do you think about this approach?
That sounds good, I'm looking forward to it. Cheers, Giuseppe
Hi Giuseppe,
- Add new class 'typed_value_base', with "typeinfo& type()" method. - Implement that method in typed_value template
What do you think about this approach?
That sounds good, I'm looking forward to it.
Implemented in CVS HEAD. I attach a patch for your reference, which includes example usage inside tests. HTH, Volodya
participants (2)
-
Giuseppe Vacanti
-
Vladimir Prus