Search code examples
c++serializationboost-graph

How to serialize type boost::labeled_graph


I've got a boost:labeled_graph object type which does not seem to have necessary functions for serialization.

    error: ‘class boost::labeled_graph<boost::adjacency_list<boost::listS, boost::listS,
 boost::undirectedS, Space, spaceEdge, graphProperties, boost::listS>, std::basic_string<char,
 std::char_traits<char>, std::allocator<char> >, boost::defaultS>’ has no member named
 ‘serialize’

Any way of serializing labeled_graphs to file?


Solution

  • I've not seen before, but labeled_graph looks like a thin wrapper around another graph of your choosing, in this case you chose adjacency_list by the looks of that error. There's boost support for serializing adjacency lists via <graph/adj_list_serialize.hpp>, so it looks like you can use the free function serializing quite sensibly with this, something like:

    template<class Archive>
    inline void serialize(
        Archive & ar, 
        my_grap_typedef & g, 
        const unsigned int /*file_version*/
    ){
      ar & g.graph()
    }