1 #ifndef theplu_yat_utility_boost_exception_ptr_h
2 #define theplu_yat_utility_boost_exception_ptr_h
40 #ifdef YAT_HAVE_WORKING_BOOST_EXCEPTION_PTR
41 #include <boost/exception_ptr.hpp>
44 #ifndef UUID_FA5836A2CADA11DC8CD47C8555D89593
45 #define UUID_FA5836A2CADA11DC8CD47C8555D89593
47 #include <boost/config.hpp>
48 #ifdef BOOST_NO_EXCEPTIONS
49 #error This header requires exception handling to be enabled.
51 #include <boost/exception/exception.hpp>
52 #include <boost/exception/info.hpp>
53 #include <boost/exception/diagnostic_information.hpp>
54 #include <boost/exception/detail/type_info.hpp>
55 #include <boost/shared_ptr.hpp>
64 typedef error_info<struct tag_original_exception_type,std::type_info const *> original_exception_type;
68 to_string( original_exception_type
const & x )
70 return x.value()->name();
75 exception_ptr current_exception();
76 void rethrow_exception( exception_ptr
const & );
80 public exception_detail::exception_ptr_base
82 typedef bool exception_ptr::*unspecified_bool_type;
83 friend exception_ptr current_exception();
84 friend void rethrow_exception( exception_ptr
const & );
86 shared_ptr<exception_detail::clone_base const> c_;
95 exception_ptr( bad_alloc_tag ):
101 exception_ptr( shared_ptr<exception_detail::clone_base const>
const & c ):
113 throw enable_current_exception(std::bad_alloc());
121 return !bad_alloc_ && !c_;
131 ~exception_ptr() throw() { }
133 operator unspecified_bool_type()
const
135 return _empty() ? 0 : &exception_ptr::bad_alloc_;
140 operator==( exception_ptr
const & a, exception_ptr
const & b )
142 return a.c_==b.c_ && a.bad_alloc_==b.bad_alloc_;
147 operator!=( exception_ptr
const & a, exception_ptr
const & b )
156 public std::exception,
157 public exception_detail::clone_base
166 unknown_exception( std::exception
const & e )
168 add_original_type(e);
172 unknown_exception( boost::exception
const & e ):
175 add_original_type(e);
178 ~unknown_exception() throw()
184 exception_detail::clone_base
const *
187 return new unknown_exception(*
this);
198 add_original_type( E
const & e )
200 #ifndef BOOST_NO_RTTI
201 (*this) << original_exception_type(&
typeid(e));
211 current_exception_std_exception_wrapper:
213 public boost::exception,
219 current_exception_std_exception_wrapper( T
const & e1 ):
222 add_original_type(e1);
225 current_exception_std_exception_wrapper( T
const & e1, boost::exception
const & e2 ):
229 add_original_type(e1);
232 ~current_exception_std_exception_wrapper() throw()
241 return new current_exception_std_exception_wrapper(*
this);
252 add_original_type( E
const & e )
254 #ifndef BOOST_NO_RTTI
255 (*this) << original_exception_type(&
typeid(e));
263 get_boost_exception( T
const * )
282 get_boost_exception( T
const * x )
284 return dynamic_cast<exception
const *
>(x);
290 shared_ptr<clone_base const>
291 current_exception_std_exception( T
const & e1 )
293 if( boost::exception
const * e2 = get_boost_exception(&e1) )
294 return shared_ptr<current_exception_std_exception_wrapper<T>
const>(
new current_exception_std_exception_wrapper<T>(e1,*e2));
296 return shared_ptr<current_exception_std_exception_wrapper<T>
const>(
new current_exception_std_exception_wrapper<T>(e1));
300 shared_ptr<clone_base const>
301 current_exception_unknown_exception()
303 return shared_ptr<unknown_exception const>(
new unknown_exception());
307 shared_ptr<clone_base const>
308 current_exception_unknown_boost_exception( boost::exception
const & e )
310 return shared_ptr<unknown_exception const>(
new unknown_exception(e));
314 shared_ptr<clone_base const>
315 current_exception_unknown_std_exception( std::exception
const & e )
317 if( boost::exception
const * be = get_boost_exception(&e) )
318 return current_exception_unknown_boost_exception(*be);
320 return shared_ptr<unknown_exception const>(
new unknown_exception(e));
324 shared_ptr<clone_base const>
325 current_exception_impl()
332 exception_detail::clone_base & e )
334 return shared_ptr<exception_detail::clone_base const>(e.clone());
337 std::domain_error & e )
339 return exception_detail::current_exception_std_exception(e);
342 std::invalid_argument & e )
344 return exception_detail::current_exception_std_exception(e);
347 std::length_error & e )
349 return exception_detail::current_exception_std_exception(e);
352 std::out_of_range & e )
354 return exception_detail::current_exception_std_exception(e);
357 std::logic_error & e )
359 return exception_detail::current_exception_std_exception(e);
362 std::range_error & e )
364 return exception_detail::current_exception_std_exception(e);
367 std::overflow_error & e )
369 return exception_detail::current_exception_std_exception(e);
372 std::underflow_error & e )
374 return exception_detail::current_exception_std_exception(e);
377 std::ios_base::failure & e )
379 return exception_detail::current_exception_std_exception(e);
382 std::runtime_error & e )
384 return exception_detail::current_exception_std_exception(e);
389 return exception_detail::current_exception_std_exception(e);
391 #ifndef BOOST_NO_TYPEID
395 return exception_detail::current_exception_std_exception(e);
398 std::bad_typeid & e )
400 return exception_detail::current_exception_std_exception(e);
404 std::bad_exception & e )
406 return exception_detail::current_exception_std_exception(e);
411 return exception_detail::current_exception_unknown_std_exception(e);
414 boost::exception & e )
416 return exception_detail::current_exception_unknown_boost_exception(e);
421 return exception_detail::current_exception_unknown_exception();
432 return exception_ptr(exception_detail::current_exception_impl());
443 return exception_ptr(exception_detail::current_exception_std_exception(std::bad_exception()));
455 return exception_ptr(exception_ptr::bad_alloc_tag());
461 copy_exception( T
const & e )
465 throw enable_current_exception(e);
470 return current_exception();
476 rethrow_exception( exception_ptr
const & p )
483 to_string( exception_ptr
const & p )
485 std::string s=
'\n'+diagnostic_information(p);
486 std::string padding(
" ");
489 for( std::string::const_iterator i=s.begin(),e=s.end(); i!=e; ++i )
bool operator!=(const DataWeight &, const DataWeight &)
inequality operator
bool operator==(const DNA &lhs, const DNA &rhs)