I'm trying to serialize a struct which contains two or more other types of sturct. But it seems that serialization does not work. Below is sampel code :
/SimpleData.hpp
//SimpleData.cppCode:#include <boost/serialization/access.hpp> #include <boost/serialization/base_object.hpp> #include <boost/serialization/optional.hpp> #include <boost/serialization/map.hpp> #include <boost/serialization/shared_ptr.hpp> namespace A { Struct Name { std::string firstname; std::string lastname; template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & firstname; ar & lastname; } }; Struct Address { std::string street; std::string city; template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & street; ar & city; } } Struct FullData { public : FullData(); FullData(const parameter_strings & parms); virtual ~FullData(); boost::optional<Name> nameinfo; // instance of struct Name boost::optional<Address> addressinfo; // instance of struct Address std::string country; int pincode; private : friend class boost::serialization::access; template<class Archive> void serialize(Archive &ar, const unsigned int version) { ar & nameinfo; // are these enough to take of serialization of Name and ar & addressinfo; // Address ar & country;; ar & pincode; } }; }
#include "SimpleData.hpp"
FullData::FullData()
{
}
I'm not sure if above code would serialize properly or not. Whats wrong with above code.Code:FullData::~FullData() { } FullData::~FullData(const parameter_strings & parms) { // impelmentation } BOOST_CLASS_EXPORT_IMPLEMENT(FullData); BOOST_CLASS_IMPLEMENTATION(FullData),boost::serialization::object_serializable); BOOST_CLASS_TRACKING(FullData),boost::serialization::track_never);
Do i need to add below code also for serialization of Name and Address struct in SimpleData.cpp file
ThanksCode:BOOST_CLASS_EXPORT_IMPLEMENT(Name); BOOST_CLASS_IMPLEMENTATION(name,boost::serialization::object_serializable); BOOST_CLASS_TRACKING(Name,boost::serialization::track_never); BOOST_CLASS_EXPORT_IMPLEMENT(Address); BOOST_CLASS_IMPLEMENTATION(Address,boost::serialization::object_serializable); BOOST_CLASS_TRACKING(Address,boost::serialization::track_never);




Reply With Quote
