Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions include/boost/graph/adj_list_serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
#include <boost/config.hpp>
#include <boost/detail/workaround.hpp>

#include <boost/serialization/collections_save_imp.hpp>
#include <boost/serialization/collections_load_imp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/core/serialization.hpp>
#include <boost/type_traits/integral_constant.hpp>

namespace boost
{
Expand All @@ -29,13 +28,16 @@ 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.
// Specializing tracking_level_impl (not tracking_level) avoids including
// <boost/serialization/tracking.hpp>. boost::integral_constant carries the
// integral_c_tag the archive expects.
template < class T > struct tracking_level_impl;
template < class OEL, class VL, class D, class VP, class EP, class GP,
class EL >
struct tracking_level< boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL > >
struct tracking_level_impl<
const boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL > >
: boost::integral_constant< int, 0 /* track_never */ >
{
typedef mpl::integral_c_tag tag;
typedef mpl::int_< track_never > type;
BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
};

template < class Archive, class OEL, class VL, class D, class VP, class EP,
Expand All @@ -50,29 +52,29 @@ namespace serialization

const auto V = num_vertices(graph);
const auto E = num_edges(graph);
ar << BOOST_SERIALIZATION_NVP(V);
ar << BOOST_SERIALIZATION_NVP(E);
ar << BOOST_NVP(V);
ar << BOOST_NVP(E);

// assign indices to vertices
std::unordered_map< Vertex, Vertex > indices(V);
Vertex num = 0;
BGL_FORALL_VERTICES_T(v, graph, Graph)
{
indices[v] = num++;
ar << serialization::make_nvp(
ar << boost::make_nvp(
"vertex_property", get(vertex_all_t(), graph, v));
}

// write edges
BGL_FORALL_EDGES_T(e, graph, Graph)
{
ar << serialization::make_nvp("u", indices[source(e, graph)]);
ar << serialization::make_nvp("v", indices[target(e, graph)]);
ar << serialization::make_nvp(
ar << boost::make_nvp("u", indices[source(e, graph)]);
ar << boost::make_nvp("v", indices[target(e, graph)]);
ar << boost::make_nvp(
"edge_property", get(edge_all_t(), graph, e));
}

ar << serialization::make_nvp(
ar << boost::make_nvp(
"graph_property", get_property(graph, graph_all_t()));
}

Expand All @@ -89,35 +91,35 @@ namespace serialization
using VertexSizeType = typename graph_traits< Graph >::vertices_size_type;

VertexSizeType V;
ar >> BOOST_SERIALIZATION_NVP(V);
ar >> BOOST_NVP(V);

VertexSizeType E;
ar >> BOOST_SERIALIZATION_NVP(E);
ar >> BOOST_NVP(E);

std::vector< Vertex > verts(V);
size_t i = 0;
while (V-- > 0)
{
const auto v = add_vertex(graph);
verts[i++] = v;
ar >> serialization::make_nvp(
ar >> boost::make_nvp(
"vertex_property", get(vertex_all_t(), graph, v));
}

while (E-- > 0)
{
Vertex u;
Vertex v;
ar >> BOOST_SERIALIZATION_NVP(u);
ar >> BOOST_SERIALIZATION_NVP(v);
ar >> BOOST_NVP(u);
ar >> BOOST_NVP(v);

Edge e;
bool inserted;
boost::tie(e, inserted) = add_edge(verts[u], verts[v], graph);
ar >> serialization::make_nvp(
ar >> boost::make_nvp(
"edge_property", get(edge_all_t(), graph, e));
}
ar >> serialization::make_nvp(
ar >> boost::make_nvp(
"graph_property", get_property(graph, graph_all_t()));
}

Expand All @@ -127,7 +129,7 @@ namespace serialization
boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL >& graph,
const unsigned int file_version)
{
boost::serialization::split_free(ar, graph, file_version);
boost::core::split_free(ar, graph, file_version);
}

} // serialization
Expand Down
12 changes: 8 additions & 4 deletions include/boost/pending/property_serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#define BOOST_PROPERTY_SERIALIZE_HPP

#include <boost/pending/property.hpp>
#include <boost/core/nvp.hpp>

// Only the Parallel BGL (MPI) specializations below need Boost.Serialization,
// so keep its header out of the default build.
#ifdef BOOST_GRAPH_USE_MPI
#include <boost/serialization/is_bitwise_serializable.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/nvp.hpp>
#endif

namespace boost
{
Expand All @@ -22,8 +26,8 @@ template < class Archive, class Tag, class T, class Base >
void serialize(
Archive& ar, property< Tag, T, Base >& prop, const unsigned int /*version*/)
{
ar& serialization::make_nvp("property_value", prop.m_value);
ar& serialization::make_nvp("property_base", prop.m_base);
ar& boost::make_nvp("property_value", prop.m_value);
ar& boost::make_nvp("property_base", prop.m_base);
}

#ifdef BOOST_GRAPH_USE_MPI
Expand Down
5 changes: 5 additions & 0 deletions test/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/tracking.hpp>

struct vertex_properties
{
Expand Down Expand Up @@ -47,6 +48,10 @@ typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties,

typedef graph_traits< Graph >::vertex_descriptor vd_type;

static_assert(boost::serialization::tracking_level< Graph >::value
== boost::serialization::track_never,
"adjacency_list tracking_level must be track_never");

typedef adjacency_list< vecS, vecS, undirectedS, vertex_properties >
Graph_no_edge_property;

Expand Down
Loading