]> git.proxmox.com Git - ceph.git/blob - ceph/src/Beast/include/beast/http/detail/basic_fields.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / http / detail / basic_fields.hpp
1 //
2 // Copyright (c) 2013-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
8 #ifndef BEAST_HTTP_DETAIL_BASIC_FIELDS_HPP
9 #define BEAST_HTTP_DETAIL_BASIC_FIELDS_HPP
10
11 #include <beast/core/detail/ci_char_traits.hpp>
12 #include <boost/intrusive/list.hpp>
13 #include <boost/intrusive/set.hpp>
14 #include <boost/utility/string_ref.hpp>
15
16 namespace beast {
17 namespace http {
18
19 template<class Allocator>
20 class basic_fields;
21
22 namespace detail {
23
24 class basic_fields_base
25 {
26 public:
27 struct value_type
28 {
29 std::string first;
30 std::string second;
31
32 value_type(boost::string_ref const& name_,
33 boost::string_ref const& value_)
34 : first(name_)
35 , second(value_)
36 {
37 }
38
39 boost::string_ref
40 name() const
41 {
42 return first;
43 }
44
45 boost::string_ref
46 value() const
47 {
48 return second;
49 }
50 };
51
52 protected:
53 template<class Allocator>
54 friend class beast::http::basic_fields;
55
56 struct element
57 : boost::intrusive::set_base_hook <
58 boost::intrusive::link_mode <
59 boost::intrusive::normal_link>>
60 , boost::intrusive::list_base_hook <
61 boost::intrusive::link_mode <
62 boost::intrusive::normal_link>>
63 {
64 value_type data;
65
66 element(boost::string_ref const& name,
67 boost::string_ref const& value)
68 : data(name, value)
69 {
70 }
71 };
72
73 struct less : private beast::detail::ci_less
74 {
75 template<class String>
76 bool
77 operator()(String const& lhs, element const& rhs) const
78 {
79 return ci_less::operator()(lhs, rhs.data.first);
80 }
81
82 template<class String>
83 bool
84 operator()(element const& lhs, String const& rhs) const
85 {
86 return ci_less::operator()(lhs.data.first, rhs);
87 }
88
89 bool
90 operator()(element const& lhs, element const& rhs) const
91 {
92 return ci_less::operator()(
93 lhs.data.first, rhs.data.first);
94 }
95 };
96
97 using list_t = boost::intrusive::make_list<element,
98 boost::intrusive::constant_time_size<false>>::type;
99
100 using set_t = boost::intrusive::make_multiset<element,
101 boost::intrusive::constant_time_size<true>,
102 boost::intrusive::compare<less>>::type;
103
104 // data
105 set_t set_;
106 list_t list_;
107
108 basic_fields_base(set_t&& set, list_t&& list)
109 : set_(std::move(set))
110 , list_(std::move(list))
111 {
112 }
113
114 public:
115 class const_iterator;
116
117 using iterator = const_iterator;
118
119 basic_fields_base() = default;
120 };
121
122 //------------------------------------------------------------------------------
123
124 class basic_fields_base::const_iterator
125 {
126 using iter_type = list_t::const_iterator;
127
128 iter_type it_;
129
130 template<class Allocator>
131 friend class beast::http::basic_fields;
132
133 friend class basic_fields_base;
134
135 const_iterator(iter_type it)
136 : it_(it)
137 {
138 }
139
140 public:
141 using value_type =
142 typename basic_fields_base::value_type;
143 using pointer = value_type const*;
144 using reference = value_type const&;
145 using difference_type = std::ptrdiff_t;
146 using iterator_category =
147 std::bidirectional_iterator_tag;
148
149 const_iterator() = default;
150 const_iterator(const_iterator&& other) = default;
151 const_iterator(const_iterator const& other) = default;
152 const_iterator& operator=(const_iterator&& other) = default;
153 const_iterator& operator=(const_iterator const& other) = default;
154
155 bool
156 operator==(const_iterator const& other) const
157 {
158 return it_ == other.it_;
159 }
160
161 bool
162 operator!=(const_iterator const& other) const
163 {
164 return !(*this == other);
165 }
166
167 reference
168 operator*() const
169 {
170 return it_->data;
171 }
172
173 pointer
174 operator->() const
175 {
176 return &**this;
177 }
178
179 const_iterator&
180 operator++()
181 {
182 ++it_;
183 return *this;
184 }
185
186 const_iterator
187 operator++(int)
188 {
189 auto temp = *this;
190 ++(*this);
191 return temp;
192 }
193
194 const_iterator&
195 operator--()
196 {
197 --it_;
198 return *this;
199 }
200
201 const_iterator
202 operator--(int)
203 {
204 auto temp = *this;
205 --(*this);
206 return temp;
207 }
208 };
209
210 } // detail
211 } // http
212 } // beast
213
214 #endif