demo_xml_load.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. //
  3. // demo_xml_load.cpp
  4. //
  5. // (C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com .
  6. // Use, modification and distribution is subject to the Boost Software
  7. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #include <iostream>
  10. #include <string>
  11. #include <boost/archive/tmpdir.hpp>
  12. #include <boost/archive/xml_iarchive.hpp>
  13. #include "demo_gps.hpp"
  14. void
  15. restore_schedule(bus_schedule &s, const char * filename)
  16. {
  17. // open the archive
  18. std::ifstream ifs(filename);
  19. assert(ifs.good());
  20. boost::archive::xml_iarchive ia(ifs);
  21. // restore the schedule from the archive
  22. ia >> BOOST_SERIALIZATION_NVP(s);
  23. }
  24. int main(int argc, char *argv[])
  25. {
  26. // make a new schedule
  27. bus_schedule new_schedule;
  28. std::string filename(boost::archive::tmpdir());
  29. filename += "/demo_save.xml";
  30. restore_schedule(new_schedule, filename.c_str());
  31. // and display
  32. std::cout << "\nrestored schedule";
  33. std::cout << new_schedule;
  34. return 0;
  35. }