]> git.lyx.org Git - lyx.git/blob - boost/boost/exception/get_error_info.hpp
boost: add eol property
[lyx.git] / boost / boost / exception / get_error_info.hpp
1 //Copyright (c) 2006-2009 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         template <class ErrorInfo>
21         struct
22         get_info
23             {
24             static
25             typename ErrorInfo::value_type *
26             get( exception const & x )
27                 {
28                 if( exception_detail::error_info_container * c=x.data_.get() )
29                     if( shared_ptr<exception_detail::error_info_base> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
30                         {
31 #ifndef BOOST_NO_RTTI
32                         BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
33 #endif
34                         ErrorInfo * w = static_cast<ErrorInfo *>(eib.get());
35                         return &w->value();
36                         }
37                 return 0;
38                 }
39             };
40
41         template <>
42         struct
43         get_info<throw_function>
44             {
45             static
46             char const * *
47             get( exception const & x )
48                 {
49                 return x.throw_function_ ? &x.throw_function_ : 0;
50                 }
51             };
52
53         template <>
54         struct
55         get_info<throw_file>
56             {
57             static
58             char const * *
59             get( exception const & x )
60                 {
61                 return x.throw_file_ ? &x.throw_file_ : 0;
62                 }
63             };
64
65         template <>
66         struct
67         get_info<throw_line>
68             {
69             static
70             int *
71             get( exception const & x )
72                 {
73                 return x.throw_line_!=-1 ? &x.throw_line_ : 0;
74                 }
75             };
76
77         template <class T,class R>
78         struct
79         get_error_info_return_type
80             {
81             typedef R * type;
82             };
83
84         template <class T,class R>
85         struct
86         get_error_info_return_type<T const,R>
87             {
88             typedef R const * type;
89             };
90         }
91
92 #ifdef BOOST_NO_RTTI
93     template <class ErrorInfo>
94     inline
95     typename ErrorInfo::value_type const *
96     get_error_info( boost::exception const & x )
97         {
98         return exception_detail::get_info<ErrorInfo>::get(x);
99         }
100     template <class ErrorInfo>
101     inline
102     typename ErrorInfo::value_type *
103     get_error_info( boost::exception & x )
104         {
105         return exception_detail::get_info<ErrorInfo>::get(x);
106         }
107 #else
108     template <class ErrorInfo,class E>
109     inline
110     typename exception_detail::get_error_info_return_type<E,typename ErrorInfo::value_type>::type
111     get_error_info( E & some_exception )
112         {
113         if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
114             return exception_detail::get_info<ErrorInfo>::get(*x);
115         else
116             return 0;
117         }
118 #endif
119     }
120
121 #endif