error.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright (c) 2023 Klemens D. Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_COBALT_ERROR_HPP
  6. #define BOOST_COBALT_ERROR_HPP
  7. #include <boost/cobalt/config.hpp>
  8. #include <boost/system/error_code.hpp>
  9. namespace boost::cobalt
  10. {
  11. enum class error
  12. {
  13. moved_from,
  14. detached,
  15. completed_unexpected,
  16. wait_not_ready,
  17. already_awaited,
  18. allocation_failed
  19. };
  20. struct cobalt_category_t final : system::error_category
  21. {
  22. cobalt_category_t() : system::error_category(0x7d4c7b49d8a4fdull) {}
  23. std::string message( int ev ) const override
  24. {
  25. return message(ev, nullptr, 0u);
  26. }
  27. char const * message( int ev, char * , std::size_t ) const noexcept override
  28. {
  29. switch (static_cast<error>(ev))
  30. {
  31. case error::moved_from:
  32. return "moved from";
  33. case error::detached:
  34. return "detached";
  35. case error::completed_unexpected:
  36. return "completed unexpected";
  37. case error::wait_not_ready:
  38. return "wait not ready";
  39. case error::already_awaited:
  40. return "already awaited";
  41. case error::allocation_failed:
  42. return "allocation failed";
  43. default:
  44. return "unknown cobalt error";
  45. }
  46. }
  47. const char * name() const BOOST_NOEXCEPT override
  48. {
  49. return "boost.cobalt";
  50. }
  51. };
  52. BOOST_COBALT_DECL system::error_category & cobalt_category();
  53. BOOST_COBALT_DECL system::error_code make_error_code(error e);
  54. }
  55. template<> struct boost::system::is_error_code_enum<boost::cobalt::error>
  56. {
  57. static const bool value = true;
  58. };
  59. #endif //BOOST_COBALT_ERROR_HPP