class DerivedConcrete : public BaseAbstract
{
std::vector<double> rateVec;
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(rateVec);
}
public:
DerivedConcrete(double rate) {rateVec.push_back(rate);}
DerivedConcrete(){}
virtual ~DerivedConcrete(){}
void setRate(double rate){ rateVec.push_back(rate); };
double getRate(int idx){ return rateVec[idx]; };
};
class AnyClass
{
friend class boost::serialization::access;
BaseAbstract* rate;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(rate);
}
public:
AnyClass(BaseAbstract* rateInput){ rate = rateInput; };
AnyClass() {};
setRate(BaseAbstract* rateInput){ rate = rateInput; };
};
int main(int argc, char* argv[])
{
try {
DerivedConcrete* fr = new DerivedConcrete(12.12);
fr->setRate(14.5);
AnyClass ac;
ac.setRate(fr);
std::ofstream ofs("AC.xml");
assert(ofs.good());
boost::archive::xml_oarchive oa(ofs);
oa << BOOST_SERIALIZATION_NVP(ac);
ofs.close();
}
catch (boost::archive::xml_archive_exception ex)
{
std::cerr << " X " << ex.what() << std::endl;
}
catch (boost::archive::archive_exception ex)
{
std::cerr << " A " <<
ex.what() << std::endl;
}
catch (std::exception ex)
{
std::cerr << " E " << ex.what() << std::endl;
}
catch (...)
{
std::cerr << "Unknown Exception " << std::endl;
}
return 0;
}