|
Boost Users : |
From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-07-14 09:39:03
On Jul 12, 2004, at 3:36 AM, Daniele Carlucci wrote:
> Hi all,
> I'm a newby in this library. I'm interested to make a graph of
> network. It's possible or is very hard to make?
> I want to have inside every node a struct.
Anything is possible with the BGL :) This particular thing is too hard
to do at the moment, but will become much easier as soon as we release
1.32.0 (in about 2 weeks):
First step is to create a property tag for your struct:
enum vertex_mystruct_t { vertex_mystruct };
Now make that tag a full-fledged graph property tag:
namespace boost {
BOOST_INSTALL_PROPERTY(vertex, mystruct);
}
Now when you create your graph type, you can store a value of any type
X along with each vertex like this (the first three parameters can be
anything, of course):
struct X { int foo; };
typedef adjacency_list<listS, vecS, bidirectionalS,
property<vertex_mystruct_t, X> > Graph;
Graph g; // creating a graph instance
To actually get at the X values for each vertex, we need to grab the
property map:
property_map<vertex_mystruct_t, Graph>::type
X_map(get(vertex_mystruct, g));
Now, finally, we can get to the X structure for any vertex_descriptor v:
X_map[v].foo = 17;
In 1.32.0, the BGL will support "bundled properties", which means that
this whole e-mail would boil down to:
typedef adjacency_list<listS, vecS, bidirectionalS, X> Graph;
Graph g;
graph_traits<Graph>::vertex_descriptor v = ...;
g[v].foo = 17;
Doug
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net