BGL: filtered graphs, write_graphviz, and out of memory messages
Hi all: I am seeing a strange interaction between filtered graphs and write_graphviz. Briefly, if I try to write out a filtered graph via write_graphviz, compilation ends with an out-of-memory message. A necessary condition for this to happen is that the value_type of the property map I am filtering cannot be of a native type -- int is ok, std::string is not. Example code is appended below. I am using Codewarrior Dev Tools 8.0 on WinXP Pro. Given that the code does not even compile, I am not sure how to move beyond this point. Any ideas? TIA, - S ----------------------------------------------------------------- #include "boost/config.hpp" #include <fstream.h> #include <iostream> // for std::cout #include <utility> // for std::pair #include <algorithm> // for std::for_each #include "boost/utility.hpp" // for boost::tie #include "boost/graph/graph_traits.hpp" // for boost::graph_traits #include "boost/graph/adjacency_list.hpp" #include "boost/graph/graphviz.hpp" #include "boost/graph/filtered_graph.hpp" using namespace boost; namespace boost { enum edge_prop_t { edge_prop = 389457 }; BOOST_INSTALL_PROPERTY(edge, prop); } template <typename T> struct positive_edge_prop { positive_edge_prop() {}; positive_edge_prop(T t) : m_prop(t) {}; template <typename Edge> bool operator() (const Edge& e) const { return "foo" == get(m_prop, e); } T m_prop; }; int main(void) { // create an edge property // if std::string is replaced with int, and some attendant changes are made, the code compiles typedef property<edge_prop_t, std::string> EdgeProperty; // create a simple graph type typedef adjacency_list<vecS, vecS, bidirectionalS, no_property, EdgeProperty> Pgraph; enum { A, B, C, D, E, F, N }; const int num_vertices = N; typedef std::pair<int, int> Edge; Edge edge_array[] = { Edge(A, B), Edge(B, C), Edge(C, D), Edge(D, E), Edge(E, F), Edge(F, A), }; const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]); Pgraph pg(edge_array, edge_array + num_edges, num_vertices); // Add edge properties typedef boost::property_map<Pgraph, edge_prop_t>::type ewt; ewt ew = get(edge_prop_t(), pg); boost::graph_traits<Pgraph>::edge_iterator ei, ei_end; boost::tie(ei, ei_end) = edges(pg); for (ei; ei != ei_end; ei++) put(ew, *ei, "bar"); std::map<std::string,std::string> graph_attr, vertex_attr, edge_attr; boost::write_graphviz(std::cout, pg); positive_edge_prop<ewt> filter(get(edge_prop_t(), pg)); filtered_graph<Pgraph, positive_edge_prop<ewt> > fg(pg, filter); boost::write_graphviz(std::cout, fg); // if this line is commented out, the code compiles just fine return 0; } -----------------------------------------------------------------
participants (1)
-
sa3h1n <sa3h1n@yahoo.com>