Pack required boost code together.
[xy_vsfilter.git] / src / thirdparty / boost_1_47_0 / boost / exception / diagnostic_information.hpp
blobe1830ec19f9d7f7673d53d90bf6bd233acda7649
1 //Copyright (c) 2006-2010 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_0552D49838DD11DD90146B8956D89593
7 #define UUID_0552D49838DD11DD90146B8956D89593
8 #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
9 #pragma GCC system_header
10 #endif
11 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
12 #pragma warning(push,1)
13 #endif
15 #include <boost/config.hpp>
16 #include <boost/exception/get_error_info.hpp>
17 #include <boost/exception/info.hpp>
18 #include <boost/utility/enable_if.hpp>
19 #ifndef BOOST_NO_RTTI
20 #include <boost/units/detail/utility.hpp>
21 #endif
22 #include <exception>
23 #include <sstream>
24 #include <string>
26 #ifndef BOOST_NO_EXCEPTIONS
27 #include <boost/exception/current_exception_cast.hpp>
28 namespace
29 boost
31 namespace
32 exception_detail
34 std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool );
37 inline
38 std::string
39 current_exception_diagnostic_information()
41 boost::exception const * be=current_exception_cast<boost::exception const>();
42 std::exception const * se=current_exception_cast<std::exception const>();
43 if( be || se )
44 return exception_detail::diagnostic_information_impl(be,se,true);
45 else
46 return "No diagnostic information available.";
49 #endif
51 namespace
52 boost
54 namespace
55 exception_detail
57 inline
58 exception const *
59 get_boost_exception( exception const * e )
61 return e;
64 inline
65 exception const *
66 get_boost_exception( ... )
68 return 0;
71 inline
72 std::exception const *
73 get_std_exception( std::exception const * e )
75 return e;
78 inline
79 std::exception const *
80 get_std_exception( ... )
82 return 0;
85 inline
86 char const *
87 get_diagnostic_information( exception const & x, char const * header )
89 #ifndef BOOST_NO_EXCEPTIONS
90 try
92 #endif
93 error_info_container * c=x.data_.get();
94 if( !c )
95 x.data_.adopt(c=new exception_detail::error_info_container_impl);
96 char const * di=c->diagnostic_information(header);
97 BOOST_ASSERT(di!=0);
98 return di;
99 #ifndef BOOST_NO_EXCEPTIONS
101 catch(...)
103 return 0;
105 #endif
108 inline
109 std::string
110 diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
112 if( !be && !se )
113 return "Unknown exception.";
114 #ifndef BOOST_NO_RTTI
115 if( !be )
116 be=dynamic_cast<boost::exception const *>(se);
117 if( !se )
118 se=dynamic_cast<std::exception const *>(be);
119 #endif
120 char const * wh=0;
121 if( with_what && se )
123 wh=se->what();
124 if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
125 return wh;
127 std::ostringstream tmp;
128 if( be )
130 char const * const * f=get_error_info<throw_file>(*be);
131 int const * l=get_error_info<throw_line>(*be);
132 char const * const * fn=get_error_info<throw_function>(*be);
133 if( !f && !l && !fn )
134 tmp << "Throw location unknown (consider using BOOST_THROW_EXCEPTION)\n";
135 else
137 if( f )
139 tmp << *f;
140 if( int const * l=get_error_info<throw_line>(*be) )
141 tmp << '(' << *l << "): ";
143 tmp << "Throw in function ";
144 if( char const * const * fn=get_error_info<throw_function>(*be) )
145 tmp << *fn;
146 else
147 tmp << "(unknown)";
148 tmp << '\n';
151 #ifndef BOOST_NO_RTTI
152 tmp << std::string("Dynamic exception type: ") <<
153 units::detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n';
154 #endif
155 if( with_what && se )
156 tmp << "std::exception::what: " << wh << '\n';
157 if( be )
158 if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
159 if( *s )
160 return s;
161 return tmp.str();
165 template <class T>
166 std::string
167 diagnostic_information( T const & e )
169 return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true);
172 inline
173 char const *
174 diagnostic_information_what( exception const & e ) throw()
176 char const * w=0;
177 #ifndef BOOST_NO_EXCEPTIONS
180 #endif
181 (void) exception_detail::diagnostic_information_impl(&e,0,false);
182 if( char const * di=exception_detail::get_diagnostic_information(e,0) )
183 return di;
184 else
185 return "Failed to produce boost::diagnostic_information_what()";
186 #ifndef BOOST_NO_EXCEPTIONS
188 catch(
189 ... )
192 #endif
193 return w;
197 #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
198 #pragma warning(pop)
199 #endif
200 #endif