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