我正在使用Boost Graph和Program Options构建图形生成器.例如,有两种类型的组件C和W,每种组件具有1个源,1个接收器和一些附加参数以指定其间的拓扑.我希望能够按照命令行参数的顺序将它们拼接在一起.
例如:
./bin/make_graph -c4,5,1 -w3,3 -c3,1,2
Run Code Online (Sandbox Code Playgroud)
应创建类似于以下内容的图形:
C -- W -- C
Run Code Online (Sandbox Code Playgroud)
但:
./bin/make_graph -c4,5,1 -c3,1,2 -w3,3
Run Code Online (Sandbox Code Playgroud)
应创建类似于以下内容的图形:
C -- C -- W
Run Code Online (Sandbox Code Playgroud)
使用boost :: program_options,我无法确定如何提取确切的顺序,因为它使用value_type == vector <string>(在我的情况下)将相同string_key的选项"组合"到一个映射中.
通过迭代地图,订单就会丢失.有没有办法不重复解析,但每次解析一个选项时都有一个叫做(可能是回调)的函数?我找不到这方面的文件.还有其他建议吗?
为了说服你,我没有说明这一点,这就是我到目前为止所做的:
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 …Run Code Online (Sandbox Code Playgroud)