root/win32/xsd-3.1.0-i686/libxsd/xsd/cxx/tree/exceptions.ixx @ 124

Revision 111, 11.4 kB (checked in by mido, 16 years ago)

pridana knihovna XSD (a jeji chlebodarkyne XERCES), v ramci Win32 zprovoznen priklad tests/test_xsd_hello.cxx

Line 
1// file      : xsd/cxx/tree/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_TREE_USE_CHAR) || !defined(XSD_CXX_TREE_USE_WCHAR)
7
8#ifndef XSD_CXX_TREE_EXCEPTIONS_IXX_CHAR
9#define XSD_CXX_TREE_EXCEPTIONS_IXX_CHAR
10
11namespace xsd
12{
13  namespace cxx
14  {
15    namespace tree
16    {
17
18      // error
19      //
20      inline
21      std::basic_ostream<char>&
22      operator<< (std::basic_ostream<char>& os, const error<char>& e)
23      {
24        return os << e.id () << ':' << e.line () << ':' << e.column ()
25                  << (e.severity () == severity::error
26                      ? " error: "
27                      : " warning: ") << e.message ();
28      }
29
30
31      // diagnostics
32      //
33      inline
34      std::basic_ostream<char>&
35      operator<< (std::basic_ostream<char>& os, const diagnostics<char>& d)
36      {
37        for (diagnostics<char>::const_iterator b (d.begin ()), i (b);
38             i != d.end ();
39             ++i)
40        {
41          if (i != b)
42            os << "\n";
43
44          os << *i;
45        }
46
47        return os;
48      }
49
50
51      // parsing
52      //
53      template<>
54      inline
55      void parsing<char>::
56      print (std::basic_ostream<char>& os) const
57      {
58        if (diagnostics_.empty ())
59          os << "instance document parsing failed";
60        else
61          os << diagnostics_;
62      }
63
64
65      // expected_element
66      //
67      template<>
68      inline
69      void expected_element<char>::
70      print (std::basic_ostream<char>& os) const
71      {
72        os << "expected element '"
73           << namespace_ () << (namespace_ ().empty () ? "" : "#")
74           << name () << "'";
75      }
76
77
78      // unexpected_element
79      //
80      template<>
81      inline
82      void unexpected_element<char>::
83      print (std::basic_ostream<char>& os) const
84      {
85        if (!expected_name ().empty ())
86        {
87          os << "expected element '"
88             << expected_namespace ()
89             << (expected_namespace ().empty () ? "" : "#")
90             << expected_name ()
91             << "' instead of '"
92             << encountered_namespace ()
93             << (encountered_namespace ().empty () ? "" : "#")
94             << encountered_name () << "'";
95        }
96        else
97        {
98          os << "unexpected element '"
99             << encountered_namespace ()
100             << (encountered_namespace ().empty () ? "" : "#")
101             << encountered_name () << "'";
102        }
103      }
104
105
106      // expected_attribute
107      //
108      template<>
109      inline
110      void expected_attribute<char>::
111      print (std::basic_ostream<char>& os) const
112      {
113        os << "expected attribute '"
114           << namespace_ () << (namespace_ ().empty () ? "" : "#")
115           << name () << "'";
116      }
117
118
119      // unexpected_enumerator
120      //
121      template<>
122      inline
123      void unexpected_enumerator<char>::
124      print (std::basic_ostream<char>& os) const
125      {
126        os << "unexpected enumerator '" << enumerator () << "'";
127      }
128
129
130      // expected_text_content
131      //
132      template<>
133      inline
134      void expected_text_content<char>::
135      print (std::basic_ostream<char>& os) const
136      {
137        os << "expected text content";
138      }
139
140
141      // no_type_info
142      //
143      template<>
144      inline
145      void no_type_info<char>::
146      print (std::basic_ostream<char>& os) const
147      {
148        os << "no type information available for type '"
149           << type_namespace () << (type_namespace ().empty () ? "" : "#")
150           << type_name () << "'";
151      }
152
153
154      // not_derived
155      //
156      template<>
157      inline
158      void not_derived<char>::
159      print (std::basic_ostream<char>& os) const
160      {
161        os << "type '"
162           << derived_type_namespace ()
163           << (derived_type_namespace ().empty () ? "" : "#")
164           << derived_type_name ()
165           << "' is not derived from '"
166           << base_type_namespace ()
167           << (base_type_namespace ().empty () ? "" : "#")
168           << base_type_name () << "'";
169      }
170
171
172      // duplicate_id
173      //
174      template<>
175      inline
176      void duplicate_id<char>::
177      print (std::basic_ostream<char>& os) const
178      {
179        os << "ID '" << id () << "' already exist";
180      }
181
182
183      // serialization
184      //
185      template<>
186      inline
187      void serialization<char>::
188      print (std::basic_ostream<char>& os) const
189      {
190        if (diagnostics_.empty ())
191          os << "serialization failed";
192        else
193          os << diagnostics_;
194      }
195
196
197      // no_namespace_mapping
198      //
199      template<>
200      inline
201      void no_namespace_mapping<char>::
202      print (std::basic_ostream<char>& os) const
203      {
204        os << "no mapping provided for namespace '"
205           << namespace_ () << "'";
206      }
207
208
209      // no_prefix_mapping
210      //
211      template<>
212      inline
213      void no_prefix_mapping<char>::
214      print (std::basic_ostream<char>& os) const
215      {
216        os << "no mapping provided for namespace prefix '"
217           << prefix () << "'";
218      }
219
220
221      // xsi_already_in_use
222      //
223      template<>
224      inline
225      void xsi_already_in_use<char>::
226      print (std::basic_ostream<char>& os) const
227      {
228        os << "namespace prefix 'xsi' is already in use and no "
229           << "user-defined mapping has been provided for namespace "
230           << "'http://www.w3.org/2001/XMLSchema-instance'";
231      }
232
233
234      // bounds
235      //
236      template<>
237      inline
238      void bounds<char>::
239      print (std::basic_ostream<char>& os) const
240      {
241        os << "buffer boundary rules have been violated";
242      }
243    }
244  }
245}
246
247#endif // XSD_CXX_TREE_EXCEPTIONS_IXX_CHAR
248#endif // XSD_CXX_TREE_USE_CHAR
249
250
251#if defined(XSD_CXX_TREE_USE_WCHAR) || !defined(XSD_CXX_TREE_USE_CHAR)
252
253#ifndef XSD_CXX_TREE_EXCEPTIONS_IXX_WCHAR
254#define XSD_CXX_TREE_EXCEPTIONS_IXX_WCHAR
255
256namespace xsd
257{
258  namespace cxx
259  {
260    namespace tree
261    {
262      // error
263      //
264      inline
265      std::basic_ostream<wchar_t>&
266      operator<< (std::basic_ostream<wchar_t>& os, const error<wchar_t>& e)
267      {
268        return os << e.id () << L':' << e.line () << L':' << e.column ()
269                  << (e.severity () == severity::error
270                      ? L" error: "
271                      : L" warning: ") << e.message ();
272      }
273
274
275      // diagnostics
276      //
277      inline
278      std::basic_ostream<wchar_t>&
279      operator<< (std::basic_ostream<wchar_t>& os,
280                  const diagnostics<wchar_t>& d)
281      {
282        for (diagnostics<wchar_t>::const_iterator b (d.begin ()), i (b);
283             i != d.end ();
284             ++i)
285        {
286          if (i != b)
287            os << L"\n";
288
289          os << *i;
290        }
291
292        return os;
293      }
294
295
296      // parsing
297      //
298      template<>
299      inline
300      void parsing<wchar_t>::
301      print (std::basic_ostream<wchar_t>& os) const
302      {
303        if (diagnostics_.empty ())
304          os << L"instance document parsing failed";
305        else
306          os << diagnostics_;
307      }
308
309
310      // expected_element
311      //
312      template<>
313      inline
314      void expected_element<wchar_t>::
315      print (std::basic_ostream<wchar_t>& os) const
316      {
317        os << L"expected element '"
318           << namespace_ () << (namespace_ ().empty () ? L"" : L"#")
319           << name () << L"'";
320      }
321
322
323      // unexpected_element
324      //
325      template<>
326      inline
327      void unexpected_element<wchar_t>::
328      print (std::basic_ostream<wchar_t>& os) const
329      {
330        if (!expected_name ().empty ())
331        {
332          os << L"expected element '"
333             << expected_namespace ()
334             << (expected_namespace ().empty () ? L"" : L"#")
335             << expected_name ()
336             << L"' instead of '"
337             << encountered_namespace ()
338             << (encountered_namespace ().empty () ? L"" : L"#")
339             << encountered_name () << L"'";
340        }
341        else
342        {
343          os << L"unexpected element '"
344             << encountered_namespace ()
345             << (encountered_namespace ().empty () ? L"" : L"#")
346             << encountered_name () << L"'";
347        }
348      }
349
350
351      // expected_attribute
352      //
353      template<>
354      inline
355      void expected_attribute<wchar_t>::
356      print (std::basic_ostream<wchar_t>& os) const
357      {
358        os << L"expected attribute '"
359           << namespace_ () << (namespace_ ().empty () ? L"" : L"#")
360           << name () << L"'";
361      }
362
363
364      // unexpected_enumerator
365      //
366      template<>
367      inline
368      void unexpected_enumerator<wchar_t>::
369      print (std::basic_ostream<wchar_t>& os) const
370      {
371        os << L"unexpected enumerator '" << enumerator () << L"'";
372      }
373
374
375      // expected_text_content
376      //
377      template<>
378      inline
379      void expected_text_content<wchar_t>::
380      print (std::basic_ostream<wchar_t>& os) const
381      {
382        os << L"expected text content";
383      }
384
385
386      // no_type_info
387      //
388      template<>
389      inline
390      void no_type_info<wchar_t>::
391      print (std::basic_ostream<wchar_t>& os) const
392      {
393        os << L"no type information available for type '"
394           << type_namespace () << (type_namespace ().empty () ? L"" : L"#")
395           << type_name () << L"'";
396      }
397
398
399      // not_derived
400      //
401      template<>
402      inline
403      void not_derived<wchar_t>::
404      print (std::basic_ostream<wchar_t>& os) const
405      {
406        os << L"type '"
407           << derived_type_namespace ()
408           << (derived_type_namespace ().empty () ? L"" : L"#")
409           << derived_type_name ()
410           << L"' is not derived from '"
411           << base_type_namespace ()
412           << (base_type_namespace ().empty () ? L"" : L"#")
413           << base_type_name () << L"'";
414      }
415
416
417      // duplicate_id
418      //
419      template<>
420      inline
421      void duplicate_id<wchar_t>::
422      print (std::basic_ostream<wchar_t>& os) const
423      {
424        os << L"ID '" << id () << L"' already exist";
425      }
426
427
428      // serialization
429      //
430      template<>
431      inline
432      void serialization<wchar_t>::
433      print (std::basic_ostream<wchar_t>& os) const
434      {
435        if (diagnostics_.empty ())
436          os << L"serialization failed";
437        else
438          os << diagnostics_;
439      }
440
441
442      // no_namespace_mapping
443      //
444      template<>
445      inline
446      void no_namespace_mapping<wchar_t>::
447      print (std::basic_ostream<wchar_t>& os) const
448      {
449        os << L"no mapping provided for namespace '"
450           << namespace_ () << L"'";
451      }
452
453
454      // no_prefix_mapping
455      //
456      template<>
457      inline
458      void no_prefix_mapping<wchar_t>::
459      print (std::basic_ostream<wchar_t>& os) const
460      {
461        os << L"no mapping provided for namespace prefix '"
462           << prefix () << L"'";
463      }
464
465
466      // xsi_already_in_use
467      //
468      template<>
469      inline
470      void xsi_already_in_use<wchar_t>::
471      print (std::basic_ostream<wchar_t>& os) const
472      {
473        os << L"namespace prefix 'xsi' is already in use and no "
474           << L"user-defined mapping has been provided for namespace "
475           << L"'http://www.w3.org/2001/XMLSchema-instance'";
476      }
477
478
479      // bounds
480      //
481      template<>
482      inline
483      void bounds<wchar_t>::
484      print (std::basic_ostream<wchar_t>& os) const
485      {
486        os << L"buffer boundary rules have been violated";
487      }
488    }
489  }
490}
491
492#endif // XSD_CXX_TREE_EXCEPTIONS_IXX_WCHAR
493#endif // XSD_CXX_TREE_USE_WCHAR
Note: See TracBrowser for help on using the browser.