4

I am currently using boost::program_options to parse command line and config-file arguments. However, recently I have realised I need to be able to pass my program a list of options which could be very easily summarised using e.g. JSON notation

algorithms: [
    {
        type: alg1,
        parameters: {},
        weight: 0.1,
    },
    {
        type: alg2,
        parameters: {},
        weight: 0.6,
    }
]

Where the parameter option could have a different number of arguments depending on the type. I was wondering if there is any way of giving json directly to a config-file parsed by program_options. The problem as I see it is that I can't make program_options parse a value with newlines, if it could I would be able to write something along the lines of

algorithms = [
    {
        type: alg1,
        parameters: {},
        weight: 0.1,
    }
]

parsed as a string, which I could then hand over to boost::property_tree. Alternatively, is there any better way of parsing these types of variable options using just boost::program_options? I know one option would be to simple have a separate .json file with the config, and give that json filename as the program option, but it would be nice to be able to have it all in one configuration file.

  • You may consider decision, posted in my answer to that thread: https://stackoverflow.com/questions/44239604/c-boost-program-options-with-json-file – Kirill Suetnov Jul 19 '17 at 18:37

0 Answers0