]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/exception/diagnostic_information.hpp
update boost to 1.44
[lyx.git] / boost / boost / exception / diagnostic_information.hpp
index 2c662201989d0e66a8417b8ffc5d641e23114f16..1d6bc2cc981a8451970e94eb327f5cec5cb5e6b8 100755 (executable)
@@ -1,66 +1,96 @@
-//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
+//Copyright (c) 2006-2010 Emil Dotchevski and Reverge Studios, Inc.
 
 //Distributed under the Boost Software License, Version 1.0. (See accompanying
 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #ifndef UUID_0552D49838DD11DD90146B8956D89593
 #define UUID_0552D49838DD11DD90146B8956D89593
+#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma GCC system_header
+#endif
+#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma warning(push,1)
+#endif
 
 #include <boost/config.hpp>
 #include <boost/exception/get_error_info.hpp>
 #include <boost/utility/enable_if.hpp>
+#ifndef BOOST_NO_RTTI
+#include <boost/units/detail/utility.hpp>
+#endif
 #include <exception>
 #include <sstream>
 #include <string>
 
+#ifndef BOOST_NO_EXCEPTIONS
+#include <boost/exception/current_exception_cast.hpp>
 namespace
 boost
     {
     namespace
     exception_detail
         {
-        template <class T>
-        struct
-        enable_boost_exception_overload
+        std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool );
+        }
+
+    inline
+    std::string
+    current_exception_diagnostic_information()
+        {
+        boost::exception const * be=current_exception_cast<boost::exception const>();
+        std::exception const * se=current_exception_cast<std::exception const>();
+        if( be || se )
+            return exception_detail::diagnostic_information_impl(be,se,true);
+        else
+            return "No diagnostic information available.";
+        }
+    }
+#endif
+
+namespace
+boost
+    {
+    namespace
+    exception_detail
+        {
+        inline
+        exception const *
+        get_boost_exception( exception const * e )
             {
-            struct yes { char q[100]; };
-            typedef char no;
-            static yes check(exception const *);
-            static no check(...);
-            enum e { value=sizeof(check((T*)0))==sizeof(yes) };
-            };
+            return e;
+            }
 
-        template <class T>
-        struct
-        enable_std_exception_overload
+        inline
+        exception const *
+        get_boost_exception( ... )
             {
-            struct yes { char q[100]; };
-            typedef char no;
-            static yes check(std::exception const *);
-            static no check(...);
-            enum e { value = !enable_boost_exception_overload<T>::value && sizeof(check((T*)0))==sizeof(yes) };
-            };
+            return 0;
+            }
 
-#ifndef BOOST_NO_RTTI
-        template <class T>
         inline
-        std::string
-        dynamic_exception_type( T const & x )
+        std::exception const *
+        get_std_exception( std::exception const * e )
             {
-            return std::string("Dynamic exception type: ") + BOOST_EXCEPTION_DYNAMIC_TYPEID(x).name();
+            return e;
+            }
+
+        inline
+        std::exception const *
+        get_std_exception( ... )
+            {
+            return 0;
             }
-#endif
 
         inline
         char const *
