Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/buffers |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_BUFFERS_MUTABLE_BUFFER_SPAN_HPP |
11 |
|
|
#define BOOST_BUFFERS_MUTABLE_BUFFER_SPAN_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/buffers/detail/config.hpp> |
14 |
|
|
#include <boost/buffers/mutable_buffer.hpp> |
15 |
|
|
#include <boost/buffers/mutable_buffer_subspan.hpp> |
16 |
|
|
#include <boost/buffers/type_traits.hpp> |
17 |
|
|
|
18 |
|
|
namespace boost { |
19 |
|
|
namespace buffers { |
20 |
|
|
|
21 |
|
|
/** Holds a span of buffers that are modifiable. |
22 |
|
|
|
23 |
|
|
Objects of this type meet the requirements |
24 |
|
|
of <em>MutableBufferSequence</em>. |
25 |
|
|
*/ |
26 |
|
|
class mutable_buffer_span |
27 |
|
|
{ |
28 |
|
|
mutable_buffer const* p_ = nullptr; |
29 |
|
|
std::size_t n_ = 0; |
30 |
|
|
|
31 |
|
|
friend class mutable_buffer_subspan; |
32 |
|
|
|
33 |
|
|
public: |
34 |
|
|
/** The type of buffer. |
35 |
|
|
*/ |
36 |
|
|
using value_type = mutable_buffer; |
37 |
|
|
|
38 |
|
|
/** The type of iterators returned. |
39 |
|
|
*/ |
40 |
|
|
using const_iterator = value_type const*; |
41 |
|
|
|
42 |
|
|
/** Constructor. |
43 |
|
|
*/ |
44 |
|
|
mutable_buffer_span() = default; |
45 |
|
|
|
46 |
|
|
/** Constructor. |
47 |
|
|
*/ |
48 |
|
16150 |
mutable_buffer_span( |
49 |
|
|
mutable_buffer const* p, |
50 |
|
|
std::size_t n) noexcept |
51 |
|
16150 |
: p_(p) |
52 |
|
16150 |
, n_(n) |
53 |
|
|
{ |
54 |
|
16150 |
} |
55 |
|
|
|
56 |
|
|
/** Constructor. |
57 |
|
|
*/ |
58 |
|
|
template< |
59 |
|
|
class MutableBufferSequence |
60 |
|
|
, class = typename std::enable_if< |
61 |
|
|
! std::is_same< |
62 |
|
|
MutableBufferSequence, |
63 |
|
|
mutable_buffer_span>::value && |
64 |
|
|
is_mutable_buffer_sequence< |
65 |
|
|
MutableBufferSequence>::value && |
66 |
|
|
std::is_same<decltype( |
67 |
|
|
std::declval<MutableBufferSequence |
68 |
|
|
const&>().begin()), |
69 |
|
|
mutable_buffer const*>::value |
70 |
|
|
>::type |
71 |
|
|
> |
72 |
|
|
explicit |
73 |
|
1 |
mutable_buffer_span( |
74 |
|
|
MutableBufferSequence const& bs) noexcept |
75 |
|
1 |
: p_(bs.begin()) |
76 |
|
1 |
, n_(bs.end() - bs.begin()) |
77 |
|
|
{ |
78 |
|
1 |
} |
79 |
|
|
|
80 |
|
|
/** Constructor. |
81 |
|
|
*/ |
82 |
|
|
inline |
83 |
|
|
mutable_buffer_span( |
84 |
|
|
mutable_buffer_span const&) = default; |
85 |
|
|
|
86 |
|
|
/** Assignment. |
87 |
|
|
*/ |
88 |
|
|
mutable_buffer_span& operator=( |
89 |
|
|
mutable_buffer_span const&) = default; |
90 |
|
|
|
91 |
|
|
/** Return an iterator to the beginning. |
92 |
|
|
*/ |
93 |
|
|
const_iterator |
94 |
|
13100 |
begin() const noexcept |
95 |
|
|
{ |
96 |
|
13100 |
return p_; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/** Return an iterator to the end. |
100 |
|
|
*/ |
101 |
|
|
const_iterator |
102 |
|
13100 |
end() const noexcept |
103 |
|
|
{ |
104 |
|
13100 |
return p_ + n_; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
friend |
108 |
|
|
mutable_buffer_subspan |
109 |
|
374 |
tag_invoke( |
110 |
|
|
prefix_tag const&, |
111 |
|
|
mutable_buffer_span const& s, |
112 |
|
|
std::size_t n) noexcept |
113 |
|
|
{ |
114 |
|
374 |
return s.prefix_impl(n); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
friend |
118 |
|
|
mutable_buffer_subspan |
119 |
|
374 |
tag_invoke( |
120 |
|
|
suffix_tag const&, |
121 |
|
|
mutable_buffer_span const& s, |
122 |
|
|
std::size_t n) noexcept |
123 |
|
|
{ |
124 |
|
374 |
return s.suffix_impl(n); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
private: |
128 |
|
|
inline |
129 |
|
|
mutable_buffer_subspan |
130 |
|
|
prefix_impl(std::size_t n) const noexcept; |
131 |
|
|
|
132 |
|
|
inline |
133 |
|
|
mutable_buffer_subspan |
134 |
|
|
suffix_impl(std::size_t n) const noexcept; |
135 |
|
|
}; |
136 |
|
|
|
137 |
|
|
} // buffers |
138 |
|
|
} // boost |
139 |
|
|
|
140 |
|
|
#include <boost/buffers/impl/mutable_buffer_span.hpp> |
141 |
|
|
|
142 |
|
|
#endif |
143 |
|
|
|