Pergunta

I currently use some old C library for getting program options and would like to replace that with some proper C++ (mainly to become independent of that library, which is a real burden). I was looking into using boost.program_options, but am not sure it can support all I want. Some things I want is:

  1. allow the following command-line syntax: myprogram option=value (in particular, I don't really want the --option value syntax)

  2. use a default value if no value is provided (obviously this can be done in my program, but support in the options library would be nice)

  3. allow default options (which are always present even if I don't give them) and an automatic help output consisting of all the options and their descriptions

  4. allow mathematical parsing, i.e. (command line) myprogram option1=Pi option2=3/5 option3=sqrt(2) to give 3.1415..., 0.6, and 1.415... in my program

  5. allow single values to be expanded. Let option_3Dpoint correspond to an std::array<double,3>, I want both myprogram option_3Dpoint=0,0,0 and myprogram option_3Dpoint=0 (expanding to 0,0,0) to work

Which of these can be supported by boost.program_options? Are there any alternatives?

Foi útil?

Solução

boost.program_options is very good library. You can use to parse config files aswell. Answers:

  1. Dont know but seems no builtin support.
  2. Yes.
  3. Yes.
  4. No unless you make your own expression evaluation handler or use some other boost libs to do this.
  5. Yes, you will need to write your own handler which creates 3DPoint object from string like 0,0,0
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top