aboutsummaryrefslogtreecommitdiff
path: root/examples/cxx/hybrid/evolution/passthrough/unknown-type-pimpl.cxx
blob: 950580f40a04c23ea2a94bb13a5754a0a1c534c6 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
// file      : examples/cxx/hybrid/evolution/passthrough/unknown-type-pimpl.cxx
// copyright : not copyrighted - public domain

#include <memory> // std::auto_ptr

// Include transform-pimpl.hxx (which includes unknown-type-pimpl.hxx)
// instead of unknown-type-pimpl.hxx.
//
#include "transform-pimpl.hxx"

namespace transform
{
  void unknown_type_pimpl::
  _pre ()
  {
    unknown_type_base_pimpl::_pre ();

    // Set the element name and namespace.
    //
    unknown_type* obj = unknown_type_base_pimpl_state_.unknown_type_;

    obj->element_name (
      xml::qname (_context ().element_namespace (),
                  _context ().element_name ()));

    // Initialize the current element.
    //
    cur_ = &obj->content ();
  }

  void unknown_type_pimpl::
  _start_any_element (const xml_schema::ro_string& ns,
                      const xml_schema::ro_string& name,
                      const char*)
  {
    // Create a new child element and add it to cur_.
    //
    std::auto_ptr<xml::element> e (
      new xml::element (xml::qname (ns, name), cur_));

    cur_->children ().push_back (e.get ());
    cur_ = e.get ();
    e.release ();
  }

  void unknown_type_pimpl::
  _end_any_element (const xml_schema::ro_string&,
                    const xml_schema::ro_string&)
  {
    // Make the parent of cur_ the new cur_.
    //
    cur_ = cur_->parent ();
  }

  void unknown_type_pimpl::
  _any_attribute (const xml_schema::ro_string& ns,
                  const xml_schema::ro_string& name,
                  const xml_schema::ro_string& value)
  {
    // Add a new attribute to cur_.
    //
    cur_->attributes ()[xml::qname (ns, name)] = value;
  }

  void unknown_type_pimpl::
  _any_characters (const xml_schema::ro_string& s)
  {
    // Set the character value of cur_.
    //
    cur_->value (s);
  }

  //
  // Low-level content callbacks.
  //

  void unknown_type_pimpl::
  _start_element (const xml_schema::ro_string& ns,
                  const xml_schema::ro_string& name,
                  const char* type)
  {
    // If this is one of the elements from transformation_type, then
    // delegate it to our base. Otherwise, forward it to the wildcard
    // callback.
    //
    if (name == "description" &&
        ns == "http://www.codesynthesis.com/transform")
    {
      unknown_type_base_pimpl::_start_element (ns, name, type);
    }
    else
    {
      _context ().start_wildcard_content ();
      _start_any_element (ns, name, type);
    }
  }


  void unknown_type_pimpl::
  _end_element (const xml_schema::ro_string& ns,
                const xml_schema::ro_string& name)
  {
    // If this is one of the elements from transformation_type, then
    // delegate it to our base. Otherwise, forward it to the wildcard
    // callback.
    //
    if (name == "description" &&
        ns == "http://www.codesynthesis.com/transform")
    {
      unknown_type_base_pimpl::_end_element (ns, name);
    }
    else
      _end_any_element (ns, name);
  }

  void unknown_type_pimpl::
  _attribute (const xml_schema::ro_string& ns,
              const xml_schema::ro_string& name,
              const xml_schema::ro_string& value)
  {
    // If this is one of the elements from transformation_type, then
    // delegate it to our base. Otherwise, forward it to the wildcard
    // callback.
    //
    if (name == "name" && ns.empty ())
    {
      unknown_type_base_pimpl::_attribute (ns, name, value);
    }
    else
      _any_attribute (ns, name, value);
  }

  void unknown_type_pimpl::
  _characters (const xml_schema::ro_string& s)
  {
    // transformation_type has no character content so forward this
    // straight to the wildcard callback.
    //
    _any_characters (s);
  }
}