forked from cppalliance/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_of_const_buffers.cpp
More file actions
80 lines (71 loc) · 1.39 KB
/
Copy patharray_of_const_buffers.cpp
File metadata and controls
80 lines (71 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
// Copyright (c) 2025 Mohammad Nejati
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/http
//
#include "src/detail/array_of_const_buffers.hpp"
#include <boost/http/detail/except.hpp>
namespace boost {
namespace http {
namespace detail {
array_of_const_buffers::
array_of_const_buffers(
value_type* p,
std::uint16_t capacity) noexcept
: base_(p)
, cap_(capacity)
, pos_(0)
, size_(0)
{
}
void
array_of_const_buffers::
consume(std::size_t n)
{
while(size_ > 0)
{
auto* p = base_ + pos_;
if(n < p->size())
{
*p += n;
return;
}
n -= p->size();
++pos_;
--size_;
}
}
void
array_of_const_buffers::
reset(std::uint16_t n) noexcept
{
BOOST_ASSERT(n <= cap_);
pos_ = 0;
size_ = n;
}
void
array_of_const_buffers::
slide_to_front() noexcept
{
auto* p = base_ + pos_; // begin
auto* e = p + size_; // end
auto* d = base_; // dest
while(p < e)
*d++ = *p++;
pos_ = 0;
}
void
array_of_const_buffers::
append(value_type buf) noexcept
{
BOOST_ASSERT(size_ < cap_);
base_[pos_ + size_] = buf;
++size_;
}
} // detail
} // http
} // boost