error.ipp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_TEST_IMPL_ERROR_IPP
  10. #define BOOST_BEAST_TEST_IMPL_ERROR_IPP
  11. #include <boost/beast/_experimental/test/error.hpp>
  12. namespace boost {
  13. namespace beast {
  14. namespace test {
  15. namespace detail {
  16. class error_codes : public error_category
  17. {
  18. public:
  19. BOOST_BEAST_DECL
  20. const char*
  21. name() const noexcept override
  22. {
  23. return "boost.beast.test";
  24. }
  25. BOOST_BEAST_DECL
  26. std::string
  27. message(int ev) const override
  28. {
  29. switch(static_cast<error>(ev))
  30. {
  31. default:
  32. case error::test_failure: return
  33. "An automatic unit test failure occurred";
  34. }
  35. }
  36. BOOST_BEAST_DECL
  37. error_condition
  38. default_error_condition(int ev) const noexcept override
  39. {
  40. return error_condition{ev, *this};
  41. }
  42. };
  43. } // detail
  44. error_code
  45. make_error_code(error e) noexcept
  46. {
  47. static detail::error_codes const cat{};
  48. return error_code{static_cast<
  49. std::underlying_type<error>::type>(e), cat};
  50. }
  51. } // test
  52. } // beast
  53. } // boost
  54. #endif