Line data Source code
1 : // file : xsd/cxx/tree/exceptions.hxx
2 : // copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
3 : // license : GNU GPL v2 + exceptions; see accompanying LICENSE file
4 :
5 : /**
6 : * @file
7 : *
8 : * @brief Contains exception definitions for the C++/Tree mapping.
9 : *
10 : * This is an internal header and is included by the generated code.
11 : * You normally should not include it directly.
12 : *
13 : */
14 :
15 : #ifndef XSD_CXX_TREE_EXCEPTIONS_HXX
16 : #define XSD_CXX_TREE_EXCEPTIONS_HXX
17 :
18 : #include <string>
19 : #include <vector>
20 : #include <ostream>
21 :
22 : #include <xsd/cxx/exceptions.hxx> // xsd::cxx::exception
23 :
24 : namespace xsd
25 : {
26 : namespace cxx
27 : {
28 : /**
29 : * @brief C++/Tree mapping runtime namespace.
30 : *
31 : * This is an internal namespace and normally should not be referenced
32 : * directly. Instead you should use the aliases for types in this
33 : * namespaces that are created in the generated code.
34 : *
35 : */
36 : namespace tree
37 : {
38 : /**
39 : * @brief Root of the C++/Tree %exception hierarchy.
40 : *
41 : * You can catch this %exception in order to handle all C++/Tree
42 : * errors.
43 : *
44 : * @nosubgrouping
45 : */
46 : template <typename C>
47 : class exception: public xsd::cxx::exception
48 : {
49 : public:
50 : /**
51 : * @brief Stream insertion operator for %exception.
52 : */
53 : friend
54 : std::basic_ostream<C>&
55 : operator<< (std::basic_ostream<C>& os, const exception& e)
56 : {
57 : e.print (os);
58 : return os;
59 : }
60 :
61 : protected:
62 : //@cond
63 :
64 : virtual void
65 : print (std::basic_ostream<C>&) const = 0;
66 :
67 : //@endcond
68 : };
69 :
70 :
71 : /**
72 : * @brief Error %severity.
73 : *
74 : * @nosubgrouping
75 : */
76 : class severity
77 : {
78 : public:
79 : /**
80 : * @brief Underlying enum type.
81 : */
82 : enum value
83 : {
84 : /**
85 : * @brief Indicates the warning condition.
86 : */
87 : warning,
88 :
89 : /**
90 : * @brief Indicates the %error condition.
91 : */
92 : error
93 : };
94 :
95 : /**
96 : * @brief Initialize an instance with the underlying enum value.
97 : *
98 : * @param v An underlying enum value.
99 : */
100 0 : severity (value v) : v_ (v) {}
101 :
102 : /**
103 : * @brief Implicitly convert the instance to the underlying enum
104 : * value.
105 : *
106 : * @return The underlying enum value.
107 : */
108 0 : operator value () const { return v_; }
109 :
110 : private:
111 : value v_;
112 : };
113 :
114 : /**
115 : * @brief Error condition.
116 : *
117 : * @nosubgrouping
118 : */
119 : template <typename C>
120 : class error
121 : {
122 : public:
123 : /**
124 : * @brief Initialize an instance with %error description.
125 : *
126 : * @param s An %error %severity.
127 : * @param res_id A resource %id where the %error occurred.
128 : * @param line A line number where the %error occurred.
129 : * @param column A column number where the %error occurred.
130 : * @param message A message describing the %error.
131 : */
132 : error (tree::severity s,
133 : const std::basic_string<C>& res_id,
134 : unsigned long line,
135 : unsigned long column,
136 : const std::basic_string<C>& message);
137 :
138 : /**
139 : * @brief Get %error %severity.
140 : *
141 : * @return The %severity of this %error.
142 : */
143 : tree::severity
144 0 : severity () const
145 : {
146 0 : return severity_;
147 : }
148 :
149 : /**
150 : * @brief Get resource %id.
151 : *
152 : * @return The %id of the resource where this %error occurred.
153 : */
154 : const std::basic_string<C>&
155 0 : id () const
156 : {
157 0 : return id_;
158 : }
159 :
160 : /**
161 : * @brief Get %error line.
162 : *
163 : * @return The line number where this %error occurred.
164 : */
165 : unsigned long
166 0 : line () const
167 : {
168 0 : return line_;
169 : }
170 :
171 : /**
172 : * @brief Get %error column.
173 : *
174 : * @return The column number where this %error occurred.
175 : */
176 : unsigned long
177 0 : column () const
178 : {
179 0 : return column_;
180 : }
181 :
182 : /**
183 : * @brief Get %error message.
184 : *
185 : * @return The message for this %error.
186 : */
187 : const std::basic_string<C>&
188 0 : message () const
189 : {
190 0 : return message_;
191 : }
192 :
193 : //@cond
194 :
195 : // Default c-tor that shouldn't be. Needed when we completely
196 : // instantiate std::vector in diagnostics below.
197 : //
198 : error ();
199 :
200 : //@endcond
201 :
202 :
203 : private:
204 : tree::severity severity_;
205 : std::basic_string<C> id_;
206 : unsigned long line_;
207 : unsigned long column_;
208 : std::basic_string<C> message_;
209 : };
210 :
211 : // See exceptions.ixx for operator<< (error).
212 :
213 :
214 : /**
215 : * @brief List of %error conditions.
216 : *
217 : * @nosubgrouping
218 : */
219 : template <typename C>
220 : class diagnostics: public std::vector<error<C> >
221 : {
222 : };
223 :
224 : // See exceptions.ixx for operator<< (diagnostics).
225 :
226 : /**
227 : * @brief Exception indicating a %parsing failure.
228 : *
229 : * @nosubgrouping
230 : */
231 : template <typename C>
232 : class parsing: public exception<C>
233 : {
234 : public:
235 : virtual
236 : ~parsing () throw ();
237 :
238 : /**
239 : * @brief Default constructor.
240 : */
241 : parsing ();
242 :
243 : /**
244 : * @brief Initialize an instance with a %list of %error conditions.
245 : *
246 : * @param d A %list of %error conditions.
247 : */
248 : parsing (const tree::diagnostics<C>& d);
249 :
250 : public:
251 : /**
252 : * @brief Get the %list of %error conditions.
253 : *
254 : * @return The %list of %error conditions.
255 : */
256 : const tree::diagnostics<C>&
257 : diagnostics () const
258 : {
259 : return diagnostics_;
260 : }
261 :
262 : /**
263 : * @brief Get %exception description.
264 : *
265 : * @return A C %string describing the %exception.
266 : */
267 : virtual const char*
268 : what () const throw ();
269 :
270 : protected:
271 : //@cond
272 :
273 : virtual void
274 : print (std::basic_ostream<C>&) const;
275 :
276 : //@endcond
277 :
278 : private:
279 : tree::diagnostics<C> diagnostics_;
280 : };
281 :
282 :
283 : /**
284 : * @brief Exception indicating that an expected element was not
285 : * encountered.
286 : *
287 : * @nosubgrouping
288 : */
289 : template <typename C>
290 : class expected_element: public exception<C>
291 : {
292 : public:
293 : virtual
294 : ~expected_element () throw ();
295 :
296 : /**
297 : * @brief Initialize an instance with the expected element
298 : * description.
299 : *
300 : * @param name A name of the expected element.
301 : * @param ns A namespace of the expected element.
302 : */
303 : expected_element (const std::basic_string<C>& name,
304 : const std::basic_string<C>& ns);
305 :
306 :
307 : public:
308 : /**
309 : * @brief Get the name of the expected element.
310 : *
311 : * @return The name of the expected element.
312 : */
313 : const std::basic_string<C>&
314 : name () const
315 : {
316 : return name_;
317 : }
318 :
319 : /**
320 : * @brief Get the namespace of the expected element.
321 : *
322 : * @return The namespace of the expected element.
323 : */
324 : const std::basic_string<C>&
325 : namespace_ () const
326 : {
327 : return namespace__;
328 : }
329 :
330 : /**
331 : * @brief Get %exception description.
332 : *
333 : * @return A C %string describing the %exception.
334 : */
335 : virtual const char*
336 : what () const throw ();
337 :
338 : protected:
339 : //@cond
340 :
341 : virtual void
342 : print (std::basic_ostream<C>&) const;
343 :
344 : //@endcond
345 :
346 : private:
347 : std::basic_string<C> name_;
348 : std::basic_string<C> namespace__;
349 : };
350 :
351 :
352 : /**
353 : * @brief Exception indicating that an unexpected element was
354 : * encountered.
355 : *
356 : * @nosubgrouping
357 : */
358 : template <typename C>
359 : class unexpected_element: public exception<C>
360 : {
361 : public:
362 : virtual
363 : ~unexpected_element () throw ();
364 :
365 : /**
366 : * @brief Initialize an instance with the encountered and expected
367 : * element descriptions.
368 : *
369 : * @param encountered_name A name of the encountered element.
370 : * @param encountered_ns A namespace of the encountered element.
371 : * @param expected_name A name of the expected element.
372 : * @param expected_ns A namespace of the expected element.
373 : */
374 : unexpected_element (const std::basic_string<C>& encountered_name,
375 : const std::basic_string<C>& encountered_ns,
376 : const std::basic_string<C>& expected_name,
377 : const std::basic_string<C>& expected_ns);
378 :
379 : public:
380 : /**
381 : * @brief Get the name of the encountered element.
382 : *
383 : * @return The name of the encountered element.
384 : */
385 : const std::basic_string<C>&
386 0 : encountered_name () const
387 : {
388 0 : return encountered_name_;
389 : }
390 :
391 : /**
392 : * @brief Get the namespace of the encountered element.
393 : *
394 : * @return The namespace of the encountered element.
395 : */
396 : const std::basic_string<C>&
397 0 : encountered_namespace () const
398 : {
399 0 : return encountered_namespace_;
400 : }
401 :
402 : /**
403 : * @brief Get the name of the expected element.
404 : *
405 : * @return The name of the expected element.
406 : */
407 : const std::basic_string<C>&
408 0 : expected_name () const
409 : {
410 0 : return expected_name_;
411 : }
412 :
413 : /**
414 : * @brief Get the namespace of the expected element.
415 : *
416 : * @return The namespace of the expected element.
417 : */
418 : const std::basic_string<C>&
419 0 : expected_namespace () const
420 : {
421 0 : return expected_namespace_;
422 : }
423 :
424 : /**
425 : * @brief Get %exception description.
426 : *
427 : * @return A C %string describing the %exception.
428 : */
429 : virtual const char*
430 : what () const throw ();
431 :
432 : protected:
433 : //@cond
434 :
435 : virtual void
436 : print (std::basic_ostream<C>&) const;
437 :
438 : //@endcond
439 :
440 : private:
441 : std::basic_string<C> encountered_name_;
442 : std::basic_string<C> encountered_namespace_;
443 : std::basic_string<C> expected_name_;
444 : std::basic_string<C> expected_namespace_;
445 : };
446 :
447 :
448 : /**
449 : * @brief Exception indicating that an expected attribute was not
450 : * encountered.
451 : *
452 : * @nosubgrouping
453 : */
454 : template <typename C>
455 : class expected_attribute: public exception<C>
456 : {
457 : public:
458 : virtual
459 : ~expected_attribute () throw ();
460 :
461 : /**
462 : * @brief Initialize an instance with the expected attribute
463 : * description.
464 : *
465 : * @param name A name of the expected attribute.
466 : * @param ns A namespace of the expected attribute.
467 : */
468 : expected_attribute (const std::basic_string<C>& name,
469 : const std::basic_string<C>& ns);
470 :
471 : public:
472 : /**
473 : * @brief Get the name of the expected attribute.
474 : *
475 : * @return The name of the expected attribute.
476 : */
477 : const std::basic_string<C>&
478 0 : name () const
479 : {
480 0 : return name_;
481 : }
482 :
483 : /**
484 : * @brief Get the namespace of the expected attribute.
485 : *
486 : * @return The namespace of the expected attribute.
487 : */
488 : const std::basic_string<C>&
489 0 : namespace_ () const
490 : {
491 0 : return namespace__;
492 : }
493 :
494 : /**
495 : * @brief Get %exception description.
496 : *
497 : * @return A C %string describing the %exception.
498 : */
499 : virtual const char*
500 : what () const throw ();
501 :
502 : protected:
503 : //@cond
504 :
505 : virtual void
506 : print (std::basic_ostream<C>&) const;
507 :
508 : //@endcond
509 :
510 : private:
511 : std::basic_string<C> name_;
512 : std::basic_string<C> namespace__;
513 : };
514 :
515 :
516 : /**
517 : * @brief Exception indicating that an unexpected enumerator was
518 : * encountered.
519 : *
520 : * @nosubgrouping
521 : */
522 : template <typename C>
523 : class unexpected_enumerator: public exception<C>
524 : {
525 : public:
526 : virtual
527 : ~unexpected_enumerator () throw ();
528 :
529 : /**
530 : * @brief Initialize an instance with the encountered enumerator.
531 : *
532 : * @param e A value of the encountered enumerator.
533 : */
534 : unexpected_enumerator (const std::basic_string<C>& e);
535 :
536 : public:
537 : /**
538 : * @brief Get the value of the encountered enumerator.
539 : *
540 : * @return The value of the encountered enumerator.
541 : */
542 : const std::basic_string<C>&
543 : enumerator () const
544 : {
545 : return enumerator_;
546 : }
547 :
548 : /**
549 : * @brief Get %exception description.
550 : *
551 : * @return A C %string describing the %exception.
552 : */
553 : virtual const char*
554 : what () const throw ();
555 :
556 : protected:
557 : //@cond
558 :
559 : virtual void
560 : print (std::basic_ostream<C>&) const;
561 :
562 : //@endcond
563 :
564 : private:
565 : std::basic_string<C> enumerator_;
566 : };
567 :
568 :
569 : /**
570 : * @brief Exception indicating that the text content was expected
571 : * for an element.
572 : *
573 : * @nosubgrouping
574 : */
575 : template <typename C>
576 : class expected_text_content: public exception<C>
577 : {
578 : public:
579 : /**
580 : * @brief Get %exception description.
581 : *
582 : * @return A C %string describing the %exception.
583 : */
584 : virtual const char*
585 : what () const throw ();
586 :
587 : protected:
588 : //@cond
589 :
590 : virtual void
591 : print (std::basic_ostream<C>&) const;
592 :
593 : //@endcond
594 : };
595 :
596 :
597 : /**
598 : * @brief Exception indicating that the type information is not
599 : * available for a type.
600 : *
601 : * @nosubgrouping
602 : */
603 : template <typename C>
604 : class no_type_info: public exception<C>
605 : {
606 : public:
607 : virtual
608 : ~no_type_info () throw ();
609 :
610 : /**
611 : * @brief Initialize an instance with the type description.
612 : *
613 : * @param type_name A name of the type.
614 : * @param type_ns A namespace of the type.
615 : */
616 : no_type_info (const std::basic_string<C>& type_name,
617 : const std::basic_string<C>& type_ns);
618 :
619 : public:
620 : /**
621 : * @brief Get the type name.
622 : *
623 : * @return The type name.
624 : */
625 : const std::basic_string<C>&
626 : type_name () const
627 : {
628 : return type_name_;
629 : }
630 :
631 : /**
632 : * @brief Get the type namespace.
633 : *
634 : * @return The type namespace.
635 : */
636 : const std::basic_string<C>&
637 : type_namespace () const
638 : {
639 : return type_namespace_;
640 : }
641 :
642 : /**
643 : * @brief Get %exception description.
644 : *
645 : * @return A C %string describing the %exception.
646 : */
647 : virtual const char*
648 : what () const throw ();
649 :
650 : protected:
651 : //@cond
652 :
653 : virtual void
654 : print (std::basic_ostream<C>&) const;
655 :
656 : //@endcond
657 :
658 : private:
659 : std::basic_string<C> type_name_;
660 : std::basic_string<C> type_namespace_;
661 : };
662 :
663 : /**
664 : * @brief Exception indicating that %parsing or %serialization
665 : * information is not available for an element.
666 : *
667 : * @nosubgrouping
668 : */
669 : template <typename C>
670 : class no_element_info: public exception<C>
671 : {
672 : public:
673 : virtual
674 : ~no_element_info () throw ();
675 :
676 : /**
677 : * @brief Initialize an instance with the element description.
678 : *
679 : * @param element_name An element name.
680 : * @param element_ns An element namespace.
681 : */
682 : no_element_info (const std::basic_string<C>& element_name,
683 : const std::basic_string<C>& element_ns);
684 :
685 : public:
686 : /**
687 : * @brief Get the element name.
688 : *
689 : * @return The element name.
690 : */
691 : const std::basic_string<C>&
692 : element_name () const
693 : {
694 : return element_name_;
695 : }
696 :
697 : /**
698 : * @brief Get the element namespace.
699 : *
700 : * @return The element namespace.
701 : */
702 : const std::basic_string<C>&
703 : element_namespace () const
704 : {
705 : return element_namespace_;
706 : }
707 :
708 : /**
709 : * @brief Get %exception description.
710 : *
711 : * @return A C %string describing the %exception.
712 : */
713 : virtual const char*
714 : what () const throw ();
715 :
716 : protected:
717 : //@cond
718 :
719 : virtual void
720 : print (std::basic_ostream<C>&) const;
721 :
722 : //@endcond
723 :
724 : private:
725 : std::basic_string<C> element_name_;
726 : std::basic_string<C> element_namespace_;
727 : };
728 :
729 : /**
730 : * @brief Exception indicating that the types are not related by
731 : * inheritance.
732 : *
733 : * @nosubgrouping
734 : */
735 : template <typename C>
736 : class not_derived: public exception<C>
737 : {
738 : public:
739 : virtual
740 : ~not_derived () throw ();
741 :
742 : //@cond
743 :
744 : // @@ tmp
745 : //
746 : not_derived ()
747 : {
748 : }
749 :
750 : //@endcond
751 :
752 : /**
753 : * @brief Initialize an instance with the type descriptions.
754 : *
755 : * @param base_type_name A name of the base type.
756 : * @param base_type_ns A namespace of the base type.
757 : * @param derived_type_name A name of the derived type.
758 : * @param derived_type_ns A namespace of the derived type.
759 : */
760 : not_derived (const std::basic_string<C>& base_type_name,
761 : const std::basic_string<C>& base_type_ns,
762 : const std::basic_string<C>& derived_type_name,
763 : const std::basic_string<C>& derived_type_ns);
764 :
765 : public:
766 : /**
767 : * @brief Get the base type name.
768 : *
769 : * @return The base type name.
770 : */
771 : const std::basic_string<C>&
772 : base_type_name () const
773 : {
774 : return base_type_name_;
775 : }
776 :
777 : /**
778 : * @brief Get the base type namespace.
779 : *
780 : * @return The base type namespace.
781 : */
782 : const std::basic_string<C>&
783 : base_type_namespace () const
784 : {
785 : return base_type_namespace_;
786 : }
787 :
788 : /**
789 : * @brief Get the derived type name.
790 : *
791 : * @return The derived type name.
792 : */
793 : const std::basic_string<C>&
794 : derived_type_name () const
795 : {
796 : return derived_type_name_;
797 : }
798 :
799 : /**
800 : * @brief Get the derived type namespace.
801 : *
802 : * @return The derived type namespace.
803 : */
804 : const std::basic_string<C>&
805 : derived_type_namespace () const
806 : {
807 : return derived_type_namespace_;
808 : }
809 :
810 : /**
811 : * @brief Get %exception description.
812 : *
813 : * @return A C %string describing the %exception.
814 : */
815 : virtual const char*
816 : what () const throw ();
817 :
818 : protected:
819 : //@cond
820 :
821 : virtual void
822 : print (std::basic_ostream<C>&) const;
823 :
824 : //@endcond
825 :
826 : private:
827 : std::basic_string<C> base_type_name_;
828 : std::basic_string<C> base_type_namespace_;
829 : std::basic_string<C> derived_type_name_;
830 : std::basic_string<C> derived_type_namespace_;
831 : };
832 :
833 :
834 : /**
835 : * @brief Exception indicating that a duplicate ID value was
836 : * encountered in the object model.
837 : *
838 : * @nosubgrouping
839 : */
840 : template <typename C>
841 : class duplicate_id: public exception<C>
842 : {
843 : public:
844 : virtual
845 : ~duplicate_id () throw ();
846 :
847 : /**
848 : * @brief Initialize an instance with the offending ID value.
849 : *
850 : * @param id An offending ID value.
851 : */
852 : duplicate_id (const std::basic_string<C>& id);
853 :
854 : public:
855 : /**
856 : * @brief Get the offending ID value.
857 : *
858 : * @return The offending ID value.
859 : */
860 : const std::basic_string<C>&
861 : id () const
862 : {
863 : return id_;
864 : }
865 :
866 : /**
867 : * @brief Get %exception description.
868 : *
869 : * @return A C %string describing the %exception.
870 : */
871 : virtual const char*
872 : what () const throw ();
873 :
874 : protected:
875 : //@cond
876 :
877 : virtual void
878 : print (std::basic_ostream<C>&) const;
879 :
880 : //@endcond
881 :
882 : private:
883 : std::basic_string<C> id_;
884 : };
885 :
886 :
887 : /**
888 : * @brief Exception indicating a %serialization failure.
889 : *
890 : * @nosubgrouping
891 : */
892 : template <typename C>
893 : class serialization: public exception<C>
894 : {
895 : public:
896 : virtual
897 : ~serialization () throw ();
898 :
899 : /**
900 : * @brief Default constructor.
901 : */
902 : serialization ();
903 :
904 : /**
905 : * @brief Initialize an instance with a %list of %error conditions.
906 : *
907 : * @param d A %list of %error conditions.
908 : */
909 : serialization (const tree::diagnostics<C>& d);
910 :
911 : public:
912 : /**
913 : * @brief Get the %list of %error conditions.
914 : *
915 : * @return The %list of %error conditions.
916 : */
917 : const tree::diagnostics<C>&
918 : diagnostics () const
919 : {
920 : return diagnostics_;
921 : }
922 :
923 : /**
924 : * @brief Get %exception description.
925 : *
926 : * @return A C %string describing the %exception.
927 : */
928 : virtual const char*
929 : what () const throw ();
930 :
931 : protected:
932 : //@cond
933 :
934 : virtual void
935 : print (std::basic_ostream<C>&) const;
936 :
937 : //@endcond
938 :
939 : private:
940 : tree::diagnostics<C> diagnostics_;
941 : };
942 :
943 :
944 : /**
945 : * @brief Exception indicating that a prefix-namespace mapping was
946 : * not provided.
947 : *
948 : * @nosubgrouping
949 : */
950 : template <typename C>
951 : class no_prefix_mapping: public exception<C>
952 : {
953 : public:
954 : virtual
955 : ~no_prefix_mapping () throw ();
956 :
957 : /**
958 : * @brief Initialize an instance with the prefix for which the
959 : * prefix-namespace mapping was not provided.
960 : *
961 : * @param prefix A prefix.
962 : */
963 : no_prefix_mapping (const std::basic_string<C>& prefix);
964 :
965 : public:
966 : /**
967 : * @brief Get the prefix for which the prefix-namespace mapping was
968 : * not provided.
969 : *
970 : * @return The prefix.
971 : */
972 : const std::basic_string<C>&
973 : prefix () const
974 : {
975 : return prefix_;
976 : }
977 :
978 : /**
979 : * @brief Get %exception description.
980 : *
981 : * @return A C %string describing the %exception.
982 : */
983 : virtual const char*
984 : what () const throw ();
985 :
986 : protected:
987 : //@cond
988 :
989 : virtual void
990 : print (std::basic_ostream<C>&) const;
991 :
992 : //@endcond
993 :
994 : private:
995 : std::basic_string<C> prefix_;
996 : };
997 :
998 :
999 : /**
1000 : * @brief Exception indicating that the size argument exceeds
1001 : * the capacity argument.
1002 : *
1003 : * See the buffer class for details.
1004 : *
1005 : * @nosubgrouping
1006 : */
1007 : template <typename C>
1008 : class bounds: public exception<C>
1009 : {
1010 : public:
1011 : /**
1012 : * @brief Get %exception description.
1013 : *
1014 : * @return A C %string describing the %exception.
1015 : */
1016 : virtual const char*
1017 : what () const throw ();
1018 :
1019 : protected:
1020 : //@cond
1021 :
1022 : virtual void
1023 : print (std::basic_ostream<C>&) const;
1024 :
1025 : //@endcond
1026 : };
1027 : }
1028 : }
1029 : }
1030 :
1031 : #include <xsd/cxx/tree/exceptions.txx>
1032 :
1033 : #endif // XSD_CXX_TREE_EXCEPTIONS_HXX
|