//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. //Distributed under the Boost Software License, Version 1.0. (See accompanying //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef UUID_E788439ED9F011DCB181F25B55D89593 #define UUID_E788439ED9F011DCB181F25B55D89593 #include #include namespace boost { namespace exception_detail { template struct shift_left_dispatcher; template <> struct shift_left_dispatcher { template static void convert( std::basic_ostream & out, T const & x, Stub ) { out << x; } }; template <> struct shift_left_dispatcher { template static void convert( std::basic_ostream & out, T const & x, Stub s ) { out << s(x); } }; namespace shift_left_dispatch { template char operator<<( std::basic_ostream &, T ); template void dispatch( std::basic_ostream & out, T const & x, Stub s ) { shift_left_dispatcher<1!=sizeof(out<::convert(out,x,s); } } } namespace exception_detail { template struct to_string_dispatcher; template <> struct to_string_dispatcher { template static std::string convert( T const & x, Stub ) { return to_string(x); } }; template <> struct to_string_dispatcher { template static std::string convert( T const & x, Stub s ) { std::ostringstream out; shift_left_dispatch::dispatch(out,x,s); return out.str(); } }; namespace to_string_dispatch { template char to_string( T ); template std::string dispatch( T const & x, Stub s ) { return to_string_dispatcher<1!=sizeof(to_string(x))>::convert(x,s); } } template std::string string_stub_dump( T const & x ) { std::ostringstream s; s << "[ type: " << typeid(x).name() << ", size: " << sizeof(T) << ", dump: "; size_t n=sizeof(T)>16?16:sizeof(T); s.fill('0'); s.width(2); for( unsigned char const * b=reinterpret_cast(&x),* e=b+n; b!=e; ++b ) s << std::setw(2) << std::hex << (unsigned int)*b << " "; s << "]"; return s.str(); } } template std::string to_string_stub( T const & x ) { return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump); } template std::string to_string_stub( T const & x, Stub s ) { return exception_detail::to_string_dispatch::dispatch(x,s); } template std::string to_string( std::pair const & x ) { return std::string("(") + to_string(x.first) + ',' + to_string(x.second) + ')'; } } #endif