Line data Source code
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_HTTP_PROTO_DETAIL_FILTER_HPP
11 : #define BOOST_HTTP_PROTO_DETAIL_FILTER_HPP
12 :
13 : #include <boost/http_proto/detail/config.hpp>
14 : #include <boost/buffers/const_buffer.hpp>
15 : #include <boost/buffers/const_buffer_span.hpp>
16 : #include <boost/buffers/mutable_buffer_span.hpp>
17 : #include <boost/buffers/type_traits.hpp>
18 : #include <boost/system/error_code.hpp>
19 : #include <cstddef>
20 :
21 : namespace boost {
22 : namespace http_proto {
23 : namespace detail {
24 :
25 : /** A filter for buffers
26 : */
27 : class BOOST_HTTP_PROTO_DECL
28 : filter
29 : {
30 : template<
31 : class T,
32 : std::size_t N>
33 : class unrolled;
34 :
35 : public:
36 : /** The results of processing the filter.
37 : */
38 : struct results
39 : {
40 : /** The number of bytes produced in the output.
41 :
42 : This may be less than the total number
43 : of bytes available for writing in the
44 : destination buffers.
45 : */
46 : std::size_t out_bytes = 0;
47 :
48 : /** The number of bytes consumed from the input.
49 :
50 : This may be less than the total number
51 : of bytes available for reading in the
52 : source buffers.
53 : */
54 : std::size_t in_bytes = 0;
55 :
56 : /** The error, if any occurred.
57 : */
58 : system::error_code ec;
59 :
60 : /** True if there will be no more output.
61 : */
62 : bool finished = false;
63 : };
64 :
65 : /** Called to process the filter.
66 :
67 : @par Preconditions
68 : @ref init was called once before any
69 : calls to `process`.
70 : */
71 : template<
72 : class MutableBufferSequence,
73 : class ConstBufferSequence>
74 : results
75 23756 : process(
76 : MutableBufferSequence const& out,
77 : ConstBufferSequence const& in,
78 : bool more)
79 : {
80 : static_assert(
81 : buffers::is_mutable_buffer_sequence<
82 : MutableBufferSequence>::value,
83 : "Type requirements not met");
84 :
85 : static_assert(
86 : buffers::is_const_buffer_sequence<
87 : ConstBufferSequence>::value,
88 : "Type requirements not met");
89 :
90 23756 : return process_impl(out, in, more);
91 : }
92 :
93 : #ifdef BOOST_BUFFERS_DOCS
94 : protected:
95 : #else
96 : private:
97 : #endif
98 : /** Derived class override.
99 :
100 : @par Preconditions
101 : @ref init was called once before any
102 : calls to `process`
103 : */
104 : virtual
105 : results
106 : on_process(
107 : buffers::mutable_buffer out,
108 : buffers::const_buffer in,
109 : bool more) = 0;
110 :
111 : /** Called to process the filter.
112 :
113 : @par Preconditions
114 : @ref init was called once before any
115 : calls to `process`.
116 : */
117 : virtual
118 : results
119 : on_process(
120 : buffers::mutable_buffer_span out,
121 : buffers::const_buffer_span in,
122 : bool more);
123 :
124 : private:
125 : results
126 23756 : process_impl(
127 : buffers::mutable_buffer const& out,
128 : buffers::const_buffer const& in,
129 : bool more)
130 : {
131 23756 : return on_process(out, in, more);
132 : }
133 :
134 : results
135 : process_impl(
136 : buffers::mutable_buffer_span const& out,
137 : buffers::const_buffer_span const& in,
138 : bool more)
139 : {
140 : return on_process(out, in, more);
141 : }
142 :
143 : template<
144 : class MutableBuffers,
145 : class ConstBuffers>
146 : results
147 : process_impl(
148 : MutableBuffers const& out,
149 : ConstBuffers const& in,
150 : bool more);
151 : };
152 :
153 : } // detail
154 : } // http_proto
155 : } // boost
156 :
157 : #include "impl/filter.hpp"
158 :
159 : #endif
|