ゴミ箱
ranges.hpp
Go to the documentation of this file.
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_DETAIL_RANGES_HPP
38 #define BOOST_BEAST_ZLIB_DETAIL_RANGES_HPP
39 
40 #include <cstdint>
41 #include <type_traits>
42 
43 namespace boost {
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 
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 
86 };
87 
88 // Clamp u to v where u and v are different types
89 template<class U, class V>
90 inline
91 U
92 clamp(U u, V v)
93 {
94  if(u > v)
95  u = static_cast<U>(v);
96  return u;
97 }
98 
99 } // detail
100 } // zlib
101 } // beast
102 } // boost
103 
104 #endif
iter_t first
Definition: ranges.hpp:58
iter_t last
Definition: ranges.hpp:59
std::size_t avail() const
Definition: ranges.hpp:78
Definition: async_result.hpp:20
std::size_t size() const
Definition: ranges.hpp:64
range< true > in
Definition: ranges.hpp:84
Definition: ranges.hpp:48
iter_t next
Definition: ranges.hpp:60
U clamp(U u, V v)
Definition: ranges.hpp:92
std::size_t used() const
Definition: ranges.hpp:71
range< false > out
Definition: ranges.hpp:85
typename std::conditional< isConst, std::uint8_t const *, std::uint8_t * >::type iter_t
Definition: ranges.hpp:56