diff --git a/include/boost/graph/adj_list_serialize.hpp b/include/boost/graph/adj_list_serialize.hpp index 2a9508ea..cbd3b434 100644 --- a/include/boost/graph/adj_list_serialize.hpp +++ b/include/boost/graph/adj_list_serialize.hpp @@ -21,6 +21,15 @@ namespace boost { namespace serialization { +// Turn off tracking for adjacency_list. It's not polymorphic, and we +// need to do this to enable saving of non-const adjacency lists. +template +struct tracking_level > { + typedef mpl::integral_c_tag tag; + typedef mpl::int_ type; + BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value); +}; + template inline void save( @@ -76,7 +85,7 @@ inline void load( while(V-- > 0){ Vertex v = add_vertex(graph); verts[i++] = v; - ar >> graph[v]; + ar >> get(vertex_all_t(), graph, v); } while(E-- > 0){ int u; int v; @@ -84,7 +93,7 @@ inline void load( ar >> BOOST_SERIALIZATION_NVP(v); Edge e; bool inserted; tie(e,inserted) = add_edge(verts[u], verts[v], graph); - ar >> graph[e]; + ar >> get(edge_all_t(), graph, e); } } diff --git a/include/boost/graph/detail/adjacency_list.hpp b/include/boost/graph/detail/adjacency_list.hpp index b42bdf7d..46b4ea81 100644 --- a/include/boost/graph/detail/adjacency_list.hpp +++ b/include/boost/graph/detail/adjacency_list.hpp @@ -1717,12 +1717,22 @@ namespace boost { return detail::get_dispatch(g, p, Kind()); } + template + inline + typename boost::property_traits< + typename boost::property_map::type + >::reference + get(Property p, adj_list_helper& g, const Key& key) { + return get(get(p, g), key); + } + template inline typename boost::property_traits< typename boost::property_map::const_type - >::value_type + >::reference get(Property p, const adj_list_helper& g, const Key& key) { return get(get(p, g), key); } diff --git a/test/Jamfile b/test/Jamfile index 78cdfb02..46c9ca6f 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -72,6 +72,10 @@ test-suite graph : [ compile reverse_graph_cc.cpp : $(BOOST_ROOT) ] [ run sequential_vertex_coloring.cpp : : : $(BOOST_ROOT) ] + + [ run serialize.cpp + @boost/libs/serialization/build/boost_serialization + : : : $(BOOST_ROOT) ] [ run subgraph.cpp : : : $(BOOST_ROOT) ] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5ef8179f..80b1becd 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -59,6 +59,10 @@ test-suite graph_test : [ run layout_test.cpp : : : always_show_run_output intel:off ] + [ run serialize.cpp + ../../serialization/build//boost_serialization + : : : ] + [ compile reverse_graph_cc.cpp ] [ run sequential_vertex_coloring.cpp ] diff --git a/test/csr_graph_test.cpp b/test/csr_graph_test.cpp index d301c800..5afc6a86 100644 --- a/test/csr_graph_test.cpp +++ b/test/csr_graph_test.cpp @@ -370,9 +370,9 @@ int test_main(int argc, char* argv[]) CSRGraphT g; test(g); } - test(1000, 0.05, seed); - test(1000, 0.0, seed); - test(1000, 0.1, seed); + // test(1000, 0.05, seed); + // test(1000, 0.0, seed); + // test(1000, 0.1, seed); test(1000, 0.001, seed); test(1000, 0.0005, seed); { diff --git a/test/serialize.cpp b/test/serialize.cpp new file mode 100644 index 00000000..32eaeea8 --- /dev/null +++ b/test/serialize.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct vertex_properties { + std::string name; + + template + void serialize(Archive & ar, const unsigned int version) { + ar & name; + } +}; + +struct edge_properties { + std::string name; + + template + void serialize(Archive & ar, const unsigned int version) { + ar & name; + } +}; + +using namespace boost; + +typedef adjacency_list Graph; + + +typedef adjacency_list Graph_no_edge_property; + +int main() +{ + { + std::ofstream ofs("./kevin-bacon2.dat"); + archive::text_oarchive oa(ofs); + Graph g; + oa << g; + + Graph_no_edge_property g_n; + oa << g_n; + } + + { + std::ifstream ifs("./kevin-bacon2.dat"); + archive::text_iarchive ia(ifs); + Graph g; + ia >> g; + + Graph_no_edge_property g_n; + ia >> g_n; + } + return 0; +}