aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/parser/hello/driver.cxx
blob: 1b0ba5df81cd349524b444ddb3190125a81e99fd (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
73
74
75
76
77
78
79
80
81
// file      : examples/cxx/parser/hello/driver.cxx
// copyright : not copyrighted - public domain

#include <string>
#include <iostream>

#include "hello-pskel.hxx"

using namespace std;

struct hello_pimpl: hello_pskel
{
  virtual void
  greeting (const string& greeting)
  {
    greeting_ = greeting;
  }

  virtual void
  name (const string& name)
  {
    cout << greeting_ << ", " << name << "!" << endl;
  }

private:
  string greeting_;
};


int
main (int argc, char* argv[])
{
  const char* input;

  if (argc < 2)
  {
    input = "STDIN";
    cerr << "XML file not specified, reading from STDIN" << endl;
  }
  else
    input = argv[1];

  try
  {
    // Construct the parser.
    //
    xml_schema::string_pimpl string_p;
    hello_pimpl hello_p;

    hello_p.greeting_parser (string_p);
    hello_p.name_parser (string_p);


    // Parse the XML instance document. The second argument to the
    // document's constructor is the document's root element name.
    //
    xml_schema::document_pimpl doc_p (hello_p, "hello");

    hello_p.pre ();

    if (argc < 2)
      doc_p.parse (cin);
    else
      doc_p.parse (argv[1]);

    hello_p.post_hello ();
  }
  catch (const xml_schema::parser_exception& e)
  {
    cerr << input << ":" << e.line () << ":" << e.column () << ": "
         << e.text () << endl;
    return 1;
  }
  catch (const std::ios_base::failure&)
  {
    cerr << input << ": unable to open or read failure" << endl;
    return 1;
  }

  return 0;
}