buffers_cat.hpp 3.3 KB

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