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