Boost logo

Boost Users :

Subject: [Boost-users] Vector types in dynamic_properties used by write_graphml
From: Richard Vock (vock_at_[hidden])
Date: 2009-05-31 17:11:17


He Folks,

I'm using bundled properties in order to attach multiple attributes
to graph nodes. Using only basic data types like integers, strings
etc. the following example code works well. However I would like
to also use vectors or similar containers (like in the example about
bundled properties at
http://www.boost.org/doc/libs/1_39_0/libs/graph/doc/bundles.html).

However I don't know how to use this field for my dynamic_property map.
In the following code the single commented-out line is the point where
I most probably didn't understand some kind of vital concept.

Maybe you could enlighten me or at least point me in the right direction,
thanks in advance

Richard Vock

---
Here's the example code:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/dynamic_property_map.hpp>
#include <boost/graph/graphml.hpp>
struct NodeProperties {
	int test;
	std::vector<int>	ints;
};
int main(int argc, char* argv[]) {
	typedef std::pair<int,int> Edge;
	std::vector< Edge > connections;
	// create simple edge loop for testing purposes
	for (int i=0; i<10; ++i) 
		connections.push_back( Edge(i,(i+1)%10) );
	typedef boost::adjacency_list< boost::vecS, boost::vecS, boost::undirectedS, 
NodeProperties> Graph;
	Graph g(connections.begin(), connections.end(), 10);
	boost::graph_traits<Graph>::vertex_iterator v, v_end;
	for (tie(v,v_end) = vertices(g); v != v_end; ++v) {
		Graph::vertex_descriptor desc = *v;
		g[desc].test = 10;
		for (int i=0; i<5; ++i) g[desc].ints.push_back(i);
	}
	boost::dynamic_properties dp;
	dp.property("test",  get(&NodeProperties::test, g));
	//dp.property("testInts",  get(&NodeProperties::ints, g));
	
	boost::write_graphml(std::cout, g, dp, true);
}

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