fix doc example typo
[boost.git] / boost / exception / get_error_info.hpp
blob826ef226c0315e9e20bb8ec9e7047f29f63a7bec
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
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)
6 #ifndef UUID_1A590226753311DD9E4CCF6156D89593
7 #define UUID_1A590226753311DD9E4CCF6156D89593
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>
14 namespace
15 boost
17 namespace
18 exception_detail
20 template <class ErrorInfo>
21 struct
22 get_info
24 static
25 typename ErrorInfo::value_type const *
26 get( exception const & x )
28 if( exception_detail::error_info_container * c=x.data_.get() )
29 if( shared_ptr<exception_detail::error_info_base const> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
31 #ifndef BOOST_NO_RTTI
32 BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
33 #endif
34 ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());
35 return &w->value();
37 return 0;
41 template <>
42 struct
43 get_info<throw_function>
45 static
46 char const * const *
47 get( exception const & x )
49 return x.throw_function_ ? &x.throw_function_ : 0;
53 template <>
54 struct
55 get_info<throw_file>
57 static
58 char const * const *
59 get( exception const & x )
61 return x.throw_file_ ? &x.throw_file_ : 0;
65 template <>
66 struct
67 get_info<throw_line>
69 static
70 int const *
71 get( exception const & x )
73 return x.throw_line_!=-1 ? &x.throw_line_ : 0;
78 #ifdef BOOST_NO_RTTI
79 template <class ErrorInfo>
80 inline
81 typename ErrorInfo::value_type const *
82 get_error_info( boost::exception const & x )
84 return exception_detail::get_info<ErrorInfo>::get(x);
86 #else
87 template <class ErrorInfo,class E>
88 inline
89 typename ErrorInfo::value_type const *
90 get_error_info( E const & some_exception )
92 if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
93 return exception_detail::get_info<ErrorInfo>::get(*x);
94 else
95 return 0;
97 #endif
100 #endif