mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Add buffer_traits.hpp, buffers_type
This commit is contained in:
@ -5,6 +5,7 @@ Version 198:
|
||||
* static_buffer improvements
|
||||
* flat_static_buffer_improvements
|
||||
* saved_handler maintains a work_guard (websocket)
|
||||
* Add buffer_traits.hpp, buffers_type
|
||||
|
||||
API Changes:
|
||||
|
||||
|
@ -53,7 +53,7 @@ transferred.
|
||||
][
|
||||
This class represents the buffer sequence formed from a prefix of
|
||||
an existing buffer sequence. This is the type of buffer returned by
|
||||
[link beast.ref.boost__beast__buffers_prefix.overload3 `buffers_prefix`].
|
||||
[link beast.ref.boost__beast__buffers_prefix `buffers_prefix`].
|
||||
]]
|
||||
[[
|
||||
[link beast.ref.boost__beast__buffers_range `buffers_range`]
|
||||
|
@ -235,6 +235,7 @@
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Type Traits</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member><link linkend="beast.ref.boost__beast__buffers_type">buffers_type</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__get_lowest_layer">get_lowest_layer</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__has_get_executor">has_get_executor</link></member>
|
||||
<member><link linkend="beast.ref.boost__beast__is_async_read_stream">is_async_read_stream</link></member>
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
|
||||
#include <boost/beast/core/bind_handler.hpp>
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
#include <boost/beast/core/buffered_read_stream.hpp>
|
||||
#include <boost/beast/core/buffers_adapter.hpp>
|
||||
#include <boost/beast/core/buffers_cat.hpp>
|
||||
|
73
include/boost/beast/core/buffer_traits.hpp
Normal file
73
include/boost/beast/core/buffer_traits.hpp
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BOOST_BEAST_BUFFER_TRAITS_HPP
|
||||
#define BOOST_BEAST_BUFFER_TRAITS_HPP
|
||||
|
||||
#include <boost/beast/core/detail/config.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
/** Type alias used to obtain the underlying buffer type of a buffer sequence.
|
||||
|
||||
This metafunction is used to determine the underlying buffer type for
|
||||
a given buffer sequence. The equivalent type of the alias will vary
|
||||
depending on the template type argument:
|
||||
|
||||
@li If the template argument is a <em>MutableBufferSequence</em>,
|
||||
the resulting type alias will be `net::mutable_buffer`, else
|
||||
|
||||
@li If the template argument is a <em>ConstBufferSequence</em>,
|
||||
the resulting type alias will be `net::const_buffer`, otherwise
|
||||
|
||||
@li The resulting type alias will be `void`.
|
||||
|
||||
@par Example
|
||||
The following code returns the first buffer in a buffer sequence,
|
||||
or generates a compilation error if the argument is not a buffer
|
||||
sequence:
|
||||
@code
|
||||
template <class BufferSequence>
|
||||
buffers_type <BufferSequence>
|
||||
buffers_front (BufferSequence const& buffers)
|
||||
{
|
||||
static_assert(
|
||||
net::is_const_buffer_sequence<BufferSequence>::value,
|
||||
"BufferSequence requirements not met");
|
||||
auto const first = net::buffer_sequence_begin (buffers);
|
||||
if (first == net::buffer_sequence_end (buffers))
|
||||
return {};
|
||||
return *first;
|
||||
}
|
||||
@endcode
|
||||
|
||||
@param T The buffer sequence type to use.
|
||||
*/
|
||||
template<class T>
|
||||
#if BOOST_BEAST_DOXYGEN
|
||||
struct buffers_type : __see_below__ {};
|
||||
//using buffers_type = __see_below__;
|
||||
#else
|
||||
using buffers_type = typename
|
||||
std::conditional<
|
||||
net::is_mutable_buffer_sequence<T>::value,
|
||||
net::mutable_buffer,
|
||||
typename std::conditional<
|
||||
net::is_const_buffer_sequence<T>::value,
|
||||
net::const_buffer,
|
||||
void>::type>::type;
|
||||
#endif
|
||||
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@ add_executable (tests-beast-core
|
||||
file_test.hpp
|
||||
bind_handler.cpp
|
||||
buffer.cpp
|
||||
buffer_traits.cpp
|
||||
buffered_read_stream.cpp
|
||||
buffers_adapter.cpp
|
||||
buffers_cat.cpp
|
||||
|
@ -10,6 +10,7 @@
|
||||
local SOURCES =
|
||||
bind_handler.cpp
|
||||
buffer.cpp
|
||||
buffer_traits.cpp
|
||||
buffered_read_stream.cpp
|
||||
buffers_adapter.cpp
|
||||
buffers_cat.cpp
|
||||
|
39
test/beast/core/buffer_traits.cpp
Normal file
39
test/beast/core/buffer_traits.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (c) 2018 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
std::is_same<net::const_buffer,
|
||||
buffers_type<net::const_buffer>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
std::is_same<net::mutable_buffer,
|
||||
buffers_type<net::mutable_buffer>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
std::is_same<net::const_buffer,
|
||||
buffers_type<std::array<net::const_buffer, 3>>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
std::is_same<net::mutable_buffer,
|
||||
buffers_type<std::array<net::mutable_buffer, 3>>>::value);
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
std::is_same<void,
|
||||
buffers_type<std::array<int, 3>>>::value);
|
||||
|
||||
} // beast
|
||||
} // boost
|
Reference in New Issue
Block a user