]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/http/detail/basic_parsed_list.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / http / detail / basic_parsed_list.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot 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/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP
11 #define BOOST_BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP
12
13 #include <boost/beast/core/string.hpp>
14 #include <boost/beast/core/detail/empty_base_optimization.hpp>
15 #include <cstddef>
16 #include <iterator>
17
18 namespace boost {
19 namespace beast {
20 namespace http {
21 namespace detail {
22
23 /** A list parser which presents the sequence as a container.
24 */
25 template<class Policy>
26 class basic_parsed_list
27 {
28 string_view s_;
29
30 public:
31 /// The type of policy this list uses for parsing.
32 using policy_type = Policy;
33
34 /// The type of each element in the list.
35 using value_type = typename Policy::value_type;
36
37 /// A constant iterator to a list element.
38 #if BOOST_BEAST_DOXYGEN
39 using const_iterator = implementation_defined;
40 #else
41 class const_iterator;
42 #endif
43
44 class const_iterator
45 : private beast::detail::
46 empty_base_optimization<Policy>
47 {
48 basic_parsed_list const* list_ = nullptr;
49 char const* it_ = nullptr;
50 typename Policy::value_type v_;
51 bool error_ = false;
52
53 public:
54 using value_type =
55 typename Policy::value_type;
56 using reference = value_type const&;
57 using pointer = value_type const*;
58 using difference_type = std::ptrdiff_t;
59 using iterator_category =
60 std::forward_iterator_tag;
61
62 const_iterator() = default;
63
64 bool
65 operator==(
66 const_iterator const& other) const
67 {
68 return
69 other.list_ == list_ &&
70 other.it_ == it_;
71 }
72
73 bool
74 operator!=(
75 const_iterator const& other) const
76 {
77 return ! (*this == other);
78 }
79
80 reference
81 operator*() const
82 {
83 return v_;
84 }
85
86 const_iterator&
87 operator++()
88 {
89 increment();
90 return *this;
91 }
92
93 const_iterator
94 operator++(int)
95 {
96 auto temp = *this;
97 ++(*this);
98 return temp;
99 }
100
101 bool
102 error() const
103 {
104 return error_;
105 }
106
107 private:
108 friend class basic_parsed_list;
109
110 const_iterator(
111 basic_parsed_list const& list, bool at_end)
112 : list_(&list)
113 , it_(at_end ? nullptr :
114 list.s_.begin())
115 {
116 if(! at_end)
117 increment();
118 }
119
120 void
121 increment()
122 {
123 if(! this->member()(
124 v_, it_, list_->s_))
125 {
126 it_ = nullptr;
127 error_ = true;
128 }
129 }
130 };
131
132 /// Construct a list from a string
133 explicit
134 basic_parsed_list(string_view s)
135 : s_(s)
136 {
137 }
138
139 /// Return a const iterator to the beginning of the list
140 const_iterator begin() const;
141
142 /// Return a const iterator to the end of the list
143 const_iterator end() const;
144
145 /// Return a const iterator to the beginning of the list
146 const_iterator cbegin() const;
147
148 /// Return a const iterator to the end of the list
149 const_iterator cend() const;
150 };
151
152 template<class Policy>
153 inline
154 auto
155 basic_parsed_list<Policy>::
156 begin() const ->
157 const_iterator
158 {
159 return const_iterator{*this, false};
160 }
161
162 template<class Policy>
163 inline
164 auto
165 basic_parsed_list<Policy>::
166 end() const ->
167 const_iterator
168 {
169 return const_iterator{*this, true};
170 }
171
172 template<class Policy>
173 inline
174 auto
175 basic_parsed_list<Policy>::
176 cbegin() const ->
177 const_iterator
178 {
179 return const_iterator{*this, false};
180 }
181
182 template<class Policy>
183 inline
184 auto
185 basic_parsed_list<Policy>::
186 cend() const ->
187 const_iterator
188 {
189 return const_iterator{*this, true};
190 }
191
192 } // detail
193 } // http
194 } // beast
195 } // boost
196
197 #endif
198