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