【发布时间】:2012-12-16 15:16:21
【问题描述】:
我正在编写一个应用程序来解析类似的数据结构
struct Block
{
std::string foo;
/* ... even more local data ... */
};
std::map<std::string, Block> blockContainer; // Each Block will have a name here
struct Signal
{
// the direct links to the Blocks, no redundant storage of the name so that an
// simple renaming of a Block would be possible
std::map<std::string, Block>::iterator from;
std::map<std::string, Block>::iterator to;
std::string bar;
/* ... even more local data ... */
};
std::vector<Signal> signalContainer;
解析和填写此列表非常容易。现在我需要根据信号对块进行拓扑排序 - 当我使用 Boost::Graph 时也很容易。
但是首先在 STL 数据结构中解析它,然后将它们复制到 Boost::Graph 结构对我来说没有多大意义。尤其是之后对这些数据所做的所有事情可能只是一些简单的修改(添加/删除块和信号,一些信号重新路由;再次将其序列化),然后使用新的拓扑排序。
所以我可以接受以下任何可能的解决方案:
- 让 Boost::Graph 直接在我的容器上运行
- 将数据直接解析到 Boost::Graph 数据结构中(例如,使用带有
boost::adjacency_list<boost::mapS, boost::vecS, boost::directedS, Block, Signal>等捆绑属性的图)
但我似乎不够聪明,无法理解这里的文档。此外,我在网上找到的所有示例都显示了如何使用捆绑属性 - 但没有显示如何使用这些属性构建图表。 (当然,不能同时使用节点和顶点属性,或者如何使用std::map 让节点通过它们的名称访问它们,...)
谁能帮帮我?
谢谢!
【问题讨论】:
标签: c++ boost-graph