【发布时间】:2011-08-01 23:11:13
【问题描述】:
给定一个顶点为:
class VertexProps {
public:
int id;
float frame;
string name;
};
我已经使用捆绑属性初始化了我的提升图。我知道我可以通过以下方式获取框架:
std::cout << "Vertex frame: " << boost::get(&VertexProps::frame, graph, vertex) << std::endl;
//Need to make this work: float frame = boost::get(&VertexProps::frame, graph, vertex);
//graph is a boost::adjacency_list and vertex is a boost::vertex_descriptor
但是,我想编写一个更通用的函数或包装器:
std::vector<float> frames;
std::string prop_name = "frame";
float frame = graph.get_vertex_prop(vertex, prop_name);
frames.push_back(frame);
我希望得到类似的东西:
typedef boost::variant< int, unsigned int, float, std::string > PropValType;
typedef boost::vertex_bundle_type<Graph>::type PropIdType;
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
PropValType get_vertex_prop(Vertex& v, PropIdType pname)
{
boost::get(pname, graph, v);
//If pname = frame then return value as float (or cast boost::variant to float)
//If pname = name then return value as a string
}
我想避免这样的事情:
PropValType get_vertex_prop(Vertex& v, std::string pname) {
if (pname == "frame") {
boost::get(&VertexProps::frame, graph, v)
//return value as float
}
if (...)
}
【问题讨论】:
标签: c++ boost graph properties