demo_xml_save.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. //
  3. // demo_xml_save.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_oarchive.hpp>
  13. #include "demo_gps.hpp"
  14. void save_schedule(const bus_schedule &s, const char * filename){
  15. // make an archive
  16. std::ofstream ofs(filename);
  17. assert(ofs.good());
  18. boost::archive::xml_oarchive oa(ofs);
  19. oa << BOOST_SERIALIZATION_NVP(s);
  20. }
  21. int main(int argc, char *argv[])
  22. {
  23. // make the schedule
  24. bus_schedule original_schedule;
  25. // fill in the data
  26. // make a few stops
  27. bus_stop *bs0 = new bus_stop_corner(
  28. gps_position(34, 135, 52.560f),
  29. gps_position(134, 22, 78.30f),
  30. "24th Street", "10th Avenue"
  31. );
  32. bus_stop *bs1 = new bus_stop_corner(
  33. gps_position(35, 137, 23.456f),
  34. gps_position(133, 35, 54.12f),
  35. "State street", "Cathedral Vista Lane"
  36. );
  37. bus_stop *bs2 = new bus_stop_destination(
  38. gps_position(35, 136, 15.456f),
  39. gps_position(133, 32, 15.300f),
  40. "White House"
  41. );
  42. bus_stop *bs3 = new bus_stop_destination(
  43. gps_position(35, 134, 48.789f),
  44. gps_position(133, 32, 16.230f),
  45. "Lincoln Memorial"
  46. );
  47. // make a routes
  48. bus_route route0;
  49. route0.append(bs0);
  50. route0.append(bs1);
  51. route0.append(bs2);
  52. // add trips to schedule
  53. original_schedule.append("bob", 6, 24, &route0);
  54. original_schedule.append("bob", 9, 57, &route0);
  55. original_schedule.append("alice", 11, 02, &route0);
  56. // make aother routes
  57. bus_route route1;
  58. route1.append(bs3);
  59. route1.append(bs2);
  60. route1.append(bs1);
  61. // add trips to schedule
  62. original_schedule.append("ted", 7, 17, &route1);
  63. original_schedule.append("ted", 9, 38, &route1);
  64. original_schedule.append("alice", 11, 47, &route1);
  65. // display the complete schedule
  66. std::cout << "original schedule";
  67. std::cout << original_schedule;
  68. std::string filename(boost::archive::tmpdir());
  69. filename += "/demo_save.xml";
  70. // save the schedule
  71. save_schedule(original_schedule, filename.c_str());
  72. delete bs0;
  73. delete bs1;
  74. delete bs2;
  75. delete bs3;
  76. return 0;
  77. }