mirror of
https://github.com/boostorg/beast.git
synced 2025-07-31 05:17:26 +02:00
Simplify multi_buffer and static_buffer sequences
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
Version 195:
|
Version 195:
|
||||||
|
|
||||||
* net is a namespace alias for boost::asio
|
* net is a namespace alias for boost::asio
|
||||||
|
* Simplify multi_buffer and static_buffer sequences
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -149,19 +149,28 @@ public:
|
|||||||
class const_iterator;
|
class const_iterator;
|
||||||
|
|
||||||
readable_bytes() = delete;
|
readable_bytes() = delete;
|
||||||
|
readable_bytes(readable_bytes const&) = default;
|
||||||
readable_bytes& operator=(readable_bytes const&) = default;
|
readable_bytes& operator=(readable_bytes const&) = default;
|
||||||
|
|
||||||
template<
|
template<
|
||||||
bool OtherIsMutable,
|
bool IsMutable_ = IsMutable,
|
||||||
bool ThisIsMutable = IsMutable>
|
class = typename std::enable_if<! IsMutable_>::type>
|
||||||
readable_bytes(
|
readable_bytes(
|
||||||
readable_bytes<OtherIsMutable> const& other,
|
readable_bytes<true> const& other) noexcept
|
||||||
typename std::enable_if<
|
|
||||||
! ThisIsMutable || OtherIsMutable>::type* = 0)
|
|
||||||
: b_(other.b_)
|
: b_(other.b_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<
|
||||||
|
bool IsMutable_ = IsMutable,
|
||||||
|
class = typename std::enable_if<! IsMutable_>::type>
|
||||||
|
readable_bytes& operator=(
|
||||||
|
readable_bytes<true> const& other) noexcept
|
||||||
|
{
|
||||||
|
b_ = other.b_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
const_iterator begin() const noexcept;
|
const_iterator begin() const noexcept;
|
||||||
const_iterator end() const noexcept;
|
const_iterator end() const noexcept;
|
||||||
|
|
||||||
|
@ -21,6 +21,74 @@
|
|||||||
namespace boost {
|
namespace boost {
|
||||||
namespace beast {
|
namespace beast {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<bool IsMutable>
|
||||||
|
class buffers_pair
|
||||||
|
{
|
||||||
|
template<bool IsMutable_>
|
||||||
|
friend class buffers_pair;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// VFALCO: This type is public otherwise
|
||||||
|
// asio::buffers_iterator won't compile.
|
||||||
|
using value_type = typename
|
||||||
|
std::conditional<IsMutable,
|
||||||
|
net::mutable_buffer,
|
||||||
|
net::const_buffer>::type;
|
||||||
|
|
||||||
|
using const_iterator =
|
||||||
|
value_type const*;
|
||||||
|
|
||||||
|
buffers_pair() = default;
|
||||||
|
buffers_pair(buffers_pair const&) = default;
|
||||||
|
buffers_pair& operator=(buffers_pair const&) = default;
|
||||||
|
|
||||||
|
template<
|
||||||
|
bool IsMutable_ = IsMutable,
|
||||||
|
class = typename std::enable_if<! IsMutable_>::type>
|
||||||
|
buffers_pair(buffers_pair<true> const& other) noexcept
|
||||||
|
: b_{other.b_[0], other.b_[1]}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<
|
||||||
|
bool IsMutable_ = IsMutable,
|
||||||
|
class = typename std::enable_if<! IsMutable_>::type>
|
||||||
|
buffers_pair& operator=(
|
||||||
|
buffers_pair<true> const& other) noexcept
|
||||||
|
{
|
||||||
|
b_ = {other.b_[0], other.b_[1]};
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
value_type&
|
||||||
|
operator[](int i) noexcept
|
||||||
|
{
|
||||||
|
BOOST_ASSERT(i >= 0 && i < 2);
|
||||||
|
return b_[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator
|
||||||
|
begin() const noexcept
|
||||||
|
{
|
||||||
|
return &b_[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const_iterator
|
||||||
|
end() const noexcept
|
||||||
|
{
|
||||||
|
if(b_[1].size() > 0)
|
||||||
|
return &b_[2];
|
||||||
|
else
|
||||||
|
return &b_[1];
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
value_type b_[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
/** A dynamic buffer providing a fixed, circular buffer.
|
/** A dynamic buffer providing a fixed, circular buffer.
|
||||||
|
|
||||||
A dynamic buffer encapsulates memory storage that may be
|
A dynamic buffer encapsulates memory storage that may be
|
||||||
@ -60,94 +128,6 @@ class static_buffer_base
|
|||||||
std::size_t out_size_ = 0;
|
std::size_t out_size_ = 0;
|
||||||
std::size_t capacity_;
|
std::size_t capacity_;
|
||||||
|
|
||||||
class const_buffer_pair;
|
|
||||||
|
|
||||||
class mutable_buffer_pair
|
|
||||||
{
|
|
||||||
net::mutable_buffer b_[2];
|
|
||||||
|
|
||||||
friend class const_buffer_pair;
|
|
||||||
|
|
||||||
public:
|
|
||||||
using const_iterator =
|
|
||||||
net::mutable_buffer const*;
|
|
||||||
|
|
||||||
// workaround for buffers_iterator bug
|
|
||||||
using value_type =
|
|
||||||
net::mutable_buffer;
|
|
||||||
|
|
||||||
mutable_buffer_pair() = default;
|
|
||||||
mutable_buffer_pair(
|
|
||||||
mutable_buffer_pair const&) = default;
|
|
||||||
|
|
||||||
net::mutable_buffer&
|
|
||||||
operator[](int i) noexcept
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(i >= 0 && i < 2);
|
|
||||||
return b_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator
|
|
||||||
begin() const noexcept
|
|
||||||
{
|
|
||||||
return &b_[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator
|
|
||||||
end() const noexcept
|
|
||||||
{
|
|
||||||
if(b_[1].size() > 0)
|
|
||||||
return &b_[2];
|
|
||||||
else
|
|
||||||
return &b_[1];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class const_buffer_pair
|
|
||||||
{
|
|
||||||
net::const_buffer b_[2];
|
|
||||||
|
|
||||||
public:
|
|
||||||
using const_iterator =
|
|
||||||
net::const_buffer const*;
|
|
||||||
|
|
||||||
// workaround for buffers_iterator bug
|
|
||||||
using value_type =
|
|
||||||
net::const_buffer;
|
|
||||||
|
|
||||||
const_buffer_pair() = default;
|
|
||||||
const_buffer_pair(
|
|
||||||
const_buffer_pair const&) = default;
|
|
||||||
|
|
||||||
const_buffer_pair(
|
|
||||||
mutable_buffer_pair const& other)
|
|
||||||
: b_{other.b_[0], other.b_[1]}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
net::const_buffer&
|
|
||||||
operator[](int i) noexcept
|
|
||||||
{
|
|
||||||
BOOST_ASSERT(i >= 0 && i < 2);
|
|
||||||
return b_[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator
|
|
||||||
begin() const noexcept
|
|
||||||
{
|
|
||||||
return &b_[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
const_iterator
|
|
||||||
end() const noexcept
|
|
||||||
{
|
|
||||||
if(b_[1].size() > 0)
|
|
||||||
return &b_[2];
|
|
||||||
else
|
|
||||||
return &b_[1];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static_buffer_base(static_buffer_base const& other) = delete;
|
static_buffer_base(static_buffer_base const& other) = delete;
|
||||||
static_buffer_base& operator=(static_buffer_base const&) = delete;
|
static_buffer_base& operator=(static_buffer_base const&) = delete;
|
||||||
|
|
||||||
@ -174,9 +154,9 @@ public:
|
|||||||
/// The MutableBufferSequence used to represent the writable bytes.
|
/// The MutableBufferSequence used to represent the writable bytes.
|
||||||
using mutable_buffers_type = __implementation_defined__;
|
using mutable_buffers_type = __implementation_defined__;
|
||||||
#else
|
#else
|
||||||
using const_buffers_type = const_buffer_pair;
|
using const_buffers_type = detail::buffers_pair<false>;
|
||||||
using mutable_data_type = mutable_buffer_pair;
|
using mutable_data_type = detail::buffers_pair<true>;
|
||||||
using mutable_buffers_type = mutable_buffer_pair;
|
using mutable_buffers_type = detail::buffers_pair<true>;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Returns the number of readable bytes.
|
/// Returns the number of readable bytes.
|
||||||
|
@ -46,6 +46,12 @@ public:
|
|||||||
BOOST_STATIC_ASSERT(std::is_convertible<
|
BOOST_STATIC_ASSERT(std::is_convertible<
|
||||||
multi_buffer::mutable_data_type,
|
multi_buffer::mutable_data_type,
|
||||||
multi_buffer::const_buffers_type>::value);
|
multi_buffer::const_buffers_type>::value);
|
||||||
|
#if ! defined( BOOST_LIBSTDCXX_VERSION ) || BOOST_LIBSTDCXX_VERSION >= 50000
|
||||||
|
BOOST_STATIC_ASSERT(std::is_trivially_copyable<
|
||||||
|
multi_buffer::const_buffers_type>::value);
|
||||||
|
BOOST_STATIC_ASSERT(std::is_trivially_copyable<
|
||||||
|
multi_buffer::mutable_data_type>::value);
|
||||||
|
#endif
|
||||||
|
|
||||||
template<class Alloc1, class Alloc2>
|
template<class Alloc1, class Alloc2>
|
||||||
static
|
static
|
||||||
|
@ -44,6 +44,14 @@ public:
|
|||||||
BOOST_STATIC_ASSERT(std::is_convertible<
|
BOOST_STATIC_ASSERT(std::is_convertible<
|
||||||
static_buffer_base::mutable_data_type,
|
static_buffer_base::mutable_data_type,
|
||||||
static_buffer_base::const_buffers_type>::value);
|
static_buffer_base::const_buffers_type>::value);
|
||||||
|
#if ! defined( BOOST_LIBSTDCXX_VERSION ) || BOOST_LIBSTDCXX_VERSION >= 50000
|
||||||
|
# ifndef BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
|
||||||
|
BOOST_STATIC_ASSERT(std::is_trivially_copyable<
|
||||||
|
static_buffer_base::const_buffers_type>::value);
|
||||||
|
BOOST_STATIC_ASSERT(std::is_trivially_copyable<
|
||||||
|
static_buffer_base::mutable_data_type>::value);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
template<class DynamicBuffer>
|
template<class DynamicBuffer>
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user