demo_trivial_archive.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  2. //
  3. // demo_trivial_archive.cpp
  4. //
  5. // (C) Copyright 2009 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 <cstddef> // std::size_t
  10. #include <boost/mpl/bool.hpp>
  11. /////////////////////////////////////////////////////////////////////////
  12. // class trivial_oarchive
  13. class trivial_oarchive {
  14. public:
  15. //////////////////////////////////////////////////////////
  16. // public interface used by programs that use the
  17. // serialization library
  18. typedef boost::mpl::bool_<true> is_saving;
  19. typedef boost::mpl::bool_<false> is_loading;
  20. template<class T> void register_type(){}
  21. template<class T> trivial_oarchive & operator<<(const T & t){
  22. return *this;
  23. }
  24. template<class T> trivial_oarchive & operator&(const T & t){
  25. return *this << t;
  26. }
  27. void save_binary(void *address, std::size_t count){};
  28. };
  29. #include "demo_gps.hpp"
  30. int main(int argc, char *argv[])
  31. {
  32. // make the schedule
  33. bus_schedule schedule;
  34. // fill in the data
  35. // make a few stops
  36. bus_stop *bs0 = new bus_stop_corner(
  37. gps_position(34, 135, 52.560f),
  38. gps_position(134, 22, 78.30f),
  39. "24th Street", "10th Avenue"
  40. );
  41. bus_stop *bs1 = new bus_stop_corner(
  42. gps_position(35, 137, 23.456f),
  43. gps_position(133, 35, 54.12f),
  44. "State street", "Cathedral Vista Lane"
  45. );
  46. bus_stop *bs2 = new bus_stop_destination(
  47. gps_position(35, 136, 15.456f),
  48. gps_position(133, 32, 15.300f),
  49. "White House"
  50. );
  51. bus_stop *bs3 = new bus_stop_destination(
  52. gps_position(35, 134, 48.789f),
  53. gps_position(133, 32, 16.230f),
  54. "Lincoln Memorial"
  55. );
  56. // make a routes
  57. bus_route route0;
  58. route0.append(bs0);
  59. route0.append(bs1);
  60. route0.append(bs2);
  61. // add trips to schedule
  62. schedule.append("bob", 6, 24, &route0);
  63. schedule.append("bob", 9, 57, &route0);
  64. schedule.append("alice", 11, 02, &route0);
  65. // make aother routes
  66. bus_route route1;
  67. route1.append(bs3);
  68. route1.append(bs2);
  69. route1.append(bs1);
  70. // add trips to schedule
  71. schedule.append("ted", 7, 17, &route1);
  72. schedule.append("ted", 9, 38, &route1);
  73. schedule.append("alice", 11, 47, &route1);
  74. // display the complete schedule
  75. trivial_oarchive ta;
  76. ta << schedule;
  77. delete bs0;
  78. delete bs1;
  79. delete bs2;
  80. delete bs3;
  81. return 0;
  82. }