aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/tree/binary/boost/driver.cxx
blob: df053b6a8921ded61d4a585c52b890a66348e909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// file      : examples/cxx/tree/binary/boost/driver.cxx
// copyright : not copyrighted - public domain

#include <memory>   // std::auto_ptr
#include <cstring>  // std::memcpy
#include <sstream>
#include <iostream>

// You can generate insertion/extraction code for other archive
// types (for example, binary, XML, etc).
//
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

#include "library.hxx"

using std::cerr;
using std::endl;

int
main (int argc, char* argv[])
{
  if (argc != 2)
  {
    cerr << "usage: " << argv[0] << " library.xml" << endl;
    return 1;
  }

  try
  {
    using namespace library;
    using boost::archive::text_oarchive;
    using boost::archive::text_iarchive;

    // Read in the file.
    //
    std::auto_ptr<catalog> c (catalog_ (argv[1]));

    cerr << *c << endl;

    // Save into a text archive.
    //
    std::ostringstream ostr;
    text_oarchive oa (ostr);
    xml_schema::ostream<text_oarchive> os (oa);

    os << *c;

    // Print the text representation.
    //
    std::string str (ostr.str ());

    cerr << endl
         << "text representation: " << endl
         << str << endl;

    // Load from a text archive.
    //
    std::istringstream istr (str);
    text_iarchive ia (istr);
    xml_schema::istream<text_iarchive> is (ia);

    std::auto_ptr<catalog> copy (new catalog (is));

    cerr << *copy << endl;
  }
  catch (const xml_schema::exception& e)
  {
    cerr << e << endl;
    return 1;
  }
}