Boost logo

Boost Users :

Subject: [Boost-users] [serialization - newbie] serializing multiple objects in one archive
From: Soumen (soumen78_at_[hidden])
Date: 2009-08-04 02:04:57


Hi,

I've to serialize and deserialize multiple objects. Can I serialize them in
one archive and deserialize from the same correctly? Say something like
following is my save/restore function:

void save(boost::archive::binary_oarchive &archive)
{
    string version = tool.getversion();
    MyData *data = MyData::instance();
    MyDifferentData *differentData = MyDifferentData::instance();

    if (data && differentData) {
         archive << version;
         archive << data;
         archive << differentData;
    }
}

void restore(boost::archive::binary_iarchive &archive)
{
    string version = tool.getversion();
    string serializedToolversion;

    MyData::cleanup();
    MyDifferentData::cleanup();

    archive >> serializedToolVersion;

    if (version == serializedToolVersion) {
         archive >> (MyData *) MyData::instance();
         archive >> (MyDifferentData *) MyDifferentData::instance();
    }
}

Or do I need to serialize each of these into different archives?

Regards,
~ Soumen

-- 
View this message in context: http://www.nabble.com/-serialization---newbie--serializing-multiple-objects-in-one-archive-tp24802722p24802722.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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