/Src/Dependencies/Boost/boost/exception/get_error_info.hpp

http://hadesmem.googlecode.com/ · C++ Header · 130 lines · 116 code · 11 blank · 3 comment · 6 complexity · 0023ab9fad45d3dde22c27b04fa64924 MD5 · raw file

  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_1A590226753311DD9E4CCF6156D89593
  5. #define UUID_1A590226753311DD9E4CCF6156D89593
  6. #if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  7. #pragma GCC system_header
  8. #endif
  9. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  10. #pragma warning(push,1)
  11. #endif
  12. #include <boost/exception/exception.hpp>
  13. #include <boost/exception/detail/error_info_impl.hpp>
  14. #include <boost/exception/detail/type_info.hpp>
  15. #include <boost/shared_ptr.hpp>
  16. namespace
  17. boost
  18. {
  19. namespace
  20. exception_detail
  21. {
  22. template <class ErrorInfo>
  23. struct
  24. get_info
  25. {
  26. static
  27. typename ErrorInfo::value_type *
  28. get( exception const & x )
  29. {
  30. if( exception_detail::error_info_container * c=x.data_.get() )
  31. if( shared_ptr<exception_detail::error_info_base> eib = c->get(BOOST_EXCEPTION_STATIC_TYPEID(ErrorInfo)) )
  32. {
  33. #ifndef BOOST_NO_RTTI
  34. BOOST_ASSERT( 0!=dynamic_cast<ErrorInfo *>(eib.get()) );
  35. #endif
  36. ErrorInfo * w = static_cast<ErrorInfo *>(eib.get());
  37. return &w->value();
  38. }
  39. return 0;
  40. }
  41. };
  42. template <>
  43. struct
  44. get_info<throw_function>
  45. {
  46. static
  47. char const * *
  48. get( exception const & x )
  49. {
  50. return x.throw_function_ ? &x.throw_function_ : 0;
  51. }
  52. };
  53. template <>
  54. struct
  55. get_info<throw_file>
  56. {
  57. static
  58. char const * *
  59. get( exception const & x )
  60. {
  61. return x.throw_file_ ? &x.throw_file_ : 0;
  62. }
  63. };
  64. template <>
  65. struct
  66. get_info<throw_line>
  67. {
  68. static
  69. int *
  70. get( exception const & x )
  71. {
  72. return x.throw_line_!=-1 ? &x.throw_line_ : 0;
  73. }
  74. };
  75. template <class T,class R>
  76. struct
  77. get_error_info_return_type
  78. {
  79. typedef R * type;
  80. };
  81. template <class T,class R>
  82. struct
  83. get_error_info_return_type<T const,R>
  84. {
  85. typedef R const * type;
  86. };
  87. }
  88. #ifdef BOOST_NO_RTTI
  89. template <class ErrorInfo>
  90. inline
  91. typename ErrorInfo::value_type const *
  92. get_error_info( boost::exception const & x )
  93. {
  94. return exception_detail::get_info<ErrorInfo>::get(x);
  95. }
  96. template <class ErrorInfo>
  97. inline
  98. typename ErrorInfo::value_type *
  99. get_error_info( boost::exception & x )
  100. {
  101. return exception_detail::get_info<ErrorInfo>::get(x);
  102. }
  103. #else
  104. template <class ErrorInfo,class E>
  105. inline
  106. typename exception_detail::get_error_info_return_type<E,typename ErrorInfo::value_type>::type
  107. get_error_info( E & some_exception )
  108. {
  109. if( exception const * x = dynamic_cast<exception const *>(&some_exception) )
  110. return exception_detail::get_info<ErrorInfo>::get(*x);
  111. else
  112. return 0;
  113. }
  114. #endif
  115. }
  116. #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
  117. #pragma warning(pop)
  118. #endif
  119. #endif