]> git.lyx.org Git - lyx.git/blob - boost/boost/exception/get_error_info.hpp
boost: update to version 1.40
[lyx.git] / boost / boost / exception / get_error_info.hpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.\r
2 \r
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying\r
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\r
5 \r
6 #ifndef UUID_1A590226753311DD9E4CCF6156D89593\r
7 #define UUID_1A590226753311DD9E4CCF6156D89593\r
8 \r
9 #include <boost/exception/exception.hpp>\r
10 #include <boost/exception/detail/error_info_impl.hpp>\r
11 #include <boost/exception/detail/type_info.hpp>\r
12 #include <boost/shared_ptr.hpp>\r
13 \r
14 namespace\r
15 boost\r
16     {\r
17     namespace\r
18     exception_detail\r
19         {\r
20         template <class ErrorInfo>\r
21         struct\r
22         get_info\r
23             {\r
24             static\r
25             typename ErrorInfo::value_type const *\r
26             get( exception const & x )\r
27                 {\r
28                 if( exception_detail::error_info_container * c=x.data_.get() )\r
29                     if( shared_ptr<exception_detail::error_info_base const> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )\r
30                         {\r
31 #ifndef BOOST_NO_RTTI\r
32                         BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );\r
33 #endif\r
34                         ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());\r
35                         return &w->value();\r
36                         }\r
37                 return 0;\r
38                 }\r
39             };\r
40 \r
41         template <>\r
42         struct\r
43         get_info<throw_function>\r
44             {\r
45             static\r
46             char const * const *\r
47             get( exception const & x )\r
48                 {\r
49                 return x.throw_function_ ? &x.throw_function_ : 0;\r
50                 }\r
51             };\r
52 \r
53         template <>\r
54         struct\r
55         get_info<throw_file>\r
56             {\r
57             static\r
58             char const * const *\r
59             get( exception const & x )\r
60                 {\r
61                 return x.throw_file_ ? &x.throw_file_ : 0;\r
62                 }\r
63             };\r
64 \r
65         template <>\r
66         struct\r
67         get_info<throw_line>\r
68             {\r
69             static\r
70             int const *\r
71             get( exception const & x )\r
72                 {\r
73                 return x.throw_line_!=-1 ? &x.throw_line_ : 0;\r
74                 }\r
75             };\r
76         }\r
77 \r
78 #ifdef BOOST_NO_RTTI\r
79     template <class ErrorInfo>\r
80     inline\r
81     typename ErrorInfo::value_type const *\r
82     get_error_info( boost::exception const & x )\r
83         {\r
84         return exception_detail::get_info<ErrorInfo>::get(x);\r
85         }\r
86 #else\r
87     template <class ErrorInfo,class E>\r
88     inline\r
89     typename ErrorInfo::value_type const *\r
90     get_error_info( E const & some_exception )\r
91         {\r
92         if( exception const * x = dynamic_cast<exception const *>(&some_exception) )\r
93             return exception_detail::get_info<ErrorInfo>::get(*x);\r
94         else\r
95             return 0;\r
96         }\r
97 #endif\r
98     }\r
99 \r
100 #endif\r