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