Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2019 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/http_proto |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_HTTP_PROTO_BUFFER_HPP |
11 |
|
|
#define BOOST_HTTP_PROTO_BUFFER_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/http_proto/detail/config.hpp> |
14 |
|
|
#include <cstdlib> |
15 |
|
|
|
16 |
|
|
namespace boost { |
17 |
|
|
namespace http_proto { |
18 |
|
|
|
19 |
|
|
//------------------------------------------------ |
20 |
|
|
|
21 |
|
|
class mutable_buffer |
22 |
|
|
{ |
23 |
|
|
void* p_ = nullptr; |
24 |
|
|
std::size_t n_ = 0; |
25 |
|
|
|
26 |
|
|
public: |
27 |
|
707 |
mutable_buffer() = default; |
28 |
|
|
mutable_buffer( |
29 |
|
|
mutable_buffer const&) = default; |
30 |
|
|
mutable_buffer& operator=( |
31 |
|
|
mutable_buffer const&) = default; |
32 |
|
|
|
33 |
|
2969 |
mutable_buffer( |
34 |
|
|
void* data, |
35 |
|
|
std::size_t size) noexcept |
36 |
|
2969 |
: p_(data) |
37 |
|
2969 |
, n_(size) |
38 |
|
|
{ |
39 |
|
2969 |
} |
40 |
|
|
|
41 |
|
|
void* |
42 |
|
2969 |
data() const noexcept |
43 |
|
|
{ |
44 |
|
2969 |
return p_; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
std::size_t |
48 |
|
2969 |
size() const noexcept |
49 |
|
|
{ |
50 |
|
2969 |
return n_; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
mutable_buffer& |
54 |
|
|
operator+=(std::size_t n) noexcept |
55 |
|
|
{ |
56 |
|
|
if(n >= n_) |
57 |
|
|
{ |
58 |
|
|
p_ = static_cast< |
59 |
|
|
char*>(p_) + n_; |
60 |
|
|
n_ = 0; |
61 |
|
|
return *this; |
62 |
|
|
} |
63 |
|
|
p_ = static_cast< |
64 |
|
|
char*>(p_) + n; |
65 |
|
|
n_ -= n; |
66 |
|
|
return *this; |
67 |
|
|
} |
68 |
|
|
}; |
69 |
|
|
|
70 |
|
|
//------------------------------------------------ |
71 |
|
|
|
72 |
|
|
class const_buffer |
73 |
|
|
{ |
74 |
|
|
void const* p_ = nullptr; |
75 |
|
|
std::size_t n_ = 0; |
76 |
|
|
|
77 |
|
|
public: |
78 |
|
✗ |
const_buffer() = default; |
79 |
|
|
const_buffer( |
80 |
|
|
const_buffer const&) = default; |
81 |
|
|
const_buffer& operator=( |
82 |
|
|
const_buffer const&) = default; |
83 |
|
|
|
84 |
|
✗ |
const_buffer( |
85 |
|
|
void const* data, |
86 |
|
|
std::size_t size) noexcept |
87 |
|
✗ |
: p_(data) |
88 |
|
✗ |
, n_(size) |
89 |
|
|
{ |
90 |
|
|
} |
91 |
|
|
|
92 |
|
✗ |
const_buffer( |
93 |
|
|
mutable_buffer const& other) noexcept |
94 |
|
✗ |
: p_(other.data()) |
95 |
|
✗ |
, n_(other.size()) |
96 |
|
|
{ |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void const* |
100 |
|
|
data() const noexcept |
101 |
|
|
{ |
102 |
|
|
return p_; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
std::size_t |
106 |
|
✗ |
size() const noexcept |
107 |
|
|
{ |
108 |
|
✗ |
return n_; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
const_buffer& |
112 |
|
✗ |
operator+=(std::size_t n) noexcept |
113 |
|
|
{ |
114 |
|
✗ |
if(n >= n_) |
115 |
|
|
{ |
116 |
|
✗ |
p_ = static_cast< |
117 |
|
✗ |
char const*>(p_) + n_; |
118 |
|
✗ |
n_ = 0; |
119 |
|
✗ |
return *this; |
120 |
|
|
} |
121 |
|
✗ |
p_ = static_cast< |
122 |
|
✗ |
char const*>(p_) + n; |
123 |
|
✗ |
n_ -= n; |
124 |
|
✗ |
return *this; |
125 |
|
|
} |
126 |
|
|
}; |
127 |
|
|
|
128 |
|
|
//------------------------------------------------ |
129 |
|
|
|
130 |
|
|
class mutable_buffers |
131 |
|
|
{ |
132 |
|
|
mutable_buffer const* p_ = nullptr; |
133 |
|
|
std::size_t n_ = 0; |
134 |
|
|
|
135 |
|
|
public: |
136 |
|
|
using value_type = mutable_buffer; |
137 |
|
|
|
138 |
|
|
using iterator = value_type const*; |
139 |
|
|
|
140 |
|
|
mutable_buffers() = default; |
141 |
|
|
|
142 |
|
|
mutable_buffers( |
143 |
|
|
mutable_buffers const&) = default; |
144 |
|
|
|
145 |
|
|
mutable_buffers& operator=( |
146 |
|
|
mutable_buffers const&) = default; |
147 |
|
|
|
148 |
|
2969 |
mutable_buffers( |
149 |
|
|
value_type const* p, |
150 |
|
|
std::size_t n) noexcept |
151 |
|
2969 |
: p_(p) |
152 |
|
2969 |
, n_(n) |
153 |
|
|
{ |
154 |
|
2969 |
} |
155 |
|
|
|
156 |
|
|
std::size_t |
157 |
|
|
size() const noexcept |
158 |
|
|
{ |
159 |
|
|
return n_; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
iterator |
163 |
|
2969 |
begin() const noexcept |
164 |
|
|
{ |
165 |
|
2969 |
return p_; |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
iterator |
169 |
|
|
end() const noexcept |
170 |
|
|
{ |
171 |
|
|
return p_ + n_; |
172 |
|
|
} |
173 |
|
|
}; |
174 |
|
|
|
175 |
|
|
} // http_proto |
176 |
|
|
} // boost |
177 |
|
|
|
178 |
|
|
#endif |
179 |
|
|
|