Optimization for error_info<throw_function>, error_info<throw_file>, error_info<throw_line>. Refactored exception_ptr to use shared_ptr.

[SVN r48521]
This commit is contained in:
Emil Dotchevski
2008-09-01 21:06:09 +00:00
parent 9a35c999a2
commit b84fb75a60
16 changed files with 418 additions and 455 deletions

View File

@ -6,9 +6,9 @@
#ifndef UUID_0552D49838DD11DD90146B8956D89593
#define UUID_0552D49838DD11DD90146B8956D89593
#include <boost/exception/exception.hpp>
#include <boost/exception/detail/type_info.hpp>
#include <boost/exception/get_error_info.hpp>
#include <exception>
#include <sstream>
#include <string>
namespace
@ -17,13 +17,27 @@ boost
namespace
exception_detail
{
char const *
get_diagnostic_information( exception const & x )
{
if( error_info_container * c=x.data_.get() )
try
{
return c->diagnostic_information();
}
catch(...)
{
}
return 0;
}
template <class T>
std::string
std_exception_diagnostic_information( std::exception const * x, T const & )
{
if( char const * s=x->what() )
if( *s )
return std::string("std::exception::what(): ")+s;
return std::string("\nstd::exception::what(): ")+s;
return std::string();
}
@ -35,58 +49,32 @@ boost
if( std::exception const * x=dynamic_cast<std::exception const *>(&e) )
return std_exception_diagnostic_information(x,e);
else
#endif
return std::string();
}
template <class T>
std::string
boost_exception_diagnostic_information( boost::exception const * x, T const & )
{
if( char const * s=x->diagnostic_information() )
if( *s )
return std::string("boost::exception::diagnostic_information():\n")+s;
return std::string();
}
template <class T>
std::string
boost_exception_diagnostic_information( void const *, T const & e )
{
#ifndef BOOST_NO_RTTI
if( exception const * x=dynamic_cast<exception const *>(&e) )
return boost_exception_diagnostic_information(x,e);
else
#endif
return std::string();
}
}
template <class T>
inline
std::string
diagnostic_information( T const & x )
diagnostic_information( exception const & x )
{
std::string di=
#if defined(BOOST_NO_RTTI) || defined(BOOST_NO_TYPEID)
std::string("Static exception type: ")+BOOST_EXCEPTION_STATIC_TYPEID(T)
#else
std::string("Dynamic exception type: ")+BOOST_EXCEPTION_DYNAMIC_TYPEID(x)
std::ostringstream tmp;
tmp <<
"boost::exception diagnostic information:"
#if !defined(BOOST_NO_RTTI) && !defined(BOOST_NO_TYPEID)
"\nDynamic exception type: " << BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name()
#endif
.name();
std::string di1=exception_detail::std_exception_diagnostic_information(&x,x);
if( !di1.empty() )
{
di+='\n';
di+=di1;
}
std::string di2=exception_detail::boost_exception_diagnostic_information(&x,x);
if( !di2.empty() )
{
di+='\n';
di+=di2;
}
return di;
;
if( boost::shared_ptr<char const * const> f=get_error_info<throw_function>(x) )
tmp << "\nThrow function: " << *f;
if( boost::shared_ptr<char const * const> f=get_error_info<throw_file>(x) )
tmp << "\nThrow file name: " << *f;
if( boost::shared_ptr<int const> l=get_error_info<throw_line>(x) )
tmp << "\nThrow file line: " << *l;
if( char const * s=exception_detail::get_diagnostic_information(x) )
if( *s )
tmp << "\n" << s;
return tmp.str();
}
}