C++/Tree Mapping Runtime Library
exceptions.hxx
Go to the documentation of this file.
1// file : xsd/cxx/tree/exceptions.hxx
2// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
3
14#ifndef XSD_CXX_TREE_EXCEPTIONS_HXX
15#define XSD_CXX_TREE_EXCEPTIONS_HXX
16
17#include <string>
18#include <vector>
19#include <ostream>
20
21#include <xsd/cxx/exceptions.hxx> // xsd::cxx::exception
22
23namespace xsd
24{
25 namespace cxx
26 {
35 namespace tree
36 {
45 template <typename C>
46 class exception: public xsd::cxx::exception
47 {
48 public:
52 friend
53 std::basic_ostream<C>&
54 operator<< (std::basic_ostream<C>& os, const exception& e)
55 {
56 e.print (os);
57 return os;
58 }
59
60 protected:
61 //@cond
62
63 virtual void
64 print (std::basic_ostream<C>&) const = 0;
65
66 //@endcond
67 };
68
69
76 {
77 public:
81 enum value
82 {
87
91 error
92 };
93
99 severity (value v) : v_ (v) {}
100
107 operator value () const { return v_; }
108
109 private:
110 value v_;
111 };
112
118 template <typename C>
119 class error
120 {
121 public:
132 const std::basic_string<C>& res_id,
133 unsigned long line,
134 unsigned long column,
135 const std::basic_string<C>& message);
136
143 severity () const
144 {
145 return severity_;
146 }
147
153 const std::basic_string<C>&
154 id () const
155 {
156 return id_;
157 }
158
164 unsigned long
165 line () const
166 {
167 return line_;
168 }
169
175 unsigned long
176 column () const
177 {
178 return column_;
179 }
180
186 const std::basic_string<C>&
187 message () const
188 {
189 return message_;
190 }
191
192 //@cond
193
194 // Default c-tor that shouldn't be. Needed when we completely
195 // instantiate std::vector in diagnostics below.
196 //
197 error ();
198
199 //@endcond
200
201
202 private:
203 tree::severity severity_;
204 std::basic_string<C> id_;
205 unsigned long line_;
206 unsigned long column_;
207 std::basic_string<C> message_;
208 };
209
210 // See exceptions.ixx for operator<< (error).
211
212
218 template <typename C>
219 class diagnostics: public std::vector<error<C> >
220 {
221 };
222
223 // See exceptions.ixx for operator<< (diagnostics).
224
230 template <typename C>
231 class parsing: public exception<C>
232 {
233 public:
234 virtual
235 ~parsing () throw ();
236
241
248
249 public:
256 diagnostics () const
257 {
258 return diagnostics_;
259 }
260
266 virtual const char*
267 what () const throw ();
268
269 protected:
270 //@cond
271
272 virtual void
273 print (std::basic_ostream<C>&) const;
274
275 //@endcond
276
277 private:
278 tree::diagnostics<C> diagnostics_;
279 };
280
281
288 template <typename C>
290 {
291 public:
292 virtual
293 ~expected_element () throw ();
294
302 expected_element (const std::basic_string<C>& name,
303 const std::basic_string<C>& ns);
304
305
306 public:
312 const std::basic_string<C>&
313 name () const
314 {
315 return name_;
316 }
317
323 const std::basic_string<C>&
324 namespace_ () const
325 {
326 return namespace__;
327 }
328
334 virtual const char*
335 what () const throw ();
336
337 protected:
338 //@cond
339
340 virtual void
341 print (std::basic_ostream<C>&) const;
342
343 //@endcond
344
345 private:
346 std::basic_string<C> name_;
347 std::basic_string<C> namespace__;
348 };
349
350
357 template <typename C>
359 {
360 public:
361 virtual
362 ~unexpected_element () throw ();
363
373 unexpected_element (const std::basic_string<C>& encountered_name,
374 const std::basic_string<C>& encountered_ns,
375 const std::basic_string<C>& expected_name,
376 const std::basic_string<C>& expected_ns);
377
378 public:
384 const std::basic_string<C>&
386 {
387 return encountered_name_;
388 }
389
395 const std::basic_string<C>&
397 {
398 return encountered_namespace_;
399 }
400
406 const std::basic_string<C>&
408 {
409 return expected_name_;
410 }
411
417 const std::basic_string<C>&
419 {
420 return expected_namespace_;
421 }
422
428 virtual const char*
429 what () const throw ();
430
431 protected:
432 //@cond
433
434 virtual void
435 print (std::basic_ostream<C>&) const;
436
437 //@endcond
438
439 private:
440 std::basic_string<C> encountered_name_;
441 std::basic_string<C> encountered_namespace_;
442 std::basic_string<C> expected_name_;
443 std::basic_string<C> expected_namespace_;
444 };
445
446
453 template <typename C>
455 {
456 public:
457 virtual
458 ~expected_attribute () throw ();
459
467 expected_attribute (const std::basic_string<C>& name,
468 const std::basic_string<C>& ns);
469
470 public:
476 const std::basic_string<C>&
477 name () const
478 {
479 return name_;
480 }
481
487 const std::basic_string<C>&
488 namespace_ () const
489 {
490 return namespace__;
491 }
492
498 virtual const char*
499 what () const throw ();
500
501 protected:
502 //@cond
503
504 virtual void
505 print (std::basic_ostream<C>&) const;
506
507 //@endcond
508
509 private:
510 std::basic_string<C> name_;
511 std::basic_string<C> namespace__;
512 };
513
514
521 template <typename C>
523 {
524 public:
525 virtual
526 ~unexpected_enumerator () throw ();
527
533 unexpected_enumerator (const std::basic_string<C>& e);
534
535 public:
541 const std::basic_string<C>&
542 enumerator () const
543 {
544 return enumerator_;
545 }
546
552 virtual const char*
553 what () const throw ();
554
555 protected:
556 //@cond
557
558 virtual void
559 print (std::basic_ostream<C>&) const;
560
561 //@endcond
562
563 private:
564 std::basic_string<C> enumerator_;
565 };
566
567
574 template <typename C>
576 {
577 public:
583 virtual const char*
584 what () const throw ();
585
586 protected:
587 //@cond
588
589 virtual void
590 print (std::basic_ostream<C>&) const;
591
592 //@endcond
593 };
594
595
602 template <typename C>
603 class no_type_info: public exception<C>
604 {
605 public:
606 virtual
607 ~no_type_info () throw ();
608
615 no_type_info (const std::basic_string<C>& type_name,
616 const std::basic_string<C>& type_ns);
617
618 public:
624 const std::basic_string<C>&
625 type_name () const
626 {
627 return type_name_;
628 }
629
635 const std::basic_string<C>&
637 {
638 return type_namespace_;
639 }
640
646 virtual const char*
647 what () const throw ();
648
649 protected:
650 //@cond
651
652 virtual void
653 print (std::basic_ostream<C>&) const;
654
655 //@endcond
656
657 private:
658 std::basic_string<C> type_name_;
659 std::basic_string<C> type_namespace_;
660 };
661
668 template <typename C>
669 class no_element_info: public exception<C>
670 {
671 public:
672 virtual
673 ~no_element_info () throw ();
674
681 no_element_info (const std::basic_string<C>& element_name,
682 const std::basic_string<C>& element_ns);
683
684 public:
690 const std::basic_string<C>&
692 {
693 return element_name_;
694 }
695
701 const std::basic_string<C>&
703 {
704 return element_namespace_;
705 }
706
712 virtual const char*
713 what () const throw ();
714
715 protected:
716 //@cond
717
718 virtual void
719 print (std::basic_ostream<C>&) const;
720
721 //@endcond
722
723 private:
724 std::basic_string<C> element_name_;
725 std::basic_string<C> element_namespace_;
726 };
727
734 template <typename C>
735 class not_derived: public exception<C>
736 {
737 public:
738 virtual
739 ~not_derived () throw ();
740
741 //@cond
742
743 // @@ tmp
744 //
745 not_derived ()
746 {
747 }
748
749 //@endcond
750
759 not_derived (const std::basic_string<C>& base_type_name,
760 const std::basic_string<C>& base_type_ns,
761 const std::basic_string<C>& derived_type_name,
762 const std::basic_string<C>& derived_type_ns);
763
764 public:
770 const std::basic_string<C>&
772 {
773 return base_type_name_;
774 }
775
781 const std::basic_string<C>&
783 {
784 return base_type_namespace_;
785 }
786
792 const std::basic_string<C>&
794 {
795 return derived_type_name_;
796 }
797
803 const std::basic_string<C>&
805 {
806 return derived_type_namespace_;
807 }
808
814 virtual const char*
815 what () const throw ();
816
817 protected:
818 //@cond
819
820 virtual void
821 print (std::basic_ostream<C>&) const;
822
823 //@endcond
824
825 private:
826 std::basic_string<C> base_type_name_;
827 std::basic_string<C> base_type_namespace_;
828 std::basic_string<C> derived_type_name_;
829 std::basic_string<C> derived_type_namespace_;
830 };
831
832
839 template <typename C>
840 class duplicate_id: public exception<C>
841 {
842 public:
843 virtual
844 ~duplicate_id () throw ();
845
851 duplicate_id (const std::basic_string<C>& id);
852
853 public:
859 const std::basic_string<C>&
860 id () const
861 {
862 return id_;
863 }
864
870 virtual const char*
871 what () const throw ();
872
873 protected:
874 //@cond
875
876 virtual void
877 print (std::basic_ostream<C>&) const;
878
879 //@endcond
880
881 private:
882 std::basic_string<C> id_;
883 };
884
885
891 template <typename C>
892 class serialization: public exception<C>
893 {
894 public:
895 virtual
896 ~serialization () throw ();
897
902
909
910 public:
917 diagnostics () const
918 {
919 return diagnostics_;
920 }
921
927 virtual const char*
928 what () const throw ();
929
930 protected:
931 //@cond
932
933 virtual void
934 print (std::basic_ostream<C>&) const;
935
936 //@endcond
937
938 private:
939 tree::diagnostics<C> diagnostics_;
940 };
941
942
949 template <typename C>
951 {
952 public:
953 virtual
954 ~no_prefix_mapping () throw ();
955
962 no_prefix_mapping (const std::basic_string<C>& prefix);
963
964 public:
971 const std::basic_string<C>&
972 prefix () const
973 {
974 return prefix_;
975 }
976
982 virtual const char*
983 what () const throw ();
984
985 protected:
986 //@cond
987
988 virtual void
989 print (std::basic_ostream<C>&) const;
990
991 //@endcond
992
993 private:
994 std::basic_string<C> prefix_;
995 };
996
997
1006 template <typename C>
1007 class bounds: public exception<C>
1008 {
1009 public:
1015 virtual const char*
1016 what () const throw ();
1017
1018 protected:
1019 //@cond
1020
1021 virtual void
1022 print (std::basic_ostream<C>&) const;
1023
1024 //@endcond
1025 };
1026 }
1027 }
1028}
1029
1030#include <xsd/cxx/tree/exceptions.txx>
1031
1032#endif // XSD_CXX_TREE_EXCEPTIONS_HXX
Exception indicating that the size argument exceeds the capacity argument.
Definition exceptions.hxx:1008
virtual const char * what() const
Get exception description.
List of error conditions.
Definition exceptions.hxx:220
Exception indicating that a duplicate ID value was encountered in the object model.
Definition exceptions.hxx:841
duplicate_id(const std::basic_string< C > &id)
Initialize an instance with the offending ID value.
const std::basic_string< C > & id() const
Get the offending ID value.
Definition exceptions.hxx:860
virtual const char * what() const
Get exception description.
Error condition.
Definition exceptions.hxx:120
const std::basic_string< C > & message() const
Get error message.
Definition exceptions.hxx:187
tree::severity severity() const
Get error severity.
Definition exceptions.hxx:143
error(tree::severity s, const std::basic_string< C > &res_id, unsigned long line, unsigned long column, const std::basic_string< C > &message)
Initialize an instance with error description.
const std::basic_string< C > & id() const
Get resource id.
Definition exceptions.hxx:154
unsigned long column() const
Get error column.
Definition exceptions.hxx:176
unsigned long line() const
Get error line.
Definition exceptions.hxx:165
Root of the C++/Tree exception hierarchy.
Definition exceptions.hxx:47
friend std::basic_ostream< C > & operator<<(std::basic_ostream< C > &os, const exception &e)
Stream insertion operator for exception.
Definition exceptions.hxx:54
Exception indicating that an expected attribute was not encountered.
Definition exceptions.hxx:455
const std::basic_string< C > & name() const
Get the name of the expected attribute.
Definition exceptions.hxx:477
virtual const char * what() const
Get exception description.
const std::basic_string< C > & namespace_() const
Get the namespace of the expected attribute.
Definition exceptions.hxx:488
expected_attribute(const std::basic_string< C > &name, const std::basic_string< C > &ns)
Initialize an instance with the expected attribute description.
Exception indicating that an expected element was not encountered.
Definition exceptions.hxx:290
const std::basic_string< C > & name() const
Get the name of the expected element.
Definition exceptions.hxx:313
virtual const char * what() const
Get exception description.
const std::basic_string< C > & namespace_() const
Get the namespace of the expected element.
Definition exceptions.hxx:324
expected_element(const std::basic_string< C > &name, const std::basic_string< C > &ns)
Initialize an instance with the expected element description.
Exception indicating that the text content was expected for an element.
Definition exceptions.hxx:576
virtual const char * what() const
Get exception description.
Class corresponding to the XML Schema Name built-in type.
Definition types.hxx:1200
Exception indicating that parsing or serialization information is not available for an element.
Definition exceptions.hxx:670
virtual const char * what() const
Get exception description.
no_element_info(const std::basic_string< C > &element_name, const std::basic_string< C > &element_ns)
Initialize an instance with the element description.
const std::basic_string< C > & element_namespace() const
Get the element namespace.
Definition exceptions.hxx:702
const std::basic_string< C > & element_name() const
Get the element name.
Definition exceptions.hxx:691
Exception indicating that a prefix-namespace mapping was not provided.
Definition exceptions.hxx:951
no_prefix_mapping(const std::basic_string< C > &prefix)
Initialize an instance with the prefix for which the prefix-namespace mapping was not provided.
virtual const char * what() const
Get exception description.
const std::basic_string< C > & prefix() const
Get the prefix for which the prefix-namespace mapping was not provided.
Definition exceptions.hxx:972
Exception indicating that the type information is not available for a type.
Definition exceptions.hxx:604
no_type_info(const std::basic_string< C > &type_name, const std::basic_string< C > &type_ns)
Initialize an instance with the type description.
virtual const char * what() const
Get exception description.
const std::basic_string< C > & type_namespace() const
Get the type namespace.
Definition exceptions.hxx:636
const std::basic_string< C > & type_name() const
Get the type name.
Definition exceptions.hxx:625
Exception indicating that the types are not related by inheritance.
Definition exceptions.hxx:736
const std::basic_string< C > & derived_type_name() const
Get the derived type name.
Definition exceptions.hxx:793
const std::basic_string< C > & derived_type_namespace() const
Get the derived type namespace.
Definition exceptions.hxx:804
const std::basic_string< C > & base_type_namespace() const
Get the base type namespace.
Definition exceptions.hxx:782
not_derived(const std::basic_string< C > &base_type_name, const std::basic_string< C > &base_type_ns, const std::basic_string< C > &derived_type_name, const std::basic_string< C > &derived_type_ns)
Initialize an instance with the type descriptions.
virtual const char * what() const
Get exception description.
const std::basic_string< C > & base_type_name() const
Get the base type name.
Definition exceptions.hxx:771
Exception indicating a parsing failure.
Definition exceptions.hxx:232
parsing()
Default constructor.
virtual const char * what() const
Get exception description.
const tree::diagnostics< C > & diagnostics() const
Get the list of error conditions.
Definition exceptions.hxx:256
parsing(const tree::diagnostics< C > &d)
Initialize an instance with a list of error conditions.
Exception indicating a serialization failure.
Definition exceptions.hxx:893
serialization(const tree::diagnostics< C > &d)
Initialize an instance with a list of error conditions.
serialization()
Default constructor.
virtual const char * what() const
Get exception description.
const tree::diagnostics< C > & diagnostics() const
Get the list of error conditions.
Definition exceptions.hxx:917
Error severity.
Definition exceptions.hxx:76
severity(value v)
Initialize an instance with the underlying enum value.
Definition exceptions.hxx:99
value
Underlying enum type.
Definition exceptions.hxx:82
@ warning
Indicates the warning condition.
Definition exceptions.hxx:86
Exception indicating that an unexpected element was encountered.
Definition exceptions.hxx:359
const std::basic_string< C > & expected_namespace() const
Get the namespace of the expected element.
Definition exceptions.hxx:418
const std::basic_string< C > & expected_name() const
Get the name of the expected element.
Definition exceptions.hxx:407
virtual const char * what() const
Get exception description.
const std::basic_string< C > & encountered_namespace() const
Get the namespace of the encountered element.
Definition exceptions.hxx:396
unexpected_element(const std::basic_string< C > &encountered_name, const std::basic_string< C > &encountered_ns, const std::basic_string< C > &expected_name, const std::basic_string< C > &expected_ns)
Initialize an instance with the encountered and expected element descriptions.
const std::basic_string< C > & encountered_name() const
Get the name of the encountered element.
Definition exceptions.hxx:385
Exception indicating that an unexpected enumerator was encountered.
Definition exceptions.hxx:523
unexpected_enumerator(const std::basic_string< C > &e)
Initialize an instance with the encountered enumerator.
virtual const char * what() const
Get exception description.
const std::basic_string< C > & enumerator() const
Get the value of the encountered enumerator.
Definition exceptions.hxx:542

Copyright © 2005-2023 Code Synthesis.