Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 2491bd6 | 2013-10-15 17:10:24 -0700 | [diff] [blame] | 6 | #ifndef NDNBOOST_UUID_1A590226753311DD9E4CCF6156D89593 |
| 7 | #define NDNBOOST_UUID_1A590226753311DD9E4CCF6156D89593 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 8 | #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 9 | #pragma GCC system_header |
| 10 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 11 | #if defined(_MSC_VER) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 12 | #pragma warning(push,1) |
| 13 | #endif |
| 14 | |
| 15 | #include <ndnboost/exception/exception.hpp> |
| 16 | #include <ndnboost/exception/detail/error_info_impl.hpp> |
| 17 | #include <ndnboost/exception/detail/type_info.hpp> |
| 18 | #include <ndnboost/shared_ptr.hpp> |
| 19 | |
| 20 | namespace |
| 21 | ndnboost |
| 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() ) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 35 | if( shared_ptr<exception_detail::error_info_base> eib = c->get(NDNBOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 36 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 37 | #ifndef NDNBOOST_NO_RTTI |
| 38 | NDNBOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 98 | #ifdef NDNBOOST_NO_RTTI |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 99 | template <class ErrorInfo> |
| 100 | inline |
| 101 | typename ErrorInfo::value_type const * |
| 102 | get_error_info( ndnboost::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( ndnboost::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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 127 | #if defined(_MSC_VER) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 128 | #pragma warning(pop) |
| 129 | #endif |
| 130 | #endif |