]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/zlib/impl/error.ipp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / zlib / impl / error.ipp
1 //
2 // Copyright (c) 2016-2017 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
13 This software is provided 'as-is', without any express or implied
14 warranty. In no event will the authors be held liable for any damages
15 arising from the use of this software.
16
17 Permission is granted to anyone to use this software for any purpose,
18 including commercial applications, and to alter it and redistribute it
19 freely, subject to the following restrictions:
20
21 1. The origin of this software must not be misrepresented; you must not
22 claim that you wrote the original software. If you use this software
23 in a product, an acknowledgment in the product documentation would be
24 appreciated but is not required.
25 2. Altered source versions must be plainly marked as such, and must not be
26 misrepresented as being the original software.
27 3. This notice may not be removed or altered from any source distribution.
28
29 Jean-loup Gailly Mark Adler
30 jloup@gzip.org madler@alumni.caltech.edu
31
32 The data format used by the zlib library is described by RFCs (Request for
33 Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
34 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
35 */
36
37 #ifndef BOOST_BEAST_ZLIB_IMPL_ERROR_IPP
38 #define BOOST_BEAST_ZLIB_IMPL_ERROR_IPP
39
40 #include <boost/beast/core/error.hpp>
41 #include <type_traits>
42
43 namespace boost {
44
45 namespace system {
46 template<>
47 struct is_error_code_enum<beast::zlib::error>
48 {
49 static bool const value = true;
50 };
51 } // system
52
53 namespace beast {
54 namespace zlib {
55 namespace detail {
56
57 class zlib_error_category : public error_category
58 {
59 public:
60 const char*
61 name() const noexcept override
62 {
63 return "beast.zlib";
64 }
65
66 std::string
67 message(int ev) const override
68 {
69 switch(static_cast<error>(ev))
70 {
71 case error::need_buffers: return "need buffers";
72 case error::end_of_stream: return "unexpected end of deflate stream";
73 case error::stream_error: return "stream error";
74
75 case error::invalid_block_type: return "invalid block type";
76 case error::invalid_stored_length: return "invalid stored block length";
77 case error::too_many_symbols: return "too many symbols";
78 case error::invalid_code_lenths: return "invalid code lengths";
79 case error::invalid_bit_length_repeat: return "invalid bit length repeat";
80 case error::missing_eob: return "missing end of block code";
81 case error::invalid_literal_length: return "invalid literal/length code";
82 case error::invalid_distance_code: return "invalid distance code";
83 case error::invalid_distance: return "invalid distance";
84
85 case error::over_subscribed_length: return "over-subscribed length";
86 case error::incomplete_length_set: return "incomplete length set";
87
88 case error::general:
89 default:
90 return "beast.zlib error";
91 }
92 }
93
94 error_condition
95 default_error_condition(int ev) const noexcept override
96 {
97 return error_condition{ev, *this};
98 }
99
100 bool
101 equivalent(int ev,
102 error_condition const& condition
103 ) const noexcept override
104 {
105 return condition.value() == ev &&
106 &condition.category() == this;
107 }
108
109 bool
110 equivalent(error_code const& error, int ev) const noexcept override
111 {
112 return error.value() == ev &&
113 &error.category() == this;
114 }
115 };
116
117 inline
118 error_category const&
119 get_error_category()
120 {
121 static zlib_error_category const cat{};
122 return cat;
123 }
124
125 } // detail
126
127 inline
128 error_code
129 make_error_code(error ev)
130 {
131 return error_code{
132 static_cast<std::underlying_type<error>::type>(ev),
133 detail::get_error_category()};
134 }
135
136 } // zlib
137 } // beast
138 } // boost
139
140 #endif