Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/serialization/example/demo_xml_save.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

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