Rename to static_buffer, static_buffer_n (API Change):

These classes are renamed:

* static_streambuf to static_buffer
* static_streambuf_n to static_buffer_n
This commit is contained in:
Vinnie Falco
2017-05-04 18:50:25 -07:00
parent 6e47e9a0ac
commit aa9f42cd06
14 changed files with 82 additions and 81 deletions

View File

@ -12,6 +12,7 @@ API Changes:
* New buffers() replaces to_string()
* Rename to multi_buffer, basic_multi_buffer
* Rename to flat_buffer, basic_flat_buffer
* Rename to static_buffer, static_buffer_n
--------------------------------------------------------------------------------

View File

@ -165,8 +165,8 @@
<member><link linkend="beast.ref.handler_alloc">handler_alloc</link></member>
<member><link linkend="beast.ref.handler_ptr">handler_ptr</link></member>
<member><link linkend="beast.ref.multi_buffer">multi_buffer</link></member>
<member><link linkend="beast.ref.static_streambuf">static_streambuf</link></member>
<member><link linkend="beast.ref.static_streambuf_n">static_streambuf_n</link></member>
<member><link linkend="beast.ref.static_buffer">static_buffer</link></member>
<member><link linkend="beast.ref.static_buffer_n">static_buffer_n</link></member>
<member><link linkend="beast.ref.static_string">static_string</link></member>
<member><link linkend="beast.ref.system_error">system_error</link></member>
</simplelist>

View File

@ -27,7 +27,7 @@
#include <beast/core/ostream.hpp>
#include <beast/core/placeholders.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/static_string.hpp>
#include <beast/core/stream_concepts.hpp>

View File

