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_DETAIL_IMPL_FLAT_BUFFER_IPP | ||
11 | #define BOOST_HTTP_PROTO_DETAIL_IMPL_FLAT_BUFFER_IPP | ||
12 | |||
13 | #include <boost/http_proto/detail/flat_buffer.hpp> | ||
14 | #include <boost/http_proto/detail/except.hpp> | ||
15 | #include <boost/assert.hpp> | ||
16 | |||
17 | namespace boost { | ||
18 | namespace http_proto { | ||
19 | namespace detail { | ||
20 | |||
21 | 736 | flat_buffer:: | |
22 | flat_buffer( | ||
23 | void* data, | ||
24 | std::size_t capacity, | ||
25 | 736 | std::size_t initial_size) noexcept | |
26 | : data_(reinterpret_cast< | ||
27 | unsigned char*>(data)) | ||
28 | , cap_(capacity) | ||
29 | 736 | , in_size_(initial_size) | |
30 | { | ||
31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 736 times.
|
736 | BOOST_ASSERT(in_size_ <= cap_); |
32 | 736 | } | |
33 | |||
34 | bool | ||
35 | ✗ | flat_buffer:: | |
36 | empty() const noexcept | ||
37 | { | ||
38 | ✗ | return in_size_ == 0; | |
39 | } | ||
40 | |||
41 | std::size_t | ||
42 | 6778 | flat_buffer:: | |
43 | size() const noexcept | ||
44 | { | ||
45 | 6778 | return in_size_; | |
46 | } | ||
47 | |||
48 | std::size_t | ||
49 | ✗ | flat_buffer:: | |
50 | capacity() const noexcept | ||
51 | { | ||
52 | ✗ | return cap_; | |
53 | } | ||
54 | |||
55 | const_buffer | ||
56 | ✗ | flat_buffer:: | |
57 | data() const noexcept | ||
58 | { | ||
59 | return { | ||
60 | ✗ | data_ + in_pos_, | |
61 | ✗ | in_size_ }; | |
62 | } | ||
63 | |||
64 | mutable_buffer | ||
65 | 3021 | flat_buffer:: | |
66 | prepare(std::size_t n) | ||
67 | { | ||
68 | // n exceeds available space | ||
69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3021 times.
|
3021 | if(n > cap_ - in_size_) |
70 | ✗ | detail::throw_invalid_argument(); | |
71 | |||
72 | 3021 | out_size_ = n; | |
73 | return { | ||
74 | 3021 | data_ + in_pos_ + in_size_, | |
75 | 3021 | n }; | |
76 | } | ||
77 | |||
78 | void | ||
79 | 3021 | flat_buffer:: | |
80 | commit(std::size_t n) | ||
81 | { | ||
82 | // n exceeds output size | ||
83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3021 times.
|
3021 | if(n > out_size_) |
84 | ✗ | detail::throw_invalid_argument(); | |
85 | |||
86 | 3021 | in_size_ += n; | |
87 | 3021 | out_size_ = 0; | |
88 | 3021 | } | |
89 | |||
90 | void | ||
91 | ✗ | flat_buffer:: | |
92 | consume(std::size_t n) noexcept | ||
93 | { | ||
94 | ✗ | BOOST_ASSERT(out_size_ == 0); | |
95 | |||
96 | // n exceeds input size | ||
97 | ✗ | if(n > in_size_) | |
98 | ✗ | detail::throw_invalid_argument(); | |
99 | |||
100 | ✗ | in_size_ -= n; | |
101 | ✗ | if(in_size_ > 0) | |
102 | ✗ | in_pos_ += n; | |
103 | else | ||
104 | ✗ | in_pos_ = 0; | |
105 | } | ||
106 | |||
107 | } // detail | ||
108 | } // http_proto | ||
109 | } // boost | ||
110 | |||
111 | #endif | ||
112 |