Boost logo

Boost Users :

Subject: [Boost-users] [program_options] Is it possible to change semantics after add_options() ?
From: lukasz kucharski (luk32_at_[hidden])
Date: 2013-02-06 06:54:51


Hello,

I would like to ask if it is possible to change value_semantic
associated with a program_option after it has been created ?

I create `program_options` instance and populate it with add_options.
Like in the examples provided by the documentation. I would like to
change the semantics of a particular option later on.

Is this even possible, or is this functionality deliberately disabled.

I figured out that one can use options_description::find(), then strip
it out `const`ness and dynamic cast to `typed_value_base` and use its
methods.

My motivation is such a design. I have a set of applications, which have
a common subset of command line options/switches. However, they differ a
bit in semantics. I.e. default value. I decided to refactor common parts
into some `BasicApp` class and I thought I could move common options
along with it as `boost::program_options` OO design should naturally
support it. And it worked like a charm with `add_options` semantics to
add new options. Up to the point I needed to change existing default values.

Is there a proper way to do it ? Removing `const` constraint seems a bad
approach since it looks like it's left there on purpose. Or my use-case
is ill or hopeless.

With regards,
Łukasz.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net