]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // |
92f5a8d4 | 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
7c673cae FG |
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 | // | |
b32b8144 FG |
7 | // Official repository: https://github.com/boostorg/beast |
8 | // | |
7c673cae FG |
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 | ||
b32b8144 FG |
37 | #ifndef BOOST_BEAST_ZLIB_DETAIL_RANGES_HPP |
38 | #define BOOST_BEAST_ZLIB_DETAIL_RANGES_HPP | |
7c673cae FG |
39 | |
40 | #include <cstdint> | |
41 | #include <type_traits> | |
42 | ||
b32b8144 | 43 | namespace boost { |
7c673cae FG |
44 | namespace beast { |
45 | namespace zlib { | |
46 | namespace detail { | |
47 | ||
48 | struct ranges | |
49 | { | |
50 | template<bool isConst> | |
51 | struct range | |
52 | { | |
53 | using iter_t = | |
54 | typename std::conditional<isConst, | |
55 | std::uint8_t const*, | |
56 | std::uint8_t*>::type; | |
57 | ||
58 | iter_t first; | |
59 | iter_t last; | |
60 | iter_t next; | |
61 | ||
62 | // total bytes in range | |
63 | std::size_t | |
64 | size() const | |
65 | { | |
66 | return last - first; | |
67 | } | |
68 | ||
69 | // bytes consumed | |
70 | std::size_t | |
71 | used() const | |
72 | { | |
73 | return next - first; | |
74 | } | |
75 | ||
76 | // bytes remaining | |
77 | std::size_t | |
78 | avail() const | |
79 | { | |
80 | return last - next; | |
81 | } | |
82 | }; | |
83 | ||
84 | range<true> in; | |
85 | range<false> out; | |
86 | }; | |
87 | ||
88 | // Clamp u to v where u and v are different types | |
89 | template<class U, class V> | |
92f5a8d4 | 90 | U clamp(U u, V v) |
7c673cae FG |
91 | { |
92 | if(u > v) | |
93 | u = static_cast<U>(v); | |
94 | return u; | |
95 | } | |
96 | ||
97 | } // detail | |
98 | } // zlib | |
99 | } // beast | |
b32b8144 | 100 | } // boost |
7c673cae FG |
101 | |
102 | #endif |