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