to_string_stub.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef UUID_E788439ED9F011DCB181F25B55D89593
  5. #define UUID_E788439ED9F011DCB181F25B55D89593
  6. #include <boost/exception/to_string.hpp>
  7. #include <boost/exception/detail/object_hex_dump.hpp>
  8. #include <boost/assert.hpp>
  9. #if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  10. #pragma GCC system_header
  11. #endif
  12. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  13. #pragma warning(push,1)
  14. #endif
  15. namespace
  16. boost
  17. {
  18. namespace
  19. exception_detail
  20. {
  21. template <bool ToStringAvailable>
  22. struct
  23. to_string_dispatcher
  24. {
  25. template <class T,class Stub>
  26. static
  27. std::string
  28. convert( T const & x, Stub )
  29. {
  30. return to_string(x);
  31. }
  32. };
  33. template <>
  34. struct
  35. to_string_dispatcher<false>
  36. {
  37. template <class T,class Stub>
  38. static
  39. std::string
  40. convert( T const & x, Stub s )
  41. {
  42. return s(x);
  43. }
  44. template <class T>
  45. static
  46. std::string
  47. convert( T const & x, std::string s )
  48. {
  49. return s;
  50. }
  51. template <class T>
  52. static
  53. std::string
  54. convert( T const & x, char const * s )
  55. {
  56. BOOST_ASSERT(s!=0);
  57. return s;
  58. }
  59. };
  60. namespace
  61. to_string_dispatch
  62. {
  63. template <class T,class Stub>
  64. inline
  65. std::string
  66. dispatch( T const & x, Stub s )
  67. {
  68. return to_string_dispatcher<has_to_string<T>::value>::convert(x,s);
  69. }
  70. }
  71. template <class T>
  72. inline
  73. std::string
  74. string_stub_dump( T const & x )
  75. {
  76. return "[ " + exception_detail::object_hex_dump(x) + " ]";
  77. }
  78. }
  79. template <class T>
  80. inline
  81. std::string
  82. to_string_stub( T const & x )
  83. {
  84. return exception_detail::to_string_dispatch::dispatch(x,&exception_detail::string_stub_dump<T>);
  85. }
  86. template <class T,class Stub>
  87. inline
  88. std::string
  89. to_string_stub( T const & x, Stub s )
  90. {
  91. return exception_detail::to_string_dispatch::dispatch(x,s);
  92. }
  93. template <class T,class U,class Stub>
  94. inline
  95. std::string
  96. to_string_stub( std::pair<T,U> const & x, Stub s )
  97. {
  98. return std::string("(") + to_string_stub(x.first,s) + ',' + to_string_stub(x.second,s) + ')';
  99. }
  100. }
  101. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  102. #pragma warning(pop)
  103. #endif
  104. #endif