#include "data.hpp" #include #include #include #include #include #include #include #include template void save(const T &s, const char * filename) { // make an archive std::ofstream ofs(filename); boost::archive::binary_oarchive oa(ofs); oa << s; } template void restore(T &s, const char * filename) { // open the archive std::ifstream ifs(filename); boost::archive::binary_iarchive ia(ifs); // restore the linee from the archive ia >> s; } int main(int, char **) { try { Point p1(1,1); Line l(p1,boost::shared_ptr(new Point3D(10,3,42))); std::cerr << "l=" << l << std::endl; // Save the line std::string filename(boost::archive::tmpdir()); filename += "/demofile"; save(l, filename.c_str()); // load the line back from the file Line l1; restore(l1, filename.c_str()); std::cerr << "loaded: l1=" << l1 << std::endl; Point3D p3d(1,9,-24); save(p3d, "punkt"); boost::shared_ptr sharepoint; // NO EXCEPTION ??? restore(sharepoint, "demofile"); std::cerr << "gelesen: "<< std::endl; sharepoint->dump(std::cerr); boost::shared_ptr sp3d(new Point3D(1,9,-24)); save(sp3d, "punkt2"); restore(sharepoint, "punkt2"); std::cerr << std::endl << "read: "<< std::endl; sharepoint->dump(std::cerr); std::cerr << std::endl; } catch(const std::exception &e) { std::cerr << "Exception: " << e.what() << std::endl; } return 0; }