5

I use program options to parse the command line options of my application.

I have several options like -Ox, -Oy, -Oz, ... and I want to have a super option -Oall that enables Ox and Oy and another -Osub that enables Oz and Ow.

Is there a way to do that using Boost Program Options ?

At first, I wanted to check the value of Oall and then manually enables Ox and Oy, but it is not possible to edit values after the parsing.

I want to avoid using variables to store the values of Ox, Oy, because I can have a lot of theses options.

Thanks

Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
  • If you want to avoid having variables for `Ox`, `Oy`, and `Oz`, how then do you plan on accessing their values? In other words, how do you plan on triggering the logic associated with those options when they're set individually? – rcollyer Nov 10 '11 at 16:01
  • I wanted to say options.count("Ox") – Baptiste Wicht Nov 10 '11 at 19:00
  • 1
    Understood. But, there isn't a way to link the occurrence of one parameter with another in `program_options`. However, you could adapt the method of @CharlesB, so that whenever you checked `options.count("Ox")` you also check `options.count("Oall")`. – rcollyer Nov 10 '11 at 19:13
  • Yes, that's exactly what I want to do, but how ? I found no way to edit a variable's value. All the functions of variables_map return const references and I found no way to edit way after parsing. – Baptiste Wicht Nov 10 '11 at 19:24
  • That's not what I mean. Instead of `if (options.count("Ox")>0)` use `if (options.count("Ox")>0 || options.count("Oall")>0)`. – rcollyer Nov 10 '11 at 19:47
  • Ah, yes, this is a solution, but with that, I will have a lot of boilerplate code for every option.... For that, I prefer CharlesB solution. – Baptiste Wicht Nov 12 '11 at 15:25
  • Have you considered a [custom notifier](http://www.boost.org/doc/libs/1_46_1/doc/html/boost/program_options/typed_value.html#id969982-bb)? You could then have the `-OAll` code execute the code for the other options. – rcollyer Nov 12 '11 at 15:48

1 Answers1

1

I see this more in your program's logic so I doubt Program Options provide this. Simply use

if (Oall)
{Ox = Oy = Oz = true;}

and such

CharlesB
  • 86,532
  • 28
  • 194
  • 218