|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2004-05-02 14:28:09
On Monday 05 April 2004 11:11 pm, Jeremy Siek wrote:
> Ran into another difficulty for supporting stuff like v->color
> (through a pointer or a proxy). The current BGL
> design places the sole responsibility of
> constness on the property maps. Thus we don't have
> a const_vertex_descriptor, or const_out_edge_iterator,
> or const_vertex_iterator, etc.
We discussed this offline a bit, and found that we could resolve this by
creating a graph operation that maps from a graph and vertex/edge descriptor
to the class that stores the properties of that descriptor. For instance:
struct city
{
string name;
};
struct highway
{
int speed_limit;
double distance;
};
typedef adjacency_list<listS, vecS, bidirectionalS, city, highway> graph;
graph g; // put some nodes/edges into g
graph_traits<graph>::vertex_descriptor v = vertices(g).first;
g[v].name = "Foo";
graph_traits<graph>::edge_descriptor e = edges(g).first;
g[e].speed_limit = 65;
The vertex_descriptor/edge_descriptor types will need to be different, of
course, but otherwise this is easy to do and the constness will get picked up
from the graph itself.
The second part of this is to be able to create a property map easily. Here's
one potential syntax:
member_property_map(&highway::distance, g);
Or, if we're being cute,
g ->* &highway::distance
I personally like the overloaded ->* syntax :)
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk