blob: cb3415439352c00f0565b88bc72c8dabd9d81d18 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001//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 Thompson2491bd62013-10-15 17:10:24 -07006#ifndef NDNBOOST_UUID_1A590226753311DD9E4CCF6156D89593
7#define NDNBOOST_UUID_1A590226753311DD9E4CCF6156D89593
Jeff Thompson3d613fd2013-10-15 15:39:04 -07008#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07009#pragma GCC system_header
10#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070011#if defined(_MSC_VER) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070012#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
20namespace
21ndnboost
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 Thompson3d613fd2013-10-15 15:39:04 -070035 if( shared_ptr<exception_detail::error_info_base> eib = c->get(NDNBOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070036 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -070037#ifndef NDNBOOST_NO_RTTI
38 NDNBOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070039#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 Thompson3d613fd2013-10-15 15:39:04 -070098#ifdef NDNBOOST_NO_RTTI
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070099 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 Thompson3d613fd2013-10-15 15:39:04 -0700127#if defined(_MSC_VER) && !defined(NDNBOOST_EXCEPTION_ENABLE_WARNINGS)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700128#pragma warning(pop)
129#endif
130#endif