1 //
2 // Copyright (c) 2016-2019 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 
10 #ifndef BOOST_BEAST_BUFFERS_CAT_HPP
11 #define BOOST_BEAST_BUFFERS_CAT_HPP
12 
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/buffer_traits.hpp>
15 #include <boost/beast/core/detail/tuple.hpp>
16 #include <boost/beast/core/detail/type_traits.hpp>
17 
18 namespace boost {
19 namespace beast {
20 
21 /** A buffer sequence representing a concatenation of buffer sequences.
22     @see buffers_cat
23 */
24 template<class... Buffers>
25 class buffers_cat_view
26 {
27     detail::tuple<Buffers...> bn_;
28 
29 public:
30     /** The type of buffer returned when dereferencing an iterator.
31         If every buffer sequence in the view is a <em>MutableBufferSequence</em>,
32         then `value_type` will be `net::mutable_buffer`.
33         Otherwise, `value_type` will be `net::const_buffer`.
34     */
35 #if BOOST_BEAST_DOXYGEN
36     using value_type = __see_below__;
37 #else
38     using value_type = buffers_type<Buffers...>;
39 #endif
40 
41     /// The type of iterator used by the concatenated sequence
42     class const_iterator;
43 
44     /// Copy Constructor
45     buffers_cat_view(buffers_cat_view const&) = default;
46 
47     /// Copy Assignment
48     buffers_cat_view& operator=(buffers_cat_view const&) = default;
49 
50     /** Constructor
51         @param buffers The list of buffer sequences to concatenate.
52         Copies of the arguments will be maintained for the lifetime
53         of the concatenated sequence; however, the ownership of the
54         memory buffers themselves is not transferred.
55     */
56     explicit
57     buffers_cat_view(Buffers const&... buffers);
58 
59     /// Returns an iterator to the first buffer in the sequence
60     const_iterator
61     begin() const;
62 
63     /// Returns an iterator to one past the last buffer in the sequence
64     const_iterator
65     end() const;
66 };
67 
68 /** Concatenate 1 or more buffer sequences.
69 
70     This function returns a constant or mutable buffer sequence which,
71     when iterated, efficiently concatenates the input buffer sequences.
72     Copies of the arguments passed will be made; however, the returned
73     object does not take ownership of the underlying memory. The
74     application is still responsible for managing the lifetime of the
75     referenced memory.
76     @param buffers The list of buffer sequences to concatenate.
77     @return A new buffer sequence that represents the concatenation of
78     the input buffer sequences. This buffer sequence will be a
79     <em>MutableBufferSequence</em> if each of the passed buffer sequences is
80     also a <em>MutableBufferSequence</em>; otherwise the returned buffer
81     sequence will be a <em>ConstBufferSequence</em>.
82     @see buffers_cat_view
83 */
84 #if BOOST_BEAST_DOXYGEN
85 template<class... BufferSequence>
86 buffers_cat_view<BufferSequence...>
buffers_cat(BufferSequence const &...buffers)87 buffers_cat(BufferSequence const&... buffers)
88 #else
89 template<class B1, class... Bn>
90 buffers_cat_view<B1, Bn...>
91 buffers_cat(B1 const& b1, Bn const&... bn)
92 #endif
93 {
94     static_assert(
95         is_const_buffer_sequence<B1, Bn...>::value,
96         "BufferSequence type requirements not met");
97     return buffers_cat_view<B1, Bn...>{b1, bn...};
98 }
99 
100 } // beast
101 } // boost
102 
103 #include <boost/beast/core/impl/buffers_cat.hpp>
104 
105 #endif
106