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