123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594 |
- #ifndef BOOST_BEAST_MULTI_BUFFER_HPP
- #define BOOST_BEAST_MULTI_BUFFER_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/core/detail/allocator.hpp>
- #include <boost/asio/buffer.hpp>
- #include <boost/core/empty_value.hpp>
- #include <boost/intrusive/list.hpp>
- #include <boost/type_traits/type_with_alignment.hpp>
- #include <iterator>
- #include <limits>
- #include <memory>
- #include <type_traits>
- namespace boost {
- namespace beast {
- template<class Allocator>
- class basic_multi_buffer
- #if ! BOOST_BEAST_DOXYGEN
- : private boost::empty_value<Allocator>
- #endif
- {
-
- static_assert(std::is_pointer<typename
- std::allocator_traits<Allocator>::pointer>::value,
- "Allocator must use regular pointers");
- static bool constexpr default_nothrow =
- std::is_nothrow_default_constructible<Allocator>::value;
-
-
-
- class element
- : public boost::intrusive::list_base_hook<
- boost::intrusive::link_mode<
- boost::intrusive::normal_link>>
- {
- using size_type = typename
- detail::allocator_traits<Allocator>::size_type;
- size_type const size_;
- public:
- element(element const&) = delete;
- explicit
- element(size_type n) noexcept
- : size_(n)
- {
- }
- size_type
- size() const noexcept
- {
- return size_;
- }
- char*
- data() const noexcept
- {
- return const_cast<char*>(
- reinterpret_cast<char const*>(this + 1));
- }
- };
- template<bool>
- class subrange;
- using size_type = typename
- detail::allocator_traits<Allocator>::size_type;
- using align_type = typename
- boost::type_with_alignment<alignof(element)>::type;
- using rebind_type = typename
- beast::detail::allocator_traits<Allocator>::
- template rebind_alloc<align_type>;
- using alloc_traits =
- beast::detail::allocator_traits<rebind_type>;
- using list_type = typename boost::intrusive::make_list<
- element, boost::intrusive::constant_time_size<false>>::type;
- using iter = typename list_type::iterator;
- using const_iter = typename list_type::const_iterator;
- using pocma = typename
- alloc_traits::propagate_on_container_move_assignment;
- using pocca = typename
- alloc_traits::propagate_on_container_copy_assignment;
- static_assert(std::is_base_of<std::bidirectional_iterator_tag,
- typename std::iterator_traits<iter>::iterator_category>::value,
- "BidirectionalIterator type requirements not met");
- static_assert(std::is_base_of<std::bidirectional_iterator_tag,
- typename std::iterator_traits<const_iter>::iterator_category>::value,
- "BidirectionalIterator type requirements not met");
- std::size_t max_;
- list_type list_;
- iter out_;
- size_type in_size_ = 0;
- size_type in_pos_ = 0;
- size_type out_pos_ = 0;
- size_type out_end_ = 0;
- public:
- #if BOOST_BEAST_DOXYGEN
-
- using const_buffers_type = __implementation_defined__;
-
- using mutable_buffers_type = __implementation_defined__;
- #else
- using const_buffers_type = subrange<false>;
- using mutable_buffers_type = subrange<true>;
- #endif
-
- using allocator_type = Allocator;
-
- ~basic_multi_buffer();
-
- basic_multi_buffer() noexcept(default_nothrow);
-
- explicit
- basic_multi_buffer(
- std::size_t limit) noexcept(default_nothrow);
-
- explicit
- basic_multi_buffer(Allocator const& alloc) noexcept;
-
- basic_multi_buffer(
- std::size_t limit, Allocator const& alloc) noexcept;
-
- basic_multi_buffer(basic_multi_buffer&& other) noexcept;
-
- basic_multi_buffer(
- basic_multi_buffer&& other,
- Allocator const& alloc);
-
- basic_multi_buffer(basic_multi_buffer const& other);
-
- basic_multi_buffer(basic_multi_buffer const& other,
- Allocator const& alloc);
-
- template<class OtherAlloc>
- basic_multi_buffer(basic_multi_buffer<
- OtherAlloc> const& other);
-
- template<class OtherAlloc>
- basic_multi_buffer(
- basic_multi_buffer<OtherAlloc> const& other,
- allocator_type const& alloc);
-
- basic_multi_buffer&
- operator=(basic_multi_buffer&& other);
-
- basic_multi_buffer& operator=(
- basic_multi_buffer const& other);
-
- template<class OtherAlloc>
- basic_multi_buffer& operator=(
- basic_multi_buffer<OtherAlloc> const& other);
-
- allocator_type
- get_allocator() const
- {
- return this->get();
- }
-
- void
- max_size(std::size_t n) noexcept
- {
- max_ = n;
- }
-
- void
- reserve(std::size_t n);
-
- void
- shrink_to_fit();
-
- void
- clear() noexcept;
-
- template<class Alloc>
- friend
- void
- swap(
- basic_multi_buffer<Alloc>& lhs,
- basic_multi_buffer<Alloc>& rhs) noexcept;
-
-
- size_type
- size() const noexcept
- {
- return in_size_;
- }
-
- size_type
- max_size() const noexcept
- {
- return max_;
- }
-
- std::size_t
- capacity() const noexcept;
-
- const_buffers_type
- data() const noexcept;
-
- const_buffers_type
- cdata() const noexcept
- {
- return data();
- }
-
- mutable_buffers_type
- data() noexcept;
-
- mutable_buffers_type
- prepare(size_type n);
-
- void
- commit(size_type n) noexcept;
-
- void
- consume(size_type n) noexcept;
- private:
- template<class OtherAlloc>
- friend class basic_multi_buffer;
- template<class OtherAlloc>
- void copy_from(basic_multi_buffer<OtherAlloc> const&);
- void move_assign(basic_multi_buffer& other, std::false_type);
- void move_assign(basic_multi_buffer& other, std::true_type) noexcept;
- void copy_assign(basic_multi_buffer const& other, std::false_type);
- void copy_assign(basic_multi_buffer const& other, std::true_type);
- void swap(basic_multi_buffer&) noexcept;
- void swap(basic_multi_buffer&, std::true_type) noexcept;
- void swap(basic_multi_buffer&, std::false_type) noexcept;
- void destroy(list_type& list) noexcept;
- void destroy(const_iter it);
- void destroy(element& e);
- element& alloc(std::size_t size);
- void debug_check() const;
- };
- using multi_buffer = basic_multi_buffer<std::allocator<char>>;
- }
- }
- #include <boost/beast/core/impl/multi_buffer.hpp>
- #endif
|