@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_IMPL_STATIC_STREAMBUF_IPP
#define BEAST_IMPL_STATIC_STREAMBUF_IPP
#ifndef BEAST_IMPL_STATIC_BUFFER_IPP
#define BEAST_IMPL_STATIC_BUFFER_IPP
#include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp>
@ -17,7 +17,7 @@
namespace beast {
class static_streambuf::const_buffers_type
class static_buffer::const_buffers_type
{
std::size_t n_;
std::uint8_t const* p_;
@ -40,7 +40,7 @@ public:
end() const;
private:
friend class static_streambuf;
friend class static_buffer;
const_buffers_type(
std::uint8_t const* p, std::size_t n)
@ -50,7 +50,7 @@ private:
}
};
class static_streambuf::const_buffers_type::const_iterator
class static_buffer::const_buffers_type::const_iterator
{
std::size_t n_ = 0;
std::uint8_t const* p_ = nullptr;
@ -133,7 +133,7 @@ private:
inline
auto
static_streambuf::const_buffers_type::begin() const ->
static_buffer::const_buffers_type::begin() const ->
const_iterator
{
return const_iterator{p_, n_};
@ -141,7 +141,7 @@ static_streambuf::const_buffers_type::begin() const ->
inline
auto
static_streambuf::const_buffers_type::end() const ->
static_buffer::const_buffers_type::end() const ->
const_iterator
{
return const_iterator{p_ + n_, n_};
@ -149,7 +149,7 @@ static_streambuf::const_buffers_type::end() const ->
//------------------------------------------------------------------------------
class static_streambuf::mutable_buffers_type
class static_buffer::mutable_buffers_type
{
std::size_t n_;
std::uint8_t* p_;
@ -172,7 +172,7 @@ public:
end() const;
private:
friend class static_streambuf;
friend class static_buffer;
mutable_buffers_type(
std::uint8_t* p, std::size_t n)
@ -182,7 +182,7 @@ private:
}
};
class static_streambuf::mutable_buffers_type::const_iterator
class static_buffer::mutable_buffers_type::const_iterator
{
std::size_t n_ = 0;
std::uint8_t* p_ = nullptr;
@ -264,7 +264,7 @@ private:
inline
auto
static_streambuf::mutable_buffers_type::begin() const ->
static_buffer::mutable_buffers_type::begin() const ->
const_iterator
{
return const_iterator{p_, n_};
@ -272,7 +272,7 @@ static_streambuf::mutable_buffers_type::begin() const ->
inline
auto
static_streambuf::mutable_buffers_type::end() const ->
static_buffer::mutable_buffers_type::end() const ->
const_iterator
{
return const_iterator{p_ + n_, n_};
@ -280,10 +280,9 @@ static_streambuf::mutable_buffers_type::end() const ->
//------------------------------------------------------------------------------
inline
auto
static_streambuf::data() const ->
static_buffer::data() const ->
const_buffers_type
{
return const_buffers_type{in_,
@ -292,12 +291,12 @@ static_streambuf::data() const ->
inline
auto
static_streambuf::prepare(std::size_t n) ->
static_buffer::prepare(std::size_t n) ->
mutable_buffers_type
{
if(n > static_cast<std::size_t>(end_ - out_))
throw detail::make_exception<std::length_error>(
"no space in static_buffer", __FILE__, __LINE__);
"static_buffer overflow", __FILE__, __LINE__);
last_ = out_ + n;
return mutable_buffers_type{out_, n};
}

View File

@ -5,8 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BEAST_STATIC_STREAMBUF_HPP
#define BEAST_STATIC_STREAMBUF_HPP
#ifndef BEAST_STATIC_BUFFER_HPP
#define BEAST_STATIC_BUFFER_HPP
#include <beast/config.hpp>
#include <boost/utility/base_from_member.hpp>
@ -16,17 +16,17 @@
namespace beast {
/** A @b `DynamicBuffer` with a fixed size internal buffer.
/** A @b DynamicBuffer with a fixed size internal buffer.
Ownership of the underlying storage belongs to the derived class.
@note Variables are usually declared using the template class
@ref static_streambuf_n; however, to reduce the number of instantiations
@ref static_buffer_n; however, to reduce the number of instantiations
of template functions receiving static stream buffer arguments in a
deduced context, the signature of the receiving function should use
@ref static_streambuf.
@ref static_buffer.
*/
class static_streambuf
class static_buffer
{
#if BEAST_DOXYGEN
private:
@ -51,11 +51,11 @@ public:
class const_buffers_type;
class mutable_buffers_type;
static_streambuf(
static_streambuf const& other) noexcept = delete;
static_buffer(
static_buffer const& other) noexcept = delete;
static_streambuf& operator=(
static_streambuf const&) noexcept = delete;
static_buffer& operator=(
static_buffer const&) noexcept = delete;
#endif
@ -121,7 +121,7 @@ private:
#else
protected:
#endif
static_streambuf(std::uint8_t* p, std::size_t n)
static_buffer(std::uint8_t* p, std::size_t n)
{
reset(p, n);
}
@ -139,17 +139,17 @@ protected:
//------------------------------------------------------------------------------
/** A `DynamicBuffer` with a fixed size internal buffer.
/** A @b DynamicBuffer with a fixed size internal buffer.
@tparam N The number of bytes in the internal buffer.
@note To reduce the number of template instantiations when passing
objects of this type in a deduced context, the signature of the
receiving function should use `static_streambuf` instead.
receiving function should use `static_buffer` instead.
*/
template<std::size_t N>
class static_streambuf_n
: public static_streambuf
class static_buffer_n
: public static_buffer
#if ! BEAST_DOXYGEN
, private boost::base_from_member<
std::array<std::uint8_t, N>>
@ -161,23 +161,23 @@ public:
#if BEAST_DOXYGEN
private:
#endif
static_streambuf_n(
static_streambuf_n const&) = delete;
static_streambuf_n& operator=(
static_streambuf_n const&) = delete;
static_buffer_n(
static_buffer_n const&) = delete;
static_buffer_n& operator=(
static_buffer_n const&) = delete;
#if BEAST_DOXYGEN
public:
#endif
/// Construct a static stream buffer.
static_streambuf_n()
: static_streambuf(
/// Construct a static buffer.
static_buffer_n()
: static_buffer(
member_type::member.data(),
member_type::member.size())
{
}
/** Reset the stream buffer.
/** Reset the static buffer.
Postconditions:
The input sequence and output sequence are empty,
@ -186,7 +186,7 @@ public:
void
reset()
{
static_streambuf::reset(
static_buffer::reset(
member_type::member.data(),
member_type::member.size());
}
@ -194,6 +194,6 @@ public:
} // beast
#include <beast/core/impl/static_streambuf.ipp>
#include <beast/core/impl/static_buffer.ipp>
#endif

View File

@ -12,7 +12,7 @@
#include <beast/websocket/detail/endian.hpp>
#include <beast/websocket/detail/utf8_checker.hpp>
#include <beast/core/consuming_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/static_string.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/assert.hpp>
@ -38,11 +38,11 @@ struct frame_header
// holds the largest possible frame header
using fh_streambuf =
static_streambuf_n<14>;
static_buffer_n<14>;
// holds the largest possible control frame
using frame_streambuf =
static_streambuf_n< 2 + 8 + 4 + 125 >;
static_buffer_n< 2 + 8 + 4 + 125 >;
inline
bool constexpr

View File

@ -10,7 +10,7 @@
#include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/stream_concepts.hpp>
#include <memory>
@ -43,7 +43,7 @@ class stream<NextLayer>::close_op
, cr(cr_)
{
ws.template write_close<
static_streambuf>(fb, cr);
static_buffer>(fb, cr);
}
};
@ -235,7 +235,7 @@ close(close_reason const& cr, error_code& ec)
BOOST_ASSERT(! wr_close_);
wr_close_ = true;
detail::frame_streambuf fb;
write_close<static_streambuf>(fb, cr);
write_close<static_buffer>(fb, cr);
boost::asio::write(stream_, fb.data(), ec);
failed_ = ec != 0;
}

View File

@ -42,7 +42,7 @@ class stream<NextLayer>::ping_op
using boost::asio::buffer;
using boost::asio::buffer_copy;
ws.template write_ping<
static_streambuf>(fb, op_, payload);
static_buffer>(fb, op_, payload);
}
};
@ -246,7 +246,7 @@ stream<NextLayer>::
ping(ping_data const& payload, error_code& ec)
{
detail::frame_streambuf db;
write_ping<static_streambuf>(
write_ping<static_buffer>(
db, opcode::ping, payload);
boost::asio::write(stream_, db.data(), ec);
}
@ -268,7 +268,7 @@ stream<NextLayer>::
pong(ping_data const& payload, error_code& ec)
{
detail::frame_streambuf db;
write_ping<static_streambuf>(
write_ping<static_buffer>(
db, opcode::pong, payload);
boost::asio::write(stream_, db.data(), ec);
}

View File

@ -13,7 +13,7 @@
#include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/stream_concepts.hpp>
#include <beast/core/detail/clamp.hpp>
#include <boost/assert.hpp>
@ -444,7 +444,7 @@ operator()(error_code ec,
d.state = do_read_fh;
break;
}
d.ws.template write_ping<static_streambuf>(
d.ws.template write_ping<static_buffer>(
d.fb, opcode::pong, payload);
if(d.ws.wr_block_)
{
@ -486,7 +486,7 @@ operator()(error_code ec,
cr.reason = "";
d.fb.reset();
d.ws.template write_close<
static_streambuf>(d.fb, cr);
static_buffer>(d.fb, cr);
if(d.ws.wr_block_)
{
// suspend
@ -620,7 +620,7 @@ operator()(error_code ec,
}
d.fb.reset();
d.ws.template write_close<
static_streambuf>(d.fb, code);
static_buffer>(d.fb, code);
if(d.ws.wr_block_)
{
// suspend
@ -793,7 +793,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec)
fb.reset();
if(ping_cb_)
ping_cb_(false, payload);
write_ping<static_streambuf>(
write_ping<static_buffer>(
fb, opcode::pong, payload);
boost::asio::write(stream_, fb.data(), ec);
failed_ = ec != 0;
@ -822,7 +822,7 @@ read_frame(frame_info& fi, DynamicBuffer& dynabuf, error_code& ec)
cr.reason = "";
fb.reset();
wr_close_ = true;
write_close<static_streambuf>(fb, cr);
write_close<static_buffer>(fb, cr);
boost::asio::write(stream_, fb.data(), ec);
failed_ = ec != 0;
if(failed_)
@ -951,7 +951,7 @@ do_close:
{
wr_close_ = true;
detail::frame_streambuf fb;
write_close<static_streambuf>(fb, code);
write_close<static_buffer>(fb, code);
boost::asio::write(stream_, fb.data(), ec);
failed_ = ec != 0;
if(failed_)

View File

@ -20,7 +20,7 @@
#include <beast/core/buffer_concepts.hpp>
#include <beast/core/consuming_buffers.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/stream_concepts.hpp>
#include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp>

View File

@ -15,7 +15,7 @@
#include <beast/core/handler_helpers.hpp>
#include <beast/core/handler_ptr.hpp>
#include <beast/core/prepare_buffers.hpp>
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/core/stream_concepts.hpp>
#include <beast/core/detail/clamp.hpp>
#include <beast/websocket/detail/frame.hpp>
@ -234,7 +234,7 @@ operator()(error_code ec,
BOOST_ASSERT(d.ws.wr_block_ == &d);
d.fh.fin = d.fin;
d.fh.len = buffer_size(d.cb);
detail::write<static_streambuf>(
detail::write<static_buffer>(
d.fh_buf, d.fh);
d.ws.wr_.cont = ! d.fin;
// Send frame
@ -260,7 +260,7 @@ operator()(error_code ec,
d.remain -= n;
d.fh.len = n;
d.fh.fin = d.fin ? d.remain == 0 : false;
detail::write<static_streambuf>(
detail::write<static_buffer>(
d.fh_buf, d.fh);
d.ws.wr_.cont = ! d.fin;
// Send frame
@ -308,7 +308,7 @@ operator()(error_code ec,
d.fh.len = d.remain;
d.fh.key = d.ws.maskgen_();
detail::prepare_key(d.key, d.fh.key);
detail::write<static_streambuf>(
detail::write<static_buffer>(
d.fh_buf, d.fh);
auto const n =
clamp(d.remain, d.ws.wr_.buf_size);
@ -366,7 +366,7 @@ operator()(error_code ec,
d.ws.wr_.buf.get(), n);
buffer_copy(b, d.cb);
detail::mask_inplace(b, d.key);
detail::write<static_streambuf>(
detail::write<static_buffer>(
d.fh_buf, d.fh);
d.ws.wr_.cont = ! d.fin;
// Send frame
@ -442,7 +442,7 @@ operator()(error_code ec,
d.fh.fin = ! more;
d.fh.len = n;
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, d.fh);
detail::write<static_buffer>(fh_buf, d.fh);
d.ws.wr_.cont = ! d.fin;
// Send frame
d.state = more ?
@ -647,7 +647,7 @@ write_frame(bool fin,
fh.fin = ! more;
fh.len = n;
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, fh);
detail::write<static_buffer>(fh_buf, fh);
wr_.cont = ! fin;
boost::asio::write(stream_,
buffer_cat(fh_buf.data(), b), ec);
@ -675,7 +675,7 @@ write_frame(bool fin,
fh.fin = fin;
fh.len = remain;
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, fh);
detail::write<static_buffer>(fh_buf, fh);
wr_.cont = ! fin;
boost::asio::write(stream_,
buffer_cat(fh_buf.data(), buffers), ec);
@ -696,7 +696,7 @@ write_frame(bool fin,
fh.len = n;
fh.fin = fin ? remain == 0 : false;
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, fh);
detail::write<static_buffer>(fh_buf, fh);
wr_.cont = ! fin;
boost::asio::write(stream_,
buffer_cat(fh_buf.data(),
@ -721,7 +721,7 @@ write_frame(bool fin,
detail::prepared_key key;
detail::prepare_key(key, fh.key);
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, fh);
detail::write<static_buffer>(fh_buf, fh);
consuming_buffers<
ConstBufferSequence> cb{buffers};
{
@ -772,7 +772,7 @@ write_frame(bool fin,
fh.fin = fin ? remain == 0 : false;
wr_.cont = ! fh.fin;
detail::fh_streambuf fh_buf;
detail::write<static_streambuf>(fh_buf, fh);
detail::write<static_buffer>(fh_buf, fh);
boost::asio::write(stream_,
buffer_cat(fh_buf.data(), b), ec);
failed_ = ec != 0;

View File

@ -34,7 +34,7 @@ unit-test core-tests :
core/placeholders.cpp
core/prepare_buffer.cpp
core/prepare_buffers.cpp
core/static_streambuf.cpp
core/static_buffer.cpp
core/static_string.cpp
core/stream_concepts.cpp
core/base64.cpp

View File

@ -27,7 +27,7 @@ add_executable (core-tests
placeholders.cpp
prepare_buffer.cpp
prepare_buffers.cpp
static_streambuf.cpp
static_buffer.cpp
static_string.cpp
stream_concepts.cpp
base64.cpp

View File

@ -6,7 +6,7 @@
//
// Test that header file is self-contained.
#include <beast/core/static_streambuf.hpp>
#include <beast/core/static_buffer.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/asio/buffer.hpp>
@ -14,7 +14,7 @@
namespace beast {
class static_streambuf_test : public beast::unit_test::suite
class static_buffer_test : public beast::unit_test::suite
{
public:
template<class ConstBufferSequence>
@ -32,7 +32,8 @@ public:
return s;
}
void testStaticStreambuf()
void
testStaticBuffer()
{
using boost::asio::buffer;
using boost::asio::buffer_cast;
@ -50,7 +51,7 @@ public:
std::size_t v = sizeof(buf) - (t + u);
{
std::memset(buf, 0, sizeof(buf));
static_streambuf_n<sizeof(buf)> ba;
static_buffer_n<sizeof(buf)> ba;
{
auto d = ba.prepare(z);
BEAST_EXPECT(buffer_size(d) == z);
@ -141,7 +142,7 @@ public:
void testIterators()
{
static_streambuf_n<2> ba;
static_buffer_n<2> ba;
{
auto mb = ba.prepare(2);
std::size_t n;
@ -196,11 +197,11 @@ public:
void run() override
{
testStaticStreambuf();
testStaticBuffer();
testIterators();
}
};
BEAST_DEFINE_TESTSUITE(static_streambuf,core,beast);
BEAST_DEFINE_TESTSUITE(static_buffer,core,beast);
} // beastp