[111] | 1 | // file : xsd/cxx/parser/exceptions.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_EXCEPTIONS_HXX |
---|
| 7 | #define XSD_CXX_PARSER_EXCEPTIONS_HXX |
---|
| 8 | |
---|
| 9 | #include <string> |
---|
| 10 | #include <vector> |
---|
| 11 | #include <ostream> |
---|
| 12 | |
---|
| 13 | #include <xsd/cxx/exceptions.hxx> // xsd::cxx::exception |
---|
| 14 | #include <xsd/cxx/ro-string.hxx> |
---|
| 15 | |
---|
| 16 | namespace xsd |
---|
| 17 | { |
---|
| 18 | namespace cxx |
---|
| 19 | { |
---|
| 20 | namespace parser |
---|
| 21 | { |
---|
| 22 | // |
---|
| 23 | // |
---|
| 24 | template <typename C> |
---|
| 25 | struct exception: xsd::cxx::exception |
---|
| 26 | { |
---|
| 27 | friend |
---|
| 28 | std::basic_ostream<C>& |
---|
| 29 | operator<< (std::basic_ostream<C>& os, const exception& e) |
---|
| 30 | { |
---|
| 31 | e.print (os); |
---|
| 32 | return os; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | protected: |
---|
| 36 | virtual void |
---|
| 37 | print (std::basic_ostream<C>&) const = 0; |
---|
| 38 | }; |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | // |
---|
| 42 | // |
---|
| 43 | struct severity |
---|
| 44 | { |
---|
| 45 | enum value |
---|
| 46 | { |
---|
| 47 | warning, |
---|
| 48 | error |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | severity (value v) : v_ (v) {} |
---|
| 52 | operator value () const { return v_; } |
---|
| 53 | |
---|
| 54 | private: |
---|
| 55 | value v_; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | template <typename C> |
---|
| 59 | struct error |
---|
| 60 | { |
---|
| 61 | error (cxx::parser::severity, |
---|
| 62 | const std::basic_string<C>& id, |
---|
| 63 | unsigned long line, |
---|
| 64 | unsigned long column, |
---|
| 65 | const std::basic_string<C>& message); |
---|
| 66 | |
---|
| 67 | cxx::parser::severity |
---|
| 68 | severity () const |
---|
| 69 | { |
---|
| 70 | return severity_; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | const std::basic_string<C>& |
---|
| 74 | id () const |
---|
| 75 | { |
---|
| 76 | return id_; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | unsigned long |
---|
| 80 | line () const |
---|
| 81 | { |
---|
| 82 | return line_; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | unsigned long |
---|
| 86 | column () const |
---|
| 87 | { |
---|
| 88 | return column_; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | const std::basic_string<C>& |
---|
| 92 | message () const |
---|
| 93 | { |
---|
| 94 | return message_; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | private: |
---|
| 98 | cxx::parser::severity severity_; |
---|
| 99 | std::basic_string<C> id_; |
---|
| 100 | unsigned long line_; |
---|
| 101 | unsigned long column_; |
---|
| 102 | std::basic_string<C> message_; |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | // See exceptions.ixx for operator<< (error). |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | // |
---|
| 109 | // |
---|
| 110 | template <typename C> |
---|
| 111 | struct diagnostics: std::vector<error<C> > |
---|
| 112 | { |
---|
| 113 | }; |
---|
| 114 | |
---|
| 115 | // See exceptions.ixx for operator<< (diagnostics). |
---|
| 116 | |
---|
| 117 | // |
---|
| 118 | // |
---|
| 119 | template <typename C> |
---|
| 120 | struct parsing: exception<C> |
---|
| 121 | { |
---|
| 122 | virtual |
---|
| 123 | ~parsing () throw (); |
---|
| 124 | |
---|
| 125 | parsing (); |
---|
| 126 | |
---|
| 127 | parsing (const cxx::parser::diagnostics<C>&); |
---|
| 128 | |
---|
| 129 | const cxx::parser::diagnostics<C>& |
---|
| 130 | diagnostics () const |
---|
| 131 | { |
---|
| 132 | return diagnostics_; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | virtual const char* |
---|
| 136 | what () const throw (); |
---|
| 137 | |
---|
| 138 | protected: |
---|
| 139 | virtual void |
---|
| 140 | print (std::basic_ostream<C>&) const; |
---|
| 141 | |
---|
| 142 | private: |
---|
| 143 | cxx::parser::diagnostics<C> diagnostics_; |
---|
| 144 | }; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | #include <xsd/cxx/parser/exceptions.txx> |
---|
| 150 | |
---|
| 151 | #endif // XSD_CXX_PARSER_EXCEPTIONS_HXX |
---|
| 152 | |
---|
| 153 | #include <xsd/cxx/parser/exceptions.ixx> |
---|