[111] | 1 | // file : xsd/cxx/parser/document.hxx |
---|
| 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 | #ifndef XSD_CXX_PARSER_DOCUMENT_HXX |
---|
| 7 | #define XSD_CXX_PARSER_DOCUMENT_HXX |
---|
| 8 | |
---|
| 9 | #include <string> |
---|
| 10 | #include <cstddef> // std::size_t |
---|
| 11 | |
---|
| 12 | #include <xsd/cxx/ro-string.hxx> |
---|
| 13 | #include <xsd/cxx/parser/elements.hxx> |
---|
| 14 | |
---|
| 15 | namespace xsd |
---|
| 16 | { |
---|
| 17 | namespace cxx |
---|
| 18 | { |
---|
| 19 | namespace parser |
---|
| 20 | { |
---|
| 21 | // If you want to use a different underlying XML parser, all you |
---|
| 22 | // need to do is to route events to this interface. |
---|
| 23 | // |
---|
| 24 | template <typename C> |
---|
| 25 | class document |
---|
| 26 | { |
---|
| 27 | public: |
---|
| 28 | virtual |
---|
| 29 | ~document (); |
---|
| 30 | |
---|
| 31 | document (parser_base<C>& root, |
---|
| 32 | const std::basic_string<C>& ns, |
---|
| 33 | const std::basic_string<C>& name); |
---|
| 34 | |
---|
| 35 | public: |
---|
| 36 | // The type argument is a type name and namespace from the |
---|
| 37 | // xsi:type attribute in the form "<name> <namespace>" with |
---|
| 38 | // the space and namespace part absent if the type does not |
---|
| 39 | // have a namespace or 0 if xsi:type is not present. |
---|
| 40 | // |
---|
| 41 | void |
---|
| 42 | start_element (const ro_string<C>& ns, |
---|
| 43 | const ro_string<C>& name, |
---|
| 44 | const ro_string<C>* type); |
---|
| 45 | |
---|
| 46 | void |
---|
| 47 | end_element (const ro_string<C>& ns, const ro_string<C>& name); |
---|
| 48 | |
---|
| 49 | void |
---|
| 50 | attribute (const ro_string<C>& ns, |
---|
| 51 | const ro_string<C>& name, |
---|
| 52 | const ro_string<C>& value); |
---|
| 53 | |
---|
| 54 | void |
---|
| 55 | characters (const ro_string<C>&); |
---|
| 56 | |
---|
| 57 | protected: |
---|
| 58 | document (); |
---|
| 59 | |
---|
| 60 | // This function is called to obtain the root element type parser. |
---|
| 61 | // If the returned pointed is 0 then the whole document content |
---|
| 62 | // is ignored. |
---|
| 63 | // |
---|
| 64 | virtual parser_base<C>* |
---|
| 65 | start_root_element (const ro_string<C>& ns, |
---|
| 66 | const ro_string<C>& name, |
---|
| 67 | const ro_string<C>* type); |
---|
| 68 | |
---|
| 69 | // This function is called to indicate the completion of document |
---|
| 70 | // parsing. The parser argument contains the pointer returned by |
---|
| 71 | // start_root_element. |
---|
| 72 | // |
---|
| 73 | virtual void |
---|
| 74 | end_root_element (const ro_string<C>& ns, |
---|
| 75 | const ro_string<C>& name, |
---|
| 76 | parser_base<C>* parser); |
---|
| 77 | |
---|
| 78 | private: |
---|
| 79 | parser_base<C>* root_; |
---|
| 80 | std::basic_string<C> ns_; |
---|
| 81 | std::basic_string<C> name_; |
---|
| 82 | std::size_t depth_; |
---|
| 83 | }; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | #include <xsd/cxx/parser/document.txx> |
---|
| 89 | |
---|
| 90 | #endif // XSD_CXX_PARSER_DOCUMENT_HXX |
---|