-        get_diagnostic_information( exception const & x )
+        get_diagnostic_information( exception const & x, char const * header )
             {
             if( error_info_container * c=x.data_.get() )
 #ifndef BOOST_NO_EXCEPTIONS
                 try
                     {
 #endif
-                    return c->diagnostic_information();
+                    return c->diagnostic_information(header);
 #ifndef BOOST_NO_EXCEPTIONS
                     }
                 catch(...)
@@ -72,81 +102,83 @@ boost
 
         inline
         std::string
-        boost_diagnostic_information( exception const & x )
+        diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what )
             {
-            std::ostringstream tmp;
-            if( char const * const * f=get_error_info<throw_file>(x) )
-                {
-                tmp << *f;
-                if( int const * l=get_error_info<throw_line>(x) )
-                    tmp << '(' << *l << "): ";
-                }
-            tmp << "Throw in function ";
-            if( char const * const * fn=get_error_info<throw_function>(x) )
-                tmp << *fn;
-            else
-                tmp << "(unknown)";
-            tmp << std::endl;
+            if( !be && !se )
+                return "Unknown exception.";
 #ifndef BOOST_NO_RTTI
-            tmp << dynamic_exception_type(x) << std::endl;
-            if( std::exception const * e=dynamic_cast<std::exception const *>(&x) )
-                tmp << "std::exception::what: " << e->what() << std::endl;
+            if( !be )
+                be=dynamic_cast<boost::exception const *>(se);
+            if( !se )
+                se=dynamic_cast<std::exception const *>(be);
 #endif
-            if( char const * s=exception_detail::get_diagnostic_information(x) )
-                if( *s )
-                    tmp << s;
-            return tmp.str();
-            }
-
-        inline
-        std::string
-        std_diagnostic_information( std::exception const & x )
-            {
+            char const * wh=0;
+            if( with_what && se )
+                {
+                wh=se->what();
+                if( be && exception_detail::get_diagnostic_information(*be,0)==wh )
+                    return wh;
+                }
             std::ostringstream tmp;
+            if( be )
+                {
+                if( char const * const * f=get_error_info<throw_file>(*be) )
+                    {
+                    tmp << *f;
+                    if( int const * l=get_error_info<throw_line>(*be) )
+                        tmp << '(' << *l << "): ";
+                    }
+                tmp << "Throw in function ";
+                if( char const * const * fn=get_error_info<throw_function>(*be) )
+                    tmp << *fn;
+                else
+                    tmp << "(unknown)";
+                tmp << '\n';
+                }
 #ifndef BOOST_NO_RTTI
-            if( exception const * e=dynamic_cast<exception const *>(&x) )
-                return boost_diagnostic_information(*e);
-            tmp << dynamic_exception_type(x) << std::endl;
+            tmp << std::string("Dynamic exception type: ") <<
+                units::detail::demangle((be?BOOST_EXCEPTION_DYNAMIC_TYPEID(*be):BOOST_EXCEPTION_DYNAMIC_TYPEID(*se)).type_.name()) << '\n';
 #endif
-            tmp << "std::exception::what: " << x.what() << std::endl;
+            if( with_what && se )
+                tmp << "std::exception::what: " << wh << '\n';
+            if( be )
+                if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) )
+                    if( *s )
+                        return s;
             return tmp.str();
             }
         }
 
     template <class T>
-    inline
-    typename enable_if<exception_detail::enable_boost_exception_overload<T>,std::string>::type
+    std::string
     diagnostic_information( T const & e )
         {
-        return exception_detail::boost_diagnostic_information(e);
+        return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true);
         }
 
-    template <class T>
     inline
-    typename enable_if<exception_detail::enable_std_exception_overload<T>,std::string>::type
-    diagnostic_information( T const & e )
+    char const *
+    diagnostic_information_what( exception const & e ) throw()
         {
-        return exception_detail::std_diagnostic_information(e);
+        char const * w=0;
+#ifndef BOOST_NO_EXCEPTIONS
+        try
+            {
+#endif
+            (void) exception_detail::diagnostic_information_impl(&e,0,false);
+            return exception_detail::get_diagnostic_information(e,0);
+#ifndef BOOST_NO_EXCEPTIONS
+            }
+        catch(
+        ... )
+            {
+            }
+#endif
+        return w;
         }
     }
 
-#ifndef BOOST_NO_EXCEPTIONS
-#include <boost/exception/current_exception_cast.hpp>
-namespace
-boost
-    {
-    inline
-    std::string
-    current_exception_diagnostic_information()
-        {
-        if( boost::exception const * e=current_exception_cast<boost::exception const>() )
-            return diagnostic_information(*e);
-        else if( std::exception const * e=current_exception_cast<std::exception const>() )
-            return diagnostic_information(*e);
-        else
-            return "No diagnostic information available.";
-        }
-       }
+#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
+#pragma warning(pop)
 #endif
-
 #endif