How to extract the sequence of analyzed options using the parameters of the Boost program?

I am creating a graph generator using Boost Graph and Program Options. For example, there are two types of components C and W, each of which has 1 source, 1 receiver, and some additional parameters to indicate the topology between them. I would like to be able to stitch them together in the sequence provided by the order of the command line arguments.

For instance:

./bin/make_graph -c4,5,1 -w3,3 -c3,1,2

Create a graph similar to the following:

C -- W -- C

But:

./bin/make_graph -c4,5,1 -c3,1,2 -w3,3

Create a graph similar to the following:

C -- C -- W

Using boost :: program_options, I could not determine how to extract the exact order, since it "composes" the parameters of the same line in the map using value_type == vector <string> (in my case).

, . , , (, ) ? . ?

, , :

    namespace bpo = boost::program_options;
    std::vector<std::string> args_cat, args_grid, args_web;
    bpo::options_description desc("Program options:");
    desc.add_options()
            .operator ()("help,h","Displays this help message.")
            .operator ()("caterpillar,c",bpo::value< std::vector<std::string> >(&args_cat)->default_value( std::vector<std::string>(1,"4,7,2"), "4,7,2" ),"Caterpillar tree with 3 parameters")
            .operator ()("grid,g",bpo::value< std::vector<std::string> >(&args_grid)->default_value( std::vector<std::string>(1,"3,4"), "3,4" ),"Rectangular grid with 2 parameters")
            .operator ()("web,w",bpo::value< std::vector<std::string> >(&args_web)->default_value( std::vector<std::string>(1,"3,4"), "3,4" ),"Web with 2 parameters")
            ;
    bpo::variables_map ops;
    bpo::store(bpo::parse_command_line(argc,argv,desc),ops);
    bpo::notify(ops);
    if((argc < 2) || (ops.count("help"))) {
        std::cout << desc << std::endl;
        return;
    }
    //TODO: remove the following scope block after testing
    {
        typedef bpo::variables_map::iterator OptionsIterator;
        OptionsIterator it = ops.options.begin(), it_end = ops.options.end();
        while(it != it_end) {
            std::cout << it->first << ": ";
            BOOST_FOREACH(std::string value, it->second) {
                std::cout << value << " ";
            }
            std::cout << std::endl;
            ++it;
        }
        return;
    }

, , :

./bin/make_graph --component c,4,5,1 --component w,3,3 --component c,3,1,2

/ (, Boost):

./bin/make_graph --custom c,4,5,1,w,3,3,c,3,1,2
./bin/make_graph c,4,5,1,w,3,3,c,3,1,2

, , , ?

!

PS: SO "[boost] + " "[- ] + " ( ), , , .

+5
2

"", , .

bpo::parsed_options p_ops = bpo::parse_command_line(argc,argv,desc);
typedef std::vector< bpo::basic_option<char> >::iterator OptionsIterator;
OptionsIterator it = p_ops.options.begin(), it_end = p_ops.options.end();
while(it != it_end) {
    std::cout << it->string_key << ": ";
    BOOST_FOREACH(std::string value, it->value) {
        std::cout << value << " ";
    }
    std::cout << std::endl;
    ++it;
}

, , , , , bpo:: variables_map .as<T>(). EDIT: .

+4

:

./bin/make_graph c,4,5,1 c,3,1,2 w,3,3

"c,4,5,1", "c,3,1,2" "w,3,3" - , ( ) std::vector<std::string> ( , --input-file tutorial). Boost.Tokenizer boost::algorithm::split, subtokens .

, , , . Boost.Program_Options , , .

+2

All Articles