ゴミ箱
basic_parsed_list.hpp
Go to the documentation of this file.
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 
15 #include <cstddef>
16 #include <iterator>
17 
18 namespace boost {
19 namespace beast {
20 namespace http {
21 namespace detail {
22 
25 template<class Policy>
27 {
28  string_view s_;
29 
30 public:
32  using policy_type = Policy;
33 
35  using value_type = typename Policy::value_type;
36 
38 #if BOOST_BEAST_DOXYGEN
39  using const_iterator = implementation_defined;
40 #else
41  class const_iterator;
42 #endif
43 
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
66  const_iterator const& other) const
67  {
68  return
69  other.list_ == list_ &&
70  other.it_ == it_;
71  }
72 
73  bool
75  const_iterator const& other) const
76  {
77  return ! (*this == other);
78  }
79 
80  reference
81  operator*() const
82  {
83  return v_;
84  }
85 
88  {
89  increment();
90  return *this;
91  }
92 
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 
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 
133  explicit
135  : s_(s)
136  {
137  }
138 
140  const_iterator begin() const;
141 
143  const_iterator end() const;
144 
146  const_iterator cbegin() const;
147 
149  const_iterator cend() const;
150 };
151 
152 template<class Policy>
153 inline
154 auto
156 begin() const ->
158 {
159  return const_iterator{*this, false};
160 }
161 
162 template<class Policy>
163 inline
164 auto
166 end() const ->
168 {
169  return const_iterator{*this, true};
170 }
171 
172 template<class Policy>
173 inline
174 auto
176 cbegin() const ->
178 {
179  return const_iterator{*this, false};
180 }
181 
182 template<class Policy>
183 inline
184 auto
186 cend() const ->
188 {
189  return const_iterator{*this, true};
190 }
191 
192 } // detail
193 } // http
194 } // beast
195 } // boost
196 
197 #endif
198 
typename Policy::value_type value_type
The type of each element in the list.
Definition: basic_parsed_list.hpp:35
const_iterator begin() const
Return a const iterator to the beginning of the list.
Definition: basic_parsed_list.hpp:156
Definition: async_result.hpp:20
Policy policy_type
The type of policy this list uses for parsing.
Definition: basic_parsed_list.hpp:32
value_type const & reference
Definition: basic_parsed_list.hpp:56
const_iterator cbegin() const
Return a const iterator to the beginning of the list.
Definition: basic_parsed_list.hpp:176
Definition: beast_common.hpp:6
Definition: basic_parsed_list.hpp:26
bool error() const
Definition: basic_parsed_list.hpp:102
bool operator==(const_iterator const &other) const
Definition: basic_parsed_list.hpp:65
basic_parsed_list(string_view s)
Construct a list from a string.
Definition: basic_parsed_list.hpp:134
reference operator*() const
Definition: basic_parsed_list.hpp:81
std::ptrdiff_t difference_type
Definition: basic_parsed_list.hpp:58
const_iterator & operator++()
Definition: basic_parsed_list.hpp:87
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
std::forward_iterator_tag iterator_category
Definition: basic_parsed_list.hpp:60
const_iterator operator++(int)
Definition: basic_parsed_list.hpp:94
bool operator!=(const_iterator const &other) const
Definition: basic_parsed_list.hpp:74
const_iterator end() const
Return a const iterator to the end of the list.
Definition: basic_parsed_list.hpp:166
typename Policy::value_type value_type
Definition: basic_parsed_list.hpp:55
const_iterator cend() const
Return a const iterator to the end of the list.
Definition: basic_parsed_list.hpp:186
value_type const * pointer
Definition: basic_parsed_list.hpp:57