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 BOOST_EXCEPTION_E788439ED9F011DCB181F25B55D89593 |
7 | #define BOOST_EXCEPTION_E788439ED9F011DCB181F25B55D89593 |
8 | |
9 | #include <boost/exception/to_string.hpp> |
10 | #include <boost/exception/detail/object_hex_dump.hpp> |
11 | #include <boost/assert.hpp> |
12 | |
13 | #ifndef BOOST_EXCEPTION_ENABLE_WARNINGS |
14 | #if __GNUC__*100+__GNUC_MINOR__>301 |
15 | #pragma GCC system_header |
16 | #endif |
17 | #ifdef __clang__ |
18 | #pragma clang system_header |
19 | #endif |
20 | #ifdef _MSC_VER |
21 | #pragma warning(push,1) |
22 | #endif |
23 | #endif |
24 | |
25 | namespace |
26 | boost |
27 | { |
28 | namespace |
29 | exception_detail |
30 | { |
31 | template <bool ToStringAvailable> |
32 | struct |
33 | to_string_dispatcher |
34 | { |
35 | template <class T,class Stub> |
36 | static |
37 | std::string |
38 | convert( T const & x, Stub ) |
39 | { |
40 | return to_string(x); |
41 | } |
42 | }; |
43 | |
44 | template <> |
45 | struct |
46 | to_string_dispatcher<false> |
47 | { |
48 | template <class T,class Stub> |
49 | static |
50 | std::string |
51 | convert( T const & x, Stub s ) |
52 | { |
53 | return s(x); |
54 | } |
55 | |
56 | template <class T> |
57 | static |
58 | std::string |
59 | convert( T const & x, std::string s ) |
60 | { |
61 | return s; |
62 | } |
63 | |
64 | template <class T> |
65 | static |
66 | std::string |
67 | convert( T const & x, char const * s ) |
68 | { |
69 | BOOST_ASSERT(s!=0); |
70 | return s; |
71 | } |
72 | }; |
73 | |
74 | namespace |
75 | to_string_dispatch |
76 | { |
77 | template <class T,class Stub> |
78 | inline |
79 | std::string |
80 | dispatch( T const & x, Stub s ) |
81 | { |
82 | return to_string_dispatcher<has_to_string<T>::value>::convert(x,s); |
83 | } |
84 | } |
85 | |
86 | template <class T> |
87 | inline |
88 | std::string |
89 | string_stub_dump( T const & x ) |
90 | { |
91 | return "[ " + exception_detail::object_hex_dump(x) + " ]" ; |
92 | } |
93 | } |
94 | |
95 | template <class T> |
96 | inline |
97 | std::string |
98 | to_string_stub( T const & x ) |
99 | { |
100 | return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump<T>); |
101 | } |
102 | |
103 | template <class T,class Stub> |
104 | inline |
105 | std::string |
106 | to_string_stub( T const & x, Stub s ) |
107 | { |
108 | return exception_detail::to_string_dispatch::dispatch(x,s); |
109 | } |
110 | |
111 | template <class T,class U,class Stub> |
112 | inline |
113 | std::string |
114 | to_string_stub( std::pair<T,U> const & x, Stub s ) |
115 | { |
116 | return std::string("(" ) + to_string_stub(x.first,s) + ',' + to_string_stub(x.second,s) + ')'; |
117 | } |
118 | } |
119 | |
120 | #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) |
121 | #pragma warning(pop) |
122 | #endif |
123 | #endif |
124 | |