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;
}
{
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
/ (, Boost):
./bin/make_graph
./bin/make_graph c,4,5,1,w,3,3,c,3,1,2
, , , ?
!
PS: SO "[boost] + " "[- ] + " ( ), , , .