I'm new to the BGL.
I'm trying to represent a type hierarchy along these lines:
Number : terminal(double)
String : terminal(std::string)
Vec2
x : Number
y : Number
Circle
position : Vec2
radius : Number
I'm using the following code:
struct Descriptor { std::string name; };
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Descriptor, Descriptor> Graph;
static inline void addVertex(Graph& g, const std::string& name)
{
Graph::vertex_descriptor d = boost::add_vertex( g );
g[ d ].name = name;
}
static inline void addEdge(Graph& g, const std::string& name, Index source, Index target)
{
std::pair<Graph::edge_descriptor, bool> d = boost::add_edge( source, target, g );
g[ d.first ].name = name;
}
...with the idea that Vertex properties would identify the "type names" (Number, String, Vec2 and Circle) and Edge properties would identify the "member names" (x, y, position and radius) of a compound type's components.
The conceptual trouble I'm running into is that a Vertex (Vec2, for instance) can have two members with the same type. In such a model, is it ok to create separate edges for Vec2 -> Number(x) and Vec2 -> Number(y)? Is this the correct approach?
Ultimately, I would like to be able to traverse the graph such that if we started at Circle, we would visit (in order): position.x, position.y, radius.
Thanks for your help!