Boost logo

Boost Users :

Subject: [Boost-users] Archive reload
From: Ferllings (ferllings_at_[hidden])
Date: 2009-02-26 03:25:47


Hello,

I have a Class A with string attributes that I serialize in XML format:

Class A {
public:
   string _nom;
   string _prenom;
   template<class Archive>
   void serialize(Archive& ar, const unsigned in version){
     ar & boost::serialization::make_nvp("Nom", _nom);
     ar & boost::serialization::make_nvp("Prenom", _prenom);
   }
}

The object is correctly saved using this code:

A _a;

void save() const
{
     ...
     oTextArchive::xml_oarchive oTextArchive(ofile);
     oTextArchive << make_nvp("A", _a);
     ...
}

But I want to reload the object, the A attributes aren't updated and
keep the previous values:

void load()
{
     ...
     iTextArchive::xml_oarchive iTextArchive(ifile);
     iTextArchive >> make_nvp("A", _a);
     ...
}

The only way I found to reload my object is to use an temporary object:

void load()
{
     ...
     A _tmp;
     iTextArchive::xml_oarchive iTextArchive(ifile);
     iTextArchive >> make_nvp("A", _tmp);
     _a = _tmp;
     ...
}

Why can't I update the object directly?

Thanks for your help.


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