error.ipp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. // This is a derivative work based on Zlib, copyright below:
  10. /*
  11. Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
  12. This software is provided 'as-is', without any express or implied
  13. warranty. In no event will the authors be held liable for any damages
  14. arising from the use of this software.
  15. Permission is granted to anyone to use this software for any purpose,
  16. including commercial applications, and to alter it and redistribute it
  17. freely, subject to the following restrictions:
  18. 1. The origin of this software must not be misrepresented; you must not
  19. claim that you wrote the original software. If you use this software
  20. in a product, an acknowledgment in the product documentation would be
  21. appreciated but is not required.
  22. 2. Altered source versions must be plainly marked as such, and must not be
  23. misrepresented as being the original software.
  24. 3. This notice may not be removed or altered from any source distribution.
  25. Jean-loup Gailly Mark Adler
  26. jloup@gzip.org madler@alumni.caltech.edu
  27. The data format used by the zlib library is described by RFCs (Request for
  28. Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
  29. (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
  30. */
  31. #ifndef BOOST_BEAST_ZLIB_IMPL_ERROR_IPP
  32. #define BOOST_BEAST_ZLIB_IMPL_ERROR_IPP
  33. #include <boost/beast/zlib/error.hpp>
  34. #include <type_traits>
  35. namespace boost {
  36. namespace beast {
  37. namespace zlib {
  38. namespace detail {
  39. class error_codes : public error_category
  40. {
  41. public:
  42. const char*
  43. name() const noexcept override
  44. {
  45. return "boost.beast.zlib";
  46. }
  47. std::string
  48. message(int ev) const override
  49. {
  50. switch(static_cast<error>(ev))
  51. {
  52. case error::need_buffers: return "need buffers";
  53. case error::end_of_stream: return "unexpected end of deflate stream";
  54. case error::need_dict: return "need dict";
  55. case error::stream_error: return "stream error";
  56. case error::invalid_block_type: return "invalid block type";
  57. case error::invalid_stored_length: return "invalid stored block length";
  58. case error::too_many_symbols: return "too many symbols";
  59. case error::invalid_code_lengths: return "invalid code lengths";
  60. case error::invalid_bit_length_repeat: return "invalid bit length repeat";
  61. case error::missing_eob: return "missing end of block code";
  62. case error::invalid_literal_length: return "invalid literal/length code";
  63. case error::invalid_distance_code: return "invalid distance code";
  64. case error::invalid_distance: return "invalid distance";
  65. case error::over_subscribed_length: return "over-subscribed length";
  66. case error::incomplete_length_set: return "incomplete length set";
  67. case error::general:
  68. default:
  69. return "beast.zlib error";
  70. }
  71. }
  72. error_condition
  73. default_error_condition(int ev) const noexcept override
  74. {
  75. return error_condition{ev, *this};
  76. }
  77. bool
  78. equivalent(int ev,
  79. error_condition const& condition
  80. ) const noexcept override
  81. {
  82. return condition.value() == ev &&
  83. &condition.category() == this;
  84. }
  85. bool
  86. equivalent(error_code const& error, int ev) const noexcept override
  87. {
  88. return error.value() == ev &&
  89. &error.category() == this;
  90. }
  91. };
  92. } // detail
  93. error_code
  94. make_error_code(error ev)
  95. {
  96. static detail::error_codes const cat{};
  97. return error_code{static_cast<
  98. std::underlying_type<error>::type>(ev), cat};
  99. }
  100. } // zlib
  101. } // beast
  102. } // boost
  103. #endif