Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:42:49

0001 //=======================================================================
0002 // Copyright 2005 Jeremy G. Siek
0003 // Authors: Jeremy G. Siek
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //=======================================================================
0009 #ifndef BOOST_GRAPH_ADJ_LIST_SERIALIZE_HPP
0010 #define BOOST_GRAPH_ADJ_LIST_SERIALIZE_HPP
0011 
0012 #include <boost/graph/adjacency_list.hpp>
0013 #include <boost/graph/iteration_macros.hpp>
0014 #include <boost/pending/property_serialize.hpp>
0015 #include <boost/config.hpp>
0016 #include <boost/detail/workaround.hpp>
0017 
0018 #include <boost/serialization/collections_save_imp.hpp>
0019 #include <boost/serialization/collections_load_imp.hpp>
0020 #include <boost/serialization/split_free.hpp>
0021 
0022 namespace boost
0023 {
0024 
0025 namespace serialization
0026 {
0027 
0028     // Turn off tracking for adjacency_list. It's not polymorphic, and we
0029     // need to do this to enable saving of non-const adjacency lists.
0030     template < class OEL, class VL, class D, class VP, class EP, class GP,
0031         class EL >
0032     struct tracking_level< boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL > >
0033     {
0034         typedef mpl::integral_c_tag tag;
0035         typedef mpl::int_< track_never > type;
0036         BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
0037     };
0038 
0039     template < class Archive, class OEL, class VL, class D, class VP, class EP,
0040         class GP, class EL >
0041     inline void save(Archive& ar,
0042         const boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL >& graph,
0043         const unsigned int /* file_version */
0044     )
0045     {
0046         typedef adjacency_list< OEL, VL, D, VP, EP, GP, EL > Graph;
0047         typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
0048 
0049         int V = num_vertices(graph);
0050         int E = num_edges(graph);
0051         ar << BOOST_SERIALIZATION_NVP(V);
0052         ar << BOOST_SERIALIZATION_NVP(E);
0053 
0054         // assign indices to vertices
0055         std::map< Vertex, int > indices;
0056         int num = 0;
0057         BGL_FORALL_VERTICES_T(v, graph, Graph)
0058         {
0059             indices[v] = num++;
0060             ar << serialization::make_nvp(
0061                 "vertex_property", get(vertex_all_t(), graph, v));
0062         }
0063 
0064         // write edges
0065         BGL_FORALL_EDGES_T(e, graph, Graph)
0066         {
0067             ar << serialization::make_nvp("u", indices[source(e, graph)]);
0068             ar << serialization::make_nvp("v", indices[target(e, graph)]);
0069             ar << serialization::make_nvp(
0070                 "edge_property", get(edge_all_t(), graph, e));
0071         }
0072 
0073         ar << serialization::make_nvp(
0074             "graph_property", get_property(graph, graph_all_t()));
0075     }
0076 
0077     template < class Archive, class OEL, class VL, class D, class VP, class EP,
0078         class GP, class EL >
0079     inline void load(
0080         Archive& ar, boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL >& graph,
0081         const unsigned int /* file_version */
0082     )
0083     {
0084         typedef adjacency_list< OEL, VL, D, VP, EP, GP, EL > Graph;
0085         typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
0086         typedef typename graph_traits< Graph >::edge_descriptor Edge;
0087 
0088         unsigned int V;
0089         ar >> BOOST_SERIALIZATION_NVP(V);
0090         unsigned int E;
0091         ar >> BOOST_SERIALIZATION_NVP(E);
0092 
0093         std::vector< Vertex > verts(V);
0094         int i = 0;
0095         while (V-- > 0)
0096         {
0097             Vertex v = add_vertex(graph);
0098             verts[i++] = v;
0099             ar >> serialization::make_nvp(
0100                 "vertex_property", get(vertex_all_t(), graph, v));
0101         }
0102         while (E-- > 0)
0103         {
0104             int u;
0105             int v;
0106             ar >> BOOST_SERIALIZATION_NVP(u);
0107             ar >> BOOST_SERIALIZATION_NVP(v);
0108             Edge e;
0109             bool inserted;
0110             boost::tie(e, inserted) = add_edge(verts[u], verts[v], graph);
0111             ar >> serialization::make_nvp(
0112                 "edge_property", get(edge_all_t(), graph, e));
0113         }
0114         ar >> serialization::make_nvp(
0115             "graph_property", get_property(graph, graph_all_t()));
0116     }
0117 
0118     template < class Archive, class OEL, class VL, class D, class VP, class EP,
0119         class GP, class EL >
0120     inline void serialize(Archive& ar,
0121         boost::adjacency_list< OEL, VL, D, VP, EP, GP, EL >& graph,
0122         const unsigned int file_version)
0123     {
0124         boost::serialization::split_free(ar, graph, file_version);
0125     }
0126 
0127 } // serialization
0128 } // boost
0129 
0130 #endif // BOOST_GRAPH_ADJ_LIST_SERIALIZE_HPP