to_string_stub.hpp
Go to the documentation of this file.
00001 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
00002 
00003 //Distributed under the Boost Software License, Version 1.0. (See accompanying
00004 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef UUID_E788439ED9F011DCB181F25B55D89593
00007 #define UUID_E788439ED9F011DCB181F25B55D89593
00008 
00009 #include <boost/exception/to_string.hpp>
00010 #include <boost/exception/detail/object_hex_dump.hpp>
00011 #include <boost/assert.hpp>
00012 
00013 namespace
00014 boost
00015     {
00016     namespace
00017     exception_detail
00018         {
00019         template <bool ToStringAvailable>
00020         struct
00021         to_string_dispatcher
00022             {
00023             template <class T,class Stub>
00024             static
00025             std::string
00026             convert( T const & x, Stub )
00027                 {
00028                 return to_string(x);
00029                 }
00030             };
00031 
00032         template <>
00033         struct
00034         to_string_dispatcher<false>
00035             {
00036             template <class T,class Stub>
00037             static
00038             std::string
00039             convert( T const & x, Stub s )
00040                 {
00041                 return s(x);
00042                 }
00043 
00044             template <class T>
00045             static
00046             std::string
00047             convert( T const & x, std::string s )
00048                 {
00049                 return s;
00050                 }
00051 
00052             template <class T>
00053             static
00054             std::string
00055             convert( T const & x, char const * s )
00056                 {
00057                 BOOST_ASSERT(s!=0);
00058                 return s;
00059                 }
00060             };
00061 
00062         namespace
00063         to_string_dispatch
00064             {
00065             template <class T,class Stub>
00066             inline
00067             std::string
00068             dispatch( T const & x, Stub s )
00069                 {
00070                 return to_string_dispatcher<has_to_string<T>::value>::convert(x,s);
00071                 }
00072             }
00073 
00074         template <class T>
00075         inline
00076         std::string
00077         string_stub_dump( T const & x )
00078             {
00079             return "[ " + exception_detail::object_hex_dump(x) + " ]";
00080             }
00081         }
00082 
00083     template <class T>
00084     inline
00085     std::string
00086     to_string_stub( T const & x )
00087         {
00088         return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump<T>);
00089         }
00090 
00091     template <class T,class Stub>
00092     inline
00093     std::string
00094     to_string_stub( T const & x, Stub s )
00095         {
00096         return exception_detail::to_string_dispatch::dispatch(x,s);
00097         }
00098     }
00099 
00100 #endif


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29