aboutsummaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/parser/document.txx
blob: 3c2557473a8c31265d2203de2bbecd600312c242 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// file      : xsd/cxx/parser/document.txx
// copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <cassert>

#include <xsd/cxx/parser/schema-exceptions.hxx>

namespace xsd
{
  namespace cxx
  {
    namespace parser
    {
      // document
      //
      template <typename C>
      document<C>::
      ~document ()
      {
      }

      template <typename C>
      document<C>::
      document (parser_base<C>& root,
                const std::basic_string<C>& ns,
                const std::basic_string<C>& name)
          : root_ (&root), ns_ (ns), name_ (name), depth_ (0)
      {
      }

      template <typename C>
      document<C>::
      document ()
          : root_ (0), depth_ (0)
      {
      }

      template <typename C>
      void document<C>::
      start_element (const ro_string<C>& ns,
                     const ro_string<C>& name,
                     const ro_string<C>* type)
      {
        if (depth_++ > 0)
        {
          if (root_)
            root_->_start_element (ns, name, type);
        }
        else
        {
          root_ = start_root_element (ns, name, type);

          if (root_)
          {
            // pre () is called by the user.
            //
            root_->_pre_impl ();
          }
        }
      }

      template <typename C>
      void document<C>::
      end_element (const ro_string<C>& ns, const ro_string<C>& name)
      {
        assert (depth_ > 0);

        if (--depth_ > 0)
        {
          if (root_)
            root_->_end_element (ns, name);
        }
        else
        {
          if (root_)
          {
	    root_->_post_impl ();
            //
            // post() is called by the user.
          }

          end_root_element (ns, name, root_);
        }
      }

      template <typename C>
      void document<C>::
      attribute (const ro_string<C>& ns,
                 const ro_string<C>& name,
                 const ro_string<C>& value)
      {
        if (root_)
          root_->_attribute (ns, name, value);
      }

      template <typename C>
      void document<C>::
      characters (const ro_string<C>& s)
      {
        if (root_)
          root_->_characters (s);
      }

      template <typename C>
      parser_base<C>* document<C>::
      start_root_element (const ro_string<C>& ns,
                          const ro_string<C>& name,
                          const ro_string<C>*)
      {
        if (name_ == name && ns_ == ns)
        {
          return root_;
        }
        else
          throw expected_element<C> (ns_, name_, ns, name);
      }

      template <typename C>
      void document<C>::
      end_root_element (const ro_string<C>&,
                        const ro_string<C>&,
                        parser_base<C>*)
      {
      }
    }
  }
}