| 1 | // |
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | // |
| 7 | // Official repository: https://github.com/boostorg/beast |
| 8 | // |
| 9 | |
| 10 | #ifndef BOOST_BEAST_DETAIL_BUFFERS_PAIR_HPP |
| 11 | #define BOOST_BEAST_DETAIL_BUFFERS_PAIR_HPP |
| 12 | |
| 13 | #include <boost/asio/buffer.hpp> |
| 14 | #include <boost/assert.hpp> |
| 15 | #include <boost/config/workaround.hpp> |
| 16 | #include <type_traits> |
| 17 | |
| 18 | namespace boost { |
| 19 | namespace beast { |
| 20 | namespace detail { |
| 21 | |
| 22 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) |
| 23 | # pragma warning (push) |
| 24 | # pragma warning (disable: 4521) // multiple copy constructors specified |
| 25 | # pragma warning (disable: 4522) // multiple assignment operators specified |
| 26 | #endif |
| 27 | |
| 28 | template<bool isMutable> |
| 29 | class buffers_pair |
| 30 | { |
| 31 | public: |
| 32 | // VFALCO: This type is public otherwise |
| 33 | // asio::buffers_iterator won't compile. |
| 34 | using value_type = typename |
| 35 | std::conditional<isMutable, |
| 36 | net::mutable_buffer, |
| 37 | net::const_buffer>::type; |
| 38 | |
| 39 | using const_iterator = value_type const*; |
| 40 | |
| 41 | buffers_pair() = default; |
| 42 | |
| 43 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) |
| 44 | buffers_pair(buffers_pair const& other) |
| 45 | : buffers_pair( |
| 46 | *other.begin(), *(other.begin() + 1)) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | buffers_pair& |
| 51 | operator=(buffers_pair const& other) |
| 52 | { |
| 53 | b_[0] = *other.begin(); |
| 54 | b_[1] = *(other.begin() + 1); |
| 55 | return *this; |
| 56 | } |
| 57 | #else |
| 58 | buffers_pair(buffers_pair const& other) = default; |
| 59 | buffers_pair& operator=(buffers_pair const& other) = default; |
| 60 | #endif |
| 61 | |
| 62 | template< |
| 63 | bool isMutable_ = isMutable, |
| 64 | class = typename std::enable_if< |
| 65 | ! isMutable_>::type> |
| 66 | buffers_pair(buffers_pair<true> const& other) |
| 67 | : buffers_pair( |
| 68 | *other.begin(), *(other.begin() + 1)) |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | template< |
| 73 | bool isMutable_ = isMutable, |
| 74 | class = typename std::enable_if< |
| 75 | ! isMutable_>::type> |
| 76 | buffers_pair& |
| 77 | operator=(buffers_pair<true> const& other) |
| 78 | { |
| 79 | b_[0] = *other.begin(); |
| 80 | b_[1] = *(other.begin() + 1); |
| 81 | return *this; |
| 82 | } |
| 83 | |
| 84 | buffers_pair(value_type b0, value_type b1) |
| 85 | : b_{b0, b1} |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | const_iterator |
| 90 | begin() const noexcept |
| 91 | { |
| 92 | return &b_[0]; |
| 93 | } |
| 94 | |
| 95 | const_iterator |
| 96 | end() const noexcept |
| 97 | { |
| 98 | if(b_[1].size() > 0) |
| 99 | return &b_[2]; |
| 100 | return &b_[1]; |
| 101 | } |
| 102 | |
| 103 | private: |
| 104 | value_type b_[2]; |
| 105 | }; |
| 106 | |
| 107 | #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) |
| 108 | # pragma warning (pop) |
| 109 | #endif |
| 110 | |
| 111 | } // detail |
| 112 | } // beast |
| 113 | } // boost |
| 114 | |
| 115 | #endif |
| 116 | |