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