get_error_info.hpp
Go to the documentation of this file.
00001 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
00002 
00003 //Distributed under the Boost Software License, Version 1.0. (See accompanying
00004 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef UUID_1A590226753311DD9E4CCF6156D89593
00007 #define UUID_1A590226753311DD9E4CCF6156D89593
00008 
00009 #include <boost/exception/exception.hpp>
00010 #include <boost/exception/detail/error_info_impl.hpp>
00011 #include <boost/exception/detail/type_info.hpp>
00012 #include <boost/shared_ptr.hpp>
00013 
00014 namespace
00015 boost
00016     {
00017     namespace
00018     exception_detail
00019         {
00020         template <class ErrorInfo>
00021         struct
00022         get_info
00023             {
00024             static
00025             typename ErrorInfo::value_type const *
00026             get( exception const & x )
00027                 {
00028                 if( exception_detail::error_info_container * c=x.data_.get() )
00029                     if( shared_ptr<exception_detail::error_info_base const> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
00030                         {
00031 #ifndef BOOST_NO_RTTI
00032                         BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo const *>(eib.get()) );
00033 #endif
00034                         ErrorInfo const * w = static_cast<ErrorInfo const *>(eib.get());
00035                         return &w->value();
00036                         }
00037                 return 0;
00038                 }
00039             };
00040 
00041         template <>
00042         struct
00043         get_info<throw_function>
00044             {
00045             static
00046             char const * const *
00047             get( exception const & x )
00048                 {
00049                 return x.throw_function_ ? &x.throw_function_ : 0;
00050                 }
00051             };
00052 
00053         template <>
00054         struct
00055         get_info<throw_file>
00056             {
00057             static
00058             char const * const *
00059             get( exception const & x )
00060                 {
00061                 return x.throw_file_ ? &x.throw_file_ : 0;
00062                 }
00063             };
00064 
00065         template <>
00066         struct
00067         get_info<throw_line>
00068             {
00069             static
00070             int const *
00071             get( exception const & x )
00072                 {
00073                 return x.throw_line_!=-1 ? &x.throw_line_ : 0;
00074                 }
00075             };
00076         }
00077 
00078 #ifdef BOOST_NO_RTTI
00079     template <class ErrorInfo>
00080     inline
00081     typename ErrorInfo::value_type const *
00082     get_error_info( boost::exception const & x )
00083         {
00084         return exception_detail::get_info<ErrorInfo>::get(x);
00085         }
00086 #else
00087     template <class ErrorInfo,class E>
00088     inline
00089     typename ErrorInfo::value_type const *
00090     get_error_info( E const & some_exception )
00091         {
00092         if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
00093             return exception_detail::get_info<ErrorInfo>::get(*x);
00094         else
00095             return 0;
00096         }
00097 #endif
00098     }
00099 
00100 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29