| 1 | // file : xsd/cxx/parser/exceptions.ixx |
|---|
| 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 | #if defined(XSD_CXX_PARSER_USE_CHAR) || !defined(XSD_CXX_PARSER_USE_WCHAR) |
|---|
| 7 | |
|---|
| 8 | #ifndef XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR |
|---|
| 9 | #define XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR |
|---|
| 10 | |
|---|
| 11 | namespace xsd |
|---|
| 12 | { |
|---|
| 13 | namespace cxx |
|---|
| 14 | { |
|---|
| 15 | namespace parser |
|---|
| 16 | { |
|---|
| 17 | // error |
|---|
| 18 | // |
|---|
| 19 | inline |
|---|
| 20 | std::basic_ostream<char>& |
|---|
| 21 | operator<< (std::basic_ostream<char>& os, const error<char>& e) |
|---|
| 22 | { |
|---|
| 23 | return os << e.id () << ':' << e.line () << ':' << e.column () |
|---|
| 24 | << (e.severity () == severity::error |
|---|
| 25 | ? " error: " |
|---|
| 26 | : " warning: ") << e.message (); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | // diagnostics |
|---|
| 31 | // |
|---|
| 32 | inline |
|---|
| 33 | std::basic_ostream<char>& |
|---|
| 34 | operator<< (std::basic_ostream<char>& os, const diagnostics<char>& d) |
|---|
| 35 | { |
|---|
| 36 | for (diagnostics<char>::const_iterator b (d.begin ()), i (b); |
|---|
| 37 | i != d.end (); |
|---|
| 38 | ++i) |
|---|
| 39 | { |
|---|
| 40 | if (i != b) |
|---|
| 41 | os << "\n"; |
|---|
| 42 | |
|---|
| 43 | os << *i; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | return os; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | // parsing |
|---|
| 50 | // |
|---|
| 51 | template<> |
|---|
| 52 | inline |
|---|
| 53 | void parsing<char>:: |
|---|
| 54 | print (std::basic_ostream<char>& os) const |
|---|
| 55 | { |
|---|
| 56 | if (diagnostics_.empty ()) |
|---|
| 57 | os << "instance document parsing failed"; |
|---|
| 58 | else |
|---|
| 59 | os << diagnostics_; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | #endif // XSD_CXX_PARSER_EXCEPTIONS_IXX_CHAR |
|---|
| 66 | #endif // XSD_CXX_PARSER_USE_CHAR |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | #if defined(XSD_CXX_PARSER_USE_WCHAR) || !defined(XSD_CXX_PARSER_USE_CHAR) |
|---|
| 70 | |
|---|
| 71 | #ifndef XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR |
|---|
| 72 | #define XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR |
|---|
| 73 | |
|---|
| 74 | namespace xsd |
|---|
| 75 | { |
|---|
| 76 | namespace cxx |
|---|
| 77 | { |
|---|
| 78 | namespace parser |
|---|
| 79 | { |
|---|
| 80 | // error |
|---|
| 81 | // |
|---|
| 82 | inline |
|---|
| 83 | std::basic_ostream<wchar_t>& |
|---|
| 84 | operator<< (std::basic_ostream<wchar_t>& os, const error<wchar_t>& e) |
|---|
| 85 | { |
|---|
| 86 | return os << e.id () << L':' << e.line () << L':' << e.column () |
|---|
| 87 | << (e.severity () == severity::error |
|---|
| 88 | ? L" error: " |
|---|
| 89 | : L" warning: ") << e.message (); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | // diagnostics |
|---|
| 93 | // |
|---|
| 94 | inline |
|---|
| 95 | std::basic_ostream<wchar_t>& |
|---|
| 96 | operator<< (std::basic_ostream<wchar_t>& os, |
|---|
| 97 | const diagnostics<wchar_t>& d) |
|---|
| 98 | { |
|---|
| 99 | for (diagnostics<wchar_t>::const_iterator b (d.begin ()), i (b); |
|---|
| 100 | i != d.end (); |
|---|
| 101 | ++i) |
|---|
| 102 | { |
|---|
| 103 | if (i != b) |
|---|
| 104 | os << L"\n"; |
|---|
| 105 | |
|---|
| 106 | os << *i; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | return os; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | // parsing |
|---|
| 113 | // |
|---|
| 114 | template<> |
|---|
| 115 | inline |
|---|
| 116 | void parsing<wchar_t>:: |
|---|
| 117 | print (std::basic_ostream<wchar_t>& os) const |
|---|
| 118 | { |
|---|
| 119 | if (diagnostics_.empty ()) |
|---|
| 120 | os << L"instance document parsing failed"; |
|---|
| 121 | else |
|---|
| 122 | os << diagnostics_; |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | #endif // XSD_CXX_PARSER_EXCEPTIONS_IXX_WCHAR |
|---|
| 129 | #endif // XSD_CXX_PARSER_USE_WCHAR |
|---|