|
Boost Users : |
Subject: Re: [Boost-users] Yet another issue with BGL Deserialization
From: Robert Ramey (ramey_at_[hidden])
Date: 2016-08-28 12:42:37
On 8/28/16 3:41 AM, giacomo_at_[hidden] wrote:
>
>
> I'm trying to both serialize and deserialize the data in a graph format.
> The definition of my graph is the following one.
>
> #include <boost/graph/adjacency_list.hpp>
> #include <boost/graph/directed_graph.hpp>
> #include <boost/graph/adj_list_serialize.hpp>
> #include <boost/archive/binary_oarchive.hpp>
> #include <boost/archive/binary_iarchive.hpp>
> #include <boost/serialization/string.hpp>
> #include <boost/serialization/binary_object.hpp>
>
> class VFull {
> public:
> VFull();
> unsigned int id, hash, year;
> std::string ip, organization;
> VFull(unsigned int id, unsigned int hash, unsigned int year,
> std::string ip, std::string organization);
> template<class Archive> void serialize(Archive & ar, const unsigned
> int version);
> };
>
> class EFull {
> public:
> EFull();
> template<class Archive> void serialize(Archive & ar, const unsigned
> int version);
> };
>
> class GFull {
> public:
> template<class Archive> void serialize(Archive & ar, const unsigned
> int version);
> };
>
>
> //Defining the graph data structure. Using the vecS specification
> typedef boost::adjacency_list<boost::vecS, boost::vecS,
> boost::directedS,VFull,EFull,GFull> graph_t;
> typedef boost::graph_traits<graph_t>::vertex_descriptor
> result_vertex_descriptor;
> typedef boost::graph_traits<graph_t>::edge_descriptor
> result_edge_descriptor;
>
> It seems to me that I have no problems in the serialization process,
> while I have some issues in the deserialization part. In fact, I have no
> linking errors until this piece of code is added to my source:
>
> #include <iomanip>
> #include <iostream>
> #include <fstream>
> {
> std::ifstream file(path,std::ios_base::binary);
> boost::archive::binary_iarchive store{file};
> store >> graph; // Deserialization part that triggers the error
> }
>
Consider making a smaller/simpler test program to verify that things
work independently of the graph library. In other words, what happens
with the following example:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/binary_object.hpp>
#include "full.hpp" // VFull etc...
#include "full.cpp" // VFull::void serialize(Archive &ar, const unsigned
int version {...} definitions
#include <fstream>
int main(){
VFull vf{...}; // create test instance of VFull
// ... same for EFull, GFull
{
std::ifstream f(path,std::ios_base::binary);
boost::archive::binary_oarchive oa{f};
oa << vf << ef << gf;
// exiting context closes archive and files
}
{
std::ifstream f(path,std::ios_base::binary);
boost::archive::binary_iarchive ia{f};
VFull in_vf; // create test instance of VFull
// ... same for EFull, GFull
ia >> in_vf >> in_ef >> in_gf;
if(in_vf != vf)
exit(1);
// same for ef and gf
// exiting context closes archive and files
}
exit (0);
}
Making this test program will exclude the graph library from the
equation. So if you have problems getting this to compile, link or run
correctly, we can focus exclusively on the serialization library usage.
If this does work as expected, one can delve into the serialization
implementation in the graph library
Robert Ramey
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net