Boost logo

Boost Users :

From: n.torrey.pines (n.torrey.pines_at_[hidden])
Date: 2007-02-22 16:02:51


Hi

The logic I want to implement is:
* b contains a
* when saving b, save a, followed by other data
* when loading b, load a into a temporary, if it matches b.m_a, load
other data

Would you expect the following code to work?

class b {
     a m_a; // a is serializable
     vector<int> m_v; // other data

     template<class Archive>
     void save(Archive& ar, const unsigned version) const {
         ar & m_a;
         ar & m_v;
     }

     template<class Archive>
     void load(Archive& ar, const unsigned version) {
         a tmp;
         ar & tmp;
         if(tmp == m_a) ar & m_v;
     }

     // ...
};

Now, what if b is derived from a instead of containing it? Would this work?

class b : public a {
     vector<int> m_v; // other data

     template<class Archive>
     void save(Archive& ar, const unsigned version) const {
         ar & boost::serialization::base_object<a>(*this);
         ar & m_v;
     }

     template<class Archive>
     void load(Archive& ar, const unsigned version) {
         a tmp;
         ar & tmp;
         if(tmp == static_cast< const a& >(*this)) ar & m_v;
     }

     // ...
};

Thanks!


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