Chris@16
|
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
|
Chris@16
|
2
|
Chris@16
|
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5
|
Chris@16
|
6 #ifndef UUID_1A590226753311DD9E4CCF6156D89593
|
Chris@16
|
7 #define UUID_1A590226753311DD9E4CCF6156D89593
|
Chris@16
|
8 #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
9 #pragma GCC system_header
|
Chris@16
|
10 #endif
|
Chris@16
|
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
12 #pragma warning(push,1)
|
Chris@16
|
13 #endif
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/exception/exception.hpp>
|
Chris@16
|
16 #include <boost/exception/detail/error_info_impl.hpp>
|
Chris@16
|
17 #include <boost/exception/detail/type_info.hpp>
|
Chris@16
|
18 #include <boost/shared_ptr.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace
|
Chris@16
|
21 boost
|
Chris@16
|
22 {
|
Chris@16
|
23 namespace
|
Chris@16
|
24 exception_detail
|
Chris@16
|
25 {
|
Chris@16
|
26 template <class ErrorInfo>
|
Chris@16
|
27 struct
|
Chris@16
|
28 get_info
|
Chris@16
|
29 {
|
Chris@16
|
30 static
|
Chris@16
|
31 typename ErrorInfo::value_type *
|
Chris@16
|
32 get( exception const & x )
|
Chris@16
|
33 {
|
Chris@16
|
34 if( exception_detail::error_info_container * c=x.data_.get() )
|
Chris@16
|
35 if( shared_ptr<exception_detail::error_info_base> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
|
Chris@16
|
36 {
|
Chris@16
|
37 #ifndef BOOST_NO_RTTI
|
Chris@16
|
38 BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
|
Chris@16
|
39 #endif
|
Chris@16
|
40 ErrorInfo * w = static_cast<ErrorInfo *>(eib.get());
|
Chris@16
|
41 return &w->value();
|
Chris@16
|
42 }
|
Chris@16
|
43 return 0;
|
Chris@16
|
44 }
|
Chris@16
|
45 };
|
Chris@16
|
46
|
Chris@16
|
47 template <>
|
Chris@16
|
48 struct
|
Chris@16
|
49 get_info<throw_function>
|
Chris@16
|
50 {
|
Chris@16
|
51 static
|
Chris@16
|
52 char const * *
|
Chris@16
|
53 get( exception const & x )
|
Chris@16
|
54 {
|
Chris@16
|
55 return x.throw_function_ ? &x.throw_function_ : 0;
|
Chris@16
|
56 }
|
Chris@16
|
57 };
|
Chris@16
|
58
|
Chris@16
|
59 template <>
|
Chris@16
|
60 struct
|
Chris@16
|
61 get_info<throw_file>
|
Chris@16
|
62 {
|
Chris@16
|
63 static
|
Chris@16
|
64 char const * *
|
Chris@16
|
65 get( exception const & x )
|
Chris@16
|
66 {
|
Chris@16
|
67 return x.throw_file_ ? &x.throw_file_ : 0;
|
Chris@16
|
68 }
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71 template <>
|
Chris@16
|
72 struct
|
Chris@16
|
73 get_info<throw_line>
|
Chris@16
|
74 {
|
Chris@16
|
75 static
|
Chris@16
|
76 int *
|
Chris@16
|
77 get( exception const & x )
|
Chris@16
|
78 {
|
Chris@16
|
79 return x.throw_line_!=-1 ? &x.throw_line_ : 0;
|
Chris@16
|
80 }
|
Chris@16
|
81 };
|
Chris@16
|
82
|
Chris@16
|
83 template <class T,class R>
|
Chris@16
|
84 struct
|
Chris@16
|
85 get_error_info_return_type
|
Chris@16
|
86 {
|
Chris@16
|
87 typedef R * type;
|
Chris@16
|
88 };
|
Chris@16
|
89
|
Chris@16
|
90 template <class T,class R>
|
Chris@16
|
91 struct
|
Chris@16
|
92 get_error_info_return_type<T const,R>
|
Chris@16
|
93 {
|
Chris@16
|
94 typedef R const * type;
|
Chris@16
|
95 };
|
Chris@16
|
96 }
|
Chris@16
|
97
|
Chris@16
|
98 #ifdef BOOST_NO_RTTI
|
Chris@16
|
99 template <class ErrorInfo>
|
Chris@16
|
100 inline
|
Chris@16
|
101 typename ErrorInfo::value_type const *
|
Chris@16
|
102 get_error_info( boost::exception const & x )
|
Chris@16
|
103 {
|
Chris@16
|
104 return exception_detail::get_info<ErrorInfo>::get(x);
|
Chris@16
|
105 }
|
Chris@16
|
106 template <class ErrorInfo>
|
Chris@16
|
107 inline
|
Chris@16
|
108 typename ErrorInfo::value_type *
|
Chris@16
|
109 get_error_info( boost::exception & x )
|
Chris@16
|
110 {
|
Chris@16
|
111 return exception_detail::get_info<ErrorInfo>::get(x);
|
Chris@16
|
112 }
|
Chris@16
|
113 #else
|
Chris@16
|
114 template <class ErrorInfo,class E>
|
Chris@16
|
115 inline
|
Chris@16
|
116 typename exception_detail::get_error_info_return_type<E,typename ErrorInfo::value_type>::type
|
Chris@16
|
117 get_error_info( E & some_exception )
|
Chris@16
|
118 {
|
Chris@16
|
119 if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
|
Chris@16
|
120 return exception_detail::get_info<ErrorInfo>::get(*x);
|
Chris@16
|
121 else
|
Chris@16
|
122 return 0;
|
Chris@16
|
123 }
|
Chris@16
|
124 #endif
|
Chris@16
|
125 }
|
Chris@16
|
126
|
Chris@16
|
127 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
|
Chris@16
|
128 #pragma warning(pop)
|
Chris@16
|
129 #endif
|
Chris@16
|
130 #endif
|