Search code examples
c++serializationboostboost-serializationboost-graph

Serializing a class containing as a member a boost adjacency_list using boost::serialization


I have a class which has a member graph which is a boost adjacency_list boost::adjacency_list<setS, setS, undirectedS, AINGNodeData, AINGEdgeData> graph;, would it be directly serializable ? How can I serialize it ? I use boost:serialization.


Solution

  • It should not be an issue. The class boost::adjacency_list<....> is serializable. See the file

    #include <boost/graph/adj_list_serialize.hpp>
    

    Simply make sure your properties AINGNodeData, AINGEdgeData are serializable, the library should take care of the rest. If properties are simple types or containers (e.g. std::string), it would be enough to make sure the proper serialization header is included, e.g.

    #include <boost/serialization/string.hpp>
    #include <boost/serialization/vector.hpp>
    

    Good luck.