epoc32/include/stdapis/boost/graph/adj_list_serialize.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/graph/adj_list_serialize.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,114 @@
     1.4 +//=======================================================================
     1.5 +// Copyright 2005 Jeremy G. Siek
     1.6 +// Authors: Jeremy G. Siek
     1.7 +//
     1.8 +// Distributed under the Boost Software License, Version 1.0. (See
     1.9 +// accompanying file LICENSE_1_0.txt or copy at
    1.10 +// http://www.boost.org/LICENSE_1_0.txt)
    1.11 +//=======================================================================
    1.12 +#ifndef ADJ_LIST_SERIALIZE_HPP
    1.13 +#define ADJ_LIST_SERIALIZE_HPP
    1.14 +
    1.15 +#include <boost/graph/adjacency_list.hpp>
    1.16 +#include <boost/pending/property_serialize.hpp>
    1.17 +#include <boost/config.hpp>
    1.18 +#include <boost/detail/workaround.hpp>
    1.19 +
    1.20 +#include <boost/serialization/collections_save_imp.hpp>
    1.21 +#include <boost/serialization/collections_load_imp.hpp>
    1.22 +#include <boost/serialization/split_free.hpp>
    1.23 +
    1.24 +namespace boost { 
    1.25 +
    1.26 +namespace serialization {
    1.27 +
    1.28 +// Turn off tracking for adjacency_list. It's not polymorphic, and we
    1.29 +// need to do this to enable saving of non-const adjacency lists.
    1.30 +template<class OEL, class VL, class D, class VP, class EP, class GP, class EL>
    1.31 +struct tracking_level<boost::adjacency_list<OEL,VL,D,VP,EP,GP,EL> > {
    1.32 +  typedef mpl::integral_c_tag tag;
    1.33 +  typedef mpl::int_<track_never> type;
    1.34 +  BOOST_STATIC_CONSTANT(int, value = tracking_level::type::value);
    1.35 +};
    1.36 +
    1.37 +template<class Archive, class OEL, class VL, class D, 
    1.38 +     class VP, class EP, class GP, class EL>
    1.39 +inline void save(
    1.40 +    Archive & ar,
    1.41 +    const boost::adjacency_list<OEL,VL,D,VP,EP,GP,EL> &graph,
    1.42 +    const unsigned int /* file_version */
    1.43 +){
    1.44 +  typedef adjacency_list<OEL,VL,D,VP,EP,GP,EL> Graph;
    1.45 +  typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    1.46 +
    1.47 +  int V = num_vertices(graph);
    1.48 +  int E = num_edges(graph);
    1.49 +  ar << BOOST_SERIALIZATION_NVP(V);
    1.50 +  ar << BOOST_SERIALIZATION_NVP(E);
    1.51 +
    1.52 +  // assign indices to vertices
    1.53 +  std::map<Vertex,int> indices;
    1.54 +  int num = 0;
    1.55 +  typename graph_traits<Graph>::vertex_iterator vi;
    1.56 +  for (vi = vertices(graph).first; vi != vertices(graph).second; ++vi) {
    1.57 +    indices[*vi] = num++;
    1.58 +    ar << serialization::make_nvp("vertex_property", get(vertex_all_t(), graph, *vi) );
    1.59 +  }
    1.60 +  
    1.61 +  // write edges
    1.62 +  typename graph_traits<Graph>::edge_iterator ei;
    1.63 +  for (ei = edges(graph).first; ei != edges(graph).second; ++ei){
    1.64 +    ar << serialization::make_nvp("u" , indices[source(*ei,graph)]);
    1.65 +    ar << serialization::make_nvp("v" , indices[target(*ei,graph)]);
    1.66 +    ar << serialization::make_nvp("edge_property", get(edge_all_t(), graph, *ei) );
    1.67 +  }
    1.68 +}
    1.69 +
    1.70 +
    1.71 +template<class Archive, class OEL, class VL, class D,
    1.72 +     class VP, class EP, class GP, class EL>
    1.73 +inline void load(
    1.74 +    Archive & ar,
    1.75 +    boost::adjacency_list<OEL,VL,D,VP,EP,GP,EL> &graph,
    1.76 +    const unsigned int /* file_version */
    1.77 +){
    1.78 +  typedef adjacency_list<OEL,VL,D,VP,EP,GP,EL> Graph;
    1.79 +  typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    1.80 +  typedef typename graph_traits<Graph>::edge_descriptor Edge;
    1.81 +
    1.82 +  unsigned int V;
    1.83 +  ar >> BOOST_SERIALIZATION_NVP(V);
    1.84 +  unsigned int E;
    1.85 +  ar >> BOOST_SERIALIZATION_NVP(E);
    1.86 +  
    1.87 +  std::vector<Vertex> verts(V);
    1.88 +  int i = 0;
    1.89 +  while(V-- > 0){
    1.90 +    Vertex v = add_vertex(graph);
    1.91 +    verts[i++] = v;
    1.92 +    ar >> serialization::make_nvp("vertex_property", get(vertex_all_t(), graph, v) );
    1.93 +  }
    1.94 +  while(E-- > 0){
    1.95 +    int u; int v;
    1.96 +    ar >> BOOST_SERIALIZATION_NVP(u);
    1.97 +    ar >> BOOST_SERIALIZATION_NVP(v);
    1.98 +    Edge e; bool inserted;
    1.99 +    tie(e,inserted) = add_edge(verts[u], verts[v], graph);
   1.100 +    ar >> serialization::make_nvp("edge_property", get(edge_all_t(), graph, e) );
   1.101 +  }
   1.102 +}
   1.103 +
   1.104 +template<class Archive, class OEL, class VL, class D, class VP, class EP, class GP, class EL>
   1.105 +inline void serialize(
   1.106 +    Archive & ar,
   1.107 +    boost::adjacency_list<OEL,VL,D,VP,EP,GP,EL> &graph,
   1.108 +    const unsigned int file_version
   1.109 +){
   1.110 +    boost::serialization::split_free(ar, graph, file_version);
   1.111 +}
   1.112 +
   1.113 +}//serialization
   1.114 +}//boost
   1.115 +
   1.116 +
   1.117 +#endif // ADJ_LIST_SERIALIZE_HPP