123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- #ifndef BOOST_BEAST_FLAT_STATIC_BUFFER_HPP
- #define BOOST_BEAST_FLAT_STATIC_BUFFER_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/asio/buffer.hpp>
- #include <algorithm>
- #include <cstddef>
- #include <cstring>
- namespace boost {
- namespace beast {
- class flat_static_buffer_base
- {
- char* begin_;
- char* in_;
- char* out_;
- char* last_;
- char* end_;
- flat_static_buffer_base(
- flat_static_buffer_base const& other) = delete;
- flat_static_buffer_base& operator=(
- flat_static_buffer_base const&) = delete;
- public:
-
- flat_static_buffer_base(
- void* p, std::size_t n) noexcept
- {
- reset(p, n);
- }
-
- BOOST_BEAST_DECL
- void
- clear() noexcept;
-
-
- using const_buffers_type = net::const_buffer;
-
- using mutable_buffers_type = net::mutable_buffer;
-
- std::size_t
- size() const noexcept
- {
- return out_ - in_;
- }
-
- std::size_t
- max_size() const noexcept
- {
- return dist(begin_, end_);
- }
-
- std::size_t
- capacity() const noexcept
- {
- return max_size();
- }
-
- const_buffers_type
- data() const noexcept
- {
- return {in_, dist(in_, out_)};
- }
-
- const_buffers_type
- cdata() const noexcept
- {
- return data();
- }
-
- mutable_buffers_type
- data() noexcept
- {
- return {in_, dist(in_, out_)};
- }
-
- BOOST_BEAST_DECL
- mutable_buffers_type
- prepare(std::size_t n);
-
- void
- commit(std::size_t n) noexcept
- {
- out_ += (std::min<std::size_t>)(n, last_ - out_);
- }
-
- BOOST_BEAST_DECL
- void
- consume(std::size_t n) noexcept;
- protected:
-
- flat_static_buffer_base() = default;
-
- BOOST_BEAST_DECL
- void
- reset(void* p, std::size_t n) noexcept;
- private:
- static
- std::size_t
- dist(char const* first, char const* last) noexcept
- {
- return static_cast<std::size_t>(last - first);
- }
- };
- template<std::size_t N>
- class flat_static_buffer : public flat_static_buffer_base
- {
- char buf_[N];
- public:
-
- flat_static_buffer(flat_static_buffer const&);
-
- flat_static_buffer()
- : flat_static_buffer_base(buf_, N)
- {
- }
-
- flat_static_buffer& operator=(flat_static_buffer const&);
-
- flat_static_buffer_base&
- base()
- {
- return *this;
- }
-
- flat_static_buffer_base const&
- base() const
- {
- return *this;
- }
-
- std::size_t constexpr
- max_size() const
- {
- return N;
- }
-
- std::size_t constexpr
- capacity() const
- {
- return N;
- }
- };
- }
- }
- #include <boost/beast/core/impl/flat_static_buffer.hpp>
- #ifdef BOOST_BEAST_HEADER_ONLY
- #include <boost/beast/core/impl/flat_static_buffer.ipp>
- #endif
- #endif
|