Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:44:35

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #ifndef BOOST_BEAST_BUFFER_TRAITS_HPP
0011 #define BOOST_BEAST_BUFFER_TRAITS_HPP
0012 
0013 #include <boost/beast/core/detail/config.hpp>
0014 #include <boost/beast/core/detail/buffer_traits.hpp>
0015 #include <boost/beast/core/detail/static_const.hpp>
0016 #include <boost/asio/buffer.hpp>
0017 #include <boost/config/workaround.hpp>
0018 #include <boost/mp11/function.hpp>
0019 #include <type_traits>
0020 
0021 namespace boost {
0022 namespace beast {
0023 
0024 /** Determine if a list of types satisfy the <em>ConstBufferSequence</em> requirements.
0025 
0026     This metafunction is used to determine if all of the specified types
0027     meet the requirements for constant buffer sequences. This type alias
0028     will be `std::true_type` if each specified type meets the requirements,
0029     otherwise, this type alias will be `std::false_type`.
0030 
0031     @tparam BufferSequence A list of zero or more types to check. If this
0032     list is empty, the resulting type alias will be `std::true_type`.
0033 */
0034 template<class... BufferSequence>
0035 #if BOOST_BEAST_DOXYGEN
0036 using is_const_buffer_sequence = __see_below__;
0037 #else
0038 using is_const_buffer_sequence = mp11::mp_all<
0039     net::is_const_buffer_sequence<
0040         typename std::decay<BufferSequence>::type>...>;
0041 #endif
0042 
0043 /** Determine if a list of types satisfy the <em>MutableBufferSequence</em> requirements.
0044 
0045     This metafunction is used to determine if all of the specified types
0046     meet the requirements for mutable buffer sequences. This type alias
0047     will be `std::true_type` if each specified type meets the requirements,
0048     otherwise, this type alias will be `std::false_type`.
0049 
0050     @tparam BufferSequence A list of zero or more types to check. If this
0051     list is empty, the resulting type alias will be `std::true_type`.
0052 */
0053 template<class... BufferSequence>
0054 #if BOOST_BEAST_DOXYGEN
0055 using is_mutable_buffer_sequence = __see_below__;
0056 #else
0057 using is_mutable_buffer_sequence = mp11::mp_all<
0058     net::is_mutable_buffer_sequence<
0059         typename std::decay<BufferSequence>::type>...>;
0060 #endif
0061 
0062 /** Type alias for the underlying buffer type of a list of buffer sequence types.
0063 
0064     This metafunction is used to determine the underlying buffer type for
0065     a list of buffer sequence. The equivalent type of the alias will vary
0066     depending on the template type argument:
0067 
0068     @li If every type in the list is a <em>MutableBufferSequence</em>,
0069         the resulting type alias will be `net::mutable_buffer`, otherwise
0070 
0071     @li The resulting type alias will be `net::const_buffer`.
0072 
0073     @par Example
0074     The following code returns the first buffer in a buffer sequence,
0075     or generates a compilation error if the argument is not a buffer
0076     sequence:
0077     @code
0078     template <class BufferSequence>
0079     buffers_type <BufferSequence>
0080     buffers_front (BufferSequence const& buffers)
0081     {
0082         static_assert(
0083             net::is_const_buffer_sequence<BufferSequence>::value,
0084             "BufferSequence type requirements not met");
0085         auto const first = net::buffer_sequence_begin (buffers);
0086         if (first == net::buffer_sequence_end (buffers))
0087             return {};
0088         return *first;
0089     }
0090     @endcode
0091 
0092     @tparam BufferSequence A list of zero or more types to check. If this
0093     list is empty, the resulting type alias will be `net::mutable_buffer`.
0094 */
0095 template<class... BufferSequence>
0096 #if BOOST_BEAST_DOXYGEN
0097 using buffers_type = __see_below__;
0098 #else
0099 using buffers_type = typename std::conditional<
0100     is_mutable_buffer_sequence<BufferSequence...>::value,
0101     net::mutable_buffer, net::const_buffer>::type;
0102 #endif
0103 
0104 /** Type alias for the iterator type of a buffer sequence type.
0105 
0106     This metafunction is used to determine the type of iterator
0107     used by a particular buffer sequence.
0108 
0109     @tparam T The buffer sequence type to use. The resulting
0110     type alias will be equal to the iterator type used by
0111     the buffer sequence.
0112 */
0113 template <class BufferSequence>
0114 #if BOOST_BEAST_DOXYGEN
0115 using buffers_iterator_type = __see_below__;
0116 #elif BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0117 using buffers_iterator_type = typename
0118     detail::buffers_iterator_type_helper<
0119         typename std::decay<BufferSequence>::type>::type;
0120 #else
0121 using buffers_iterator_type =
0122     decltype(net::buffer_sequence_begin(
0123         std::declval<BufferSequence const&>()));
0124 #endif
0125 
0126 /** Return the total number of bytes in a buffer or buffer sequence
0127 
0128     This function returns the total number of bytes in a buffer,
0129     buffer sequence, or object convertible to a buffer. Specifically
0130     it may be passed:
0131 
0132     @li A <em>ConstBufferSequence</em> or <em>MutableBufferSequence</em>
0133 
0134     @li A `net::const_buffer` or `net::mutable_buffer`
0135 
0136     @li An object convertible to `net::const_buffer`
0137 
0138     This function is designed as an easier-to-use replacement for
0139     `net::buffer_size`. It recognizes customization points found through
0140     argument-dependent lookup. The call `beast::buffer_bytes(b)` is
0141     equivalent to performing:
0142     @code
0143     using net::buffer_size;
0144     return buffer_size(b);
0145     @endcode
0146     In addition this handles types which are convertible to
0147     `net::const_buffer`; these are not handled by `net::buffer_size`.
0148 
0149     @param buffers The buffer or buffer sequence to calculate the size of.
0150 
0151     @return The total number of bytes in the buffer or sequence.
0152 */
0153 #if BOOST_BEAST_DOXYGEN
0154 template<class BufferSequence>
0155 std::size_t
0156 buffer_bytes(BufferSequence const& buffers);
0157 #else
0158 BOOST_BEAST_INLINE_VARIABLE(buffer_bytes, detail::buffer_bytes_impl)
0159 #endif
0160 
0161 } // beast
0162 } // boost
0163 
0164 #endif