| 1 | // file : xsd/cxx/parser/document.txx |
|---|
| 2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
|---|
| 3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
|---|
| 4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
|---|
| 5 | |
|---|
| 6 | #include <cassert> |
|---|
| 7 | |
|---|
| 8 | #include <xsd/cxx/parser/schema-exceptions.hxx> |
|---|
| 9 | |
|---|
| 10 | namespace xsd |
|---|
| 11 | { |
|---|
| 12 | namespace cxx |
|---|
| 13 | { |
|---|
| 14 | namespace parser |
|---|
| 15 | { |
|---|
| 16 | // document |
|---|
| 17 | // |
|---|
| 18 | template <typename C> |
|---|
| 19 | document<C>:: |
|---|
| 20 | ~document () |
|---|
| 21 | { |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | template <typename C> |
|---|
| 25 | document<C>:: |
|---|
| 26 | document (parser_base<C>& root, |
|---|
| 27 | const std::basic_string<C>& ns, |
|---|
| 28 | const std::basic_string<C>& name) |
|---|
| 29 | : root_ (&root), ns_ (ns), name_ (name), depth_ (0) |
|---|
| 30 | { |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | template <typename C> |
|---|
| 34 | document<C>:: |
|---|
| 35 | document () |
|---|
| 36 | : root_ (0), depth_ (0) |
|---|
| 37 | { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | template <typename C> |
|---|
| 41 | void document<C>:: |
|---|
| 42 | start_element (const ro_string<C>& ns, |
|---|
| 43 | const ro_string<C>& name, |
|---|
| 44 | const ro_string<C>* type) |
|---|
| 45 | { |
|---|
| 46 | if (depth_++ > 0) |
|---|
| 47 | { |
|---|
| 48 | if (root_) |
|---|
| 49 | root_->_start_element (ns, name, type); |
|---|
| 50 | } |
|---|
| 51 | else |
|---|
| 52 | { |
|---|
| 53 | root_ = start_root_element (ns, name, type); |
|---|
| 54 | |
|---|
| 55 | if (root_) |
|---|
| 56 | { |
|---|
| 57 | // pre () is called by the user. |
|---|
| 58 | // |
|---|
| 59 | root_->_pre_impl (); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | template <typename C> |
|---|
| 65 | void document<C>:: |
|---|
| 66 | end_element (const ro_string<C>& ns, const ro_string<C>& name) |
|---|
| 67 | { |
|---|
| 68 | assert (depth_ > 0); |
|---|
| 69 | |
|---|
| 70 | if (--depth_ > 0) |
|---|
| 71 | { |
|---|
| 72 | if (root_) |
|---|
| 73 | root_->_end_element (ns, name); |
|---|
| 74 | } |
|---|
| 75 | else |
|---|
| 76 | { |
|---|
| 77 | if (root_) |
|---|
| 78 | { |
|---|
| 79 | root_->_post_impl (); |
|---|
| 80 | // |
|---|
| 81 | // post() is called by the user. |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | end_root_element (ns, name, root_); |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | template <typename C> |
|---|
| 89 | void document<C>:: |
|---|
| 90 | attribute (const ro_string<C>& ns, |
|---|
| 91 | const ro_string<C>& name, |
|---|
| 92 | const ro_string<C>& value) |
|---|
| 93 | { |
|---|
| 94 | if (root_) |
|---|
| 95 | root_->_attribute (ns, name, value); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | template <typename C> |
|---|
| 99 | void document<C>:: |
|---|
| 100 | characters (const ro_string<C>& s) |
|---|
| 101 | { |
|---|
| 102 | if (root_) |
|---|
| 103 | root_->_characters (s); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | template <typename C> |
|---|
| 107 | parser_base<C>* document<C>:: |
|---|
| 108 | start_root_element (const ro_string<C>& ns, |
|---|
| 109 | const ro_string<C>& name, |
|---|
| 110 | const ro_string<C>*) |
|---|
| 111 | { |
|---|
| 112 | if (name_ == name && ns_ == ns) |
|---|
| 113 | { |
|---|
| 114 | return root_; |
|---|
| 115 | } |
|---|
| 116 | else |
|---|
| 117 | throw expected_element<C> (ns_, name_, ns, name); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | template <typename C> |
|---|
| 121 | void document<C>:: |
|---|
| 122 | end_root_element (const ro_string<C>&, |
|---|
| 123 | const ro_string<C>&, |
|---|
| 124 | parser_base<C>*) |
|---|
| 125 | { |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | } |
|---|