PageRenderTime 14ms CodeModel.GetById 6ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/exception/get_error_info.hpp

http://hadesmem.googlecode.com/
C++ Header | 130 lines | 116 code | 11 blank | 3 comment | 6 complexity | 0023ab9fad45d3dde22c27b04fa64924 MD5 | raw file
  1//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2
  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)
  5
  6#ifndef UUID_1A590226753311DD9E4CCF6156D89593
  7#define UUID_1A590226753311DD9E4CCF6156D89593
  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
 14
 15#include <boost/exception/exception.hpp>
 16#include <boost/exception/detail/error_info_impl.hpp>
 17#include <boost/exception/detail/type_info.hpp>
 18#include <boost/shared_ptr.hpp>
 19
 20namespace
 21boost
 22    {
 23    namespace
 24    exception_detail
 25        {
 26        template <class ErrorInfo>
 27        struct
 28        get_info
 29            {
 30            static
 31            typename ErrorInfo::value_type *
 32            get( exception const & x )
 33                {
 34                if( exception_detail::error_info_container * c=x.data_.get() )
 35                    if( shared_ptr<exception_detail::error_info_base> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
 36                        {
 37#ifndef BOOST_NO_RTTI
 38                        BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
 39#endif
 40                        ErrorInfo * w = static_cast<ErrorInfo *>(eib.get());
 41                        return &w->value();
 42                        }
 43                return 0;
 44                }
 45            };
 46
 47        template <>
 48        struct
 49        get_info<throw_function>
 50            {
 51            static
 52            char const * *
 53            get( exception const & x )
 54                {
 55                return x.throw_function_ ? &x.throw_function_ : 0;
 56                }
 57            };
 58
 59        template <>
 60        struct
 61        get_info<throw_file>
 62            {
 63            static
 64            char const * *
 65            get( exception const & x )
 66                {
 67                return x.throw_file_ ? &x.throw_file_ : 0;
 68                }
 69            };
 70
 71        template <>
 72        struct
 73        get_info<throw_line>
 74            {
 75            static
 76            int *
 77            get( exception const & x )
 78                {
 79                return x.throw_line_!=-1 ? &x.throw_line_ : 0;
 80                }
 81            };
 82
 83        template <class T,class R>
 84        struct
 85        get_error_info_return_type
 86            {
 87            typedef R * type;
 88            };
 89
 90        template <class T,class R>
 91        struct
 92        get_error_info_return_type<T const,R>
 93            {
 94            typedef R const * type;
 95            };
 96        }
 97
 98#ifdef BOOST_NO_RTTI
 99    template <class ErrorInfo>
100    inline
101    typename ErrorInfo::value_type const *
102    get_error_info( boost::exception const & x )
103        {
104        return exception_detail::get_info<ErrorInfo>::get(x);
105        }
106    template <class ErrorInfo>
107    inline
108    typename ErrorInfo::value_type *
109    get_error_info( boost::exception & x )
110        {
111        return exception_detail::get_info<ErrorInfo>::get(x);
112        }
113#else
114    template <class ErrorInfo,class E>
115    inline
116    typename exception_detail::get_error_info_return_type<E,typename ErrorInfo::value_type>::type
117    get_error_info( E & some_exception )
118        {
119        if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
120            return exception_detail::get_info<ErrorInfo>::get(*x);
121        else
122            return 0;
123        }
124#endif
125    }
126
127#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
128#pragma warning(pop)
129#endif
130#endif