From 7d89fdc46fa1327028c5234be4b29bf7d6a5666a Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 7 Jun 2017 05:10:58 -0700 Subject: [PATCH] Remove obsolete serializer allocator (API Change) --- CHANGELOG.md | 1 + include/beast/http/impl/serializer.ipp | 37 ++++---- include/beast/http/impl/write.ipp | 119 ++++++++++++------------- include/beast/http/serializer.hpp | 29 ++---- include/beast/http/write.hpp | 54 +++++------ test/http/doc_snippets.cpp | 3 +- 6 files changed, 105 insertions(+), 138 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd854c09..5840c040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ API Changes: * Protect basic_fields special members * Remove message connection settings * Remove message free functions +* Remove obsolete serializer allocator -------------------------------------------------------------------------------- diff --git a/include/beast/http/impl/serializer.ipp b/include/beast/http/impl/serializer.ipp index 15b0dcb6..79df9268 100644 --- a/include/beast/http/impl/serializer.ipp +++ b/include/beast/http/impl/serializer.ipp @@ -16,43 +16,39 @@ namespace beast { namespace http { -template +template void -serializer:: +serializer:: frdinit(std::true_type) { frd_.emplace(m_, m_.version, m_.method()); } -template +template void -serializer:: +serializer:: frdinit(std::false_type) { frd_.emplace(m_, m_.version, m_.result_int()); } -template -serializer:: +template +serializer:: serializer(message const& m, - ChunkDecorator const& d, Allocator const& alloc) + ChunkDecorator const& d) : m_(m) , d_(d) { } -template +template template void -serializer:: +serializer:: get(error_code& ec, Visit&& visit) { using boost::asio::buffer_size; @@ -258,11 +254,10 @@ get(error_code& ec, Visit&& visit) } } -template +template void -serializer:: +serializer:: consume(std::size_t n) { using boost::asio::buffer_size; diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index 53b57b57..2c757634 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -27,14 +27,14 @@ namespace beast { namespace http { namespace detail { -template class write_some_op { Stream& s_; - serializer& sr_; + serializer& sr_; Handler h_; class lambda @@ -68,7 +68,7 @@ public: template write_some_op(DeducedHandler&& h, Stream& s, serializer& sr) + Fields, Decorator>& sr) : s_(s) , sr_(sr) , h_(std::forward(h)) @@ -117,12 +117,11 @@ public: } }; -template +template void write_some_op:: + Fields, Decorator, Handler>:: operator()() { error_code ec; @@ -146,11 +145,10 @@ operator()() } template + class Fields, class Decorator, class Handler> void write_some_op:: + Fields, Decorator, Handler>:: operator()(error_code ec, std::size_t bytes_transferred) { if(! ec) @@ -162,11 +160,11 @@ operator()(error_code ec, std::size_t bytes_transferred) struct serializer_is_header_done { - template + template bool - operator()(serializer const& sr) const + operator()(serializer const& sr) const { return sr.is_header_done(); } @@ -174,25 +172,25 @@ struct serializer_is_header_done struct serializer_is_done { - template + template bool - operator()(serializer const& sr) const + operator()(serializer const& sr) const { return sr.is_done(); } }; -template class write_op { int state_ = 0; Stream& s_; - serializer& sr_; + serializer& sr_; Handler h_; class lambda @@ -226,7 +224,7 @@ public: template write_op(DeducedHandler&& h, Stream& s, serializer& sr) + Decorator>& sr) : s_(s) , sr_(sr) , h_(std::forward(h)) @@ -275,11 +273,11 @@ public: }; template + class Fields, class Decorator, class Predicate, + class Handler> void write_op:: + Decorator, Predicate, Handler>:: operator()(error_code ec, std::size_t bytes_transferred) { @@ -354,14 +352,13 @@ class write_msg_op struct data { Stream& s; - serializer> sr; + serializer sr; data(Handler& h, Stream& s_, message< isRequest, Body, Fields> const& m_) : s(s_) - , sr(m_, no_chunk_decorator{}, - handler_alloc{h}) + , sr(m_, no_chunk_decorator{}) { } }; @@ -503,11 +500,10 @@ public: //------------------------------------------------------------------------------ template + class Body, class Fields, class Decorator> void write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr) + isRequest, Body, Fields, Decorator>& sr) { static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); @@ -521,13 +517,12 @@ write_some(SyncWriteStream& stream, serializer< BOOST_THROW_EXCEPTION(system_error{ec}); } -template< - class SyncWriteStream, +template + class Decorator> void write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec) { static_assert(is_sync_write_stream::value, @@ -549,10 +544,10 @@ write_some(SyncWriteStream& stream, serializer< template + class Decorator, class WriteHandler> async_return_type async_write_some(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler) { static_assert(is_async_write_stream< @@ -565,7 +560,7 @@ async_write_some(AsyncWriteStream& stream, serializer< async_completion init{handler}; detail::write_some_op>{ init.completion_handler, stream, sr}(); return init.result.get(); @@ -573,13 +568,12 @@ async_write_some(AsyncWriteStream& stream, serializer< //------------------------------------------------------------------------------ -template< - class SyncWriteStream, +template + class Decorator> void write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr) + isRequest, Body, Fields, Decorator>& sr) { static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); @@ -593,13 +587,12 @@ write_header(SyncWriteStream& stream, serializer< BOOST_THROW_EXCEPTION(system_error{ec}); } -template< - class SyncWriteStream, +template + class Decorator> void write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec) { static_assert(is_sync_write_stream::value, @@ -622,10 +615,10 @@ write_header(SyncWriteStream& stream, serializer< template + class Decorator, class WriteHandler> async_return_type async_write_header(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler) { static_assert(is_async_write_stream< @@ -639,7 +632,7 @@ async_write_header(AsyncWriteStream& stream, serializer< async_completion init{handler}; detail::write_op>{ init.completion_handler, stream, sr}( error_code{}, 0); @@ -648,13 +641,12 @@ async_write_header(AsyncWriteStream& stream, serializer< //------------------------------------------------------------------------------ -template< - class SyncWriteStream, +template + class Decorator> void write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr) + isRequest, Body, Fields, Decorator>& sr) { static_assert(is_sync_write_stream::value, "SyncWriteStream requirements not met"); @@ -664,13 +656,12 @@ write(SyncWriteStream& stream, serializer< BOOST_THROW_EXCEPTION(system_error{ec}); } -template< - class SyncWriteStream, +template + class Decorator> void write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec) { static_assert(is_sync_write_stream::value, @@ -691,10 +682,10 @@ write(SyncWriteStream& stream, serializer< template + class Decorator, class WriteHandler> async_return_type async_write(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler) { static_assert(is_async_write_stream< @@ -708,7 +699,7 @@ async_write(AsyncWriteStream& stream, serializer< async_completion init{handler}; detail::write_op>{ init.completion_handler, stream, sr}( error_code{}, 0); diff --git a/include/beast/http/serializer.hpp b/include/beast/http/serializer.hpp index 59c5d107..4351f07e 100644 --- a/include/beast/http/serializer.hpp +++ b/include/beast/http/serializer.hpp @@ -9,7 +9,6 @@ #define BEAST_HTTP_SERIALIZER_HPP #include -#include #include #include #include @@ -19,7 +18,6 @@ #include #include #include -#include namespace beast { namespace http { @@ -117,15 +115,11 @@ struct no_chunk_decorator @tparam ChunkDecorator The type of chunk decorator to use. - @tparam Allocator The type of allocator to use. - @see @ref make_serializer */ template< bool isRequest, class Body, class Fields, - class ChunkDecorator = no_chunk_decorator, - class Allocator = std::allocator -> + class ChunkDecorator = no_chunk_decorator> class serializer { static_assert(is_body::value, @@ -194,7 +188,6 @@ class serializer message const& m_; boost::optional frd_; - ChunkDecorator d_; boost::optional rd_; boost::variant v_; @@ -204,6 +197,7 @@ class serializer bool chunked_; bool close_; bool more_; + ChunkDecorator d_; public: /** Constructor @@ -217,13 +211,10 @@ public: for the lifetime of the serializer. @param decorator An optional decorator to use. - - @param alloc An optional allocator to use. */ explicit serializer(message const& msg, - ChunkDecorator const& decorator = ChunkDecorator{}, - Allocator const& alloc = Allocator{}); + ChunkDecorator const& decorator = ChunkDecorator{}); /** Returns `true` if we will pause after writing the complete header. */ @@ -340,20 +331,16 @@ public: */ template< bool isRequest, class Body, class Fields, - class ChunkDecorator = no_chunk_decorator, - class Allocator = std::allocator> + class ChunkDecorator = no_chunk_decorator> inline serializer::type, - typename std::decay::type> + typename std::decay::type> make_serializer(message const& m, - ChunkDecorator const& decorator = ChunkDecorator{}, - Allocator const& allocator = Allocator{}) + ChunkDecorator const& decorator = ChunkDecorator{}) { return serializer::type, - typename std::decay::type>{ - m, decorator, allocator}; + typename std::decay::type>{ + m, decorator}; } } // http diff --git a/include/beast/http/write.hpp b/include/beast/http/write.hpp index eed4250a..24332804 100644 --- a/include/beast/http/write.hpp +++ b/include/beast/http/write.hpp @@ -58,12 +58,11 @@ namespace http { @see serializer */ -template +template void write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr); + isRequest, Body, Fields, Decorator>& sr); /** Write part of a message to a stream using a serializer. @@ -95,12 +94,11 @@ write_some(SyncWriteStream& stream, serializer< @see @ref async_write_some, @ref serializer */ -template +template void write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec); /** Write part of a message to a stream asynchronously using a serializer. @@ -149,14 +147,14 @@ write_some(SyncWriteStream& stream, serializer< */ template + class Decorator, class WriteHandler> #if BEAST_DOXYGEN void_or_deduced #else async_return_type #endif async_write_some(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler); //------------------------------------------------------------------------------ @@ -186,12 +184,11 @@ async_write_some(AsyncWriteStream& stream, serializer< @see @ref serializer */ -template +template void write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr); + isRequest, Body, Fields, Decorator>& sr); /** Write a header to a stream using a serializer. @@ -218,12 +215,11 @@ write_header(SyncWriteStream& stream, serializer< @see @ref serializer */ -template +template void write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec); /** Write a header to a stream asynchronously using a serializer. @@ -267,14 +263,14 @@ write_header(SyncWriteStream& stream, serializer< */ template + class Decorator, class WriteHandler> #if BEAST_DOXYGEN void_or_deduced #else async_return_type #endif async_write_header(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler); //------------------------------------------------------------------------------ @@ -301,12 +297,11 @@ async_write_header(AsyncWriteStream& stream, serializer< @see @ref serializer */ -template +template void write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr); + isRequest, Body, Fields, Decorator>& sr); /** Write a complete message to a stream using a serializer. @@ -330,12 +325,11 @@ write(SyncWriteStream& stream, serializer< @see @ref serializer */ -template +template void write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, error_code& ec); /** Write a complete message to a stream asynchronously using a serializer. @@ -376,14 +370,14 @@ write(SyncWriteStream& stream, serializer< */ template + class Decorator, class WriteHandler> #if BEAST_DOXYGEN void_or_deduced #else async_return_type #endif async_write(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator, Allocator>& sr, + isRequest, Body, Fields, Decorator>& sr, WriteHandler&& handler); //------------------------------------------------------------------------------ diff --git a/test/http/doc_snippets.cpp b/test/http/doc_snippets.cpp index 8d357bdb..473330ac 100644 --- a/test/http/doc_snippets.cpp +++ b/test/http/doc_snippets.cpp @@ -342,8 +342,7 @@ template< bool isRequest, class Body, class Fields, - class ChunkDecorator = no_chunk_decorator, - class Allocator = std::allocator + class ChunkDecorator = no_chunk_decorator > class serializer;