error.ipp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. char const*
  27. message(int ev, char*, std::size_t) const noexcept 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. std::string
  38. message(int ev) const override
  39. {
  40. return message(ev, nullptr, 0);
  41. }
  42. BOOST_BEAST_DECL
  43. error_condition
  44. default_error_condition(int ev) const noexcept override
  45. {
  46. return error_condition{ev, *this};
  47. }
  48. };
  49. } // detail
  50. error_code
  51. make_error_code(error e) noexcept
  52. {
  53. static detail::error_codes const cat{};
  54. return error_code{static_cast<
  55. std::underlying_type<error>::type>(e), cat};
  56. }
  57. } // test
  58. } // beast
  59. } // boost
  60. #endif