1// Boost.Range library
2//
3// Copyright Neil Groves 2010. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8// For more information, see http://www.boost.org/libs/range/
9//
10#ifndef BOOST_RANGE_DETAIL_ANY_ITERATOR_INTERFACE_HPP_INCLUDED
11#define BOOST_RANGE_DETAIL_ANY_ITERATOR_INTERFACE_HPP_INCLUDED
12
13#include <boost/range/detail/any_iterator_buffer.hpp>
14#include <boost/iterator/iterator_categories.hpp>
15#include <boost/type_traits/add_const.hpp>
16#include <boost/type_traits/add_reference.hpp>
17#include <boost/type_traits/is_reference.hpp>
18#include <boost/type_traits/remove_const.hpp>
19#include <boost/type_traits/remove_reference.hpp>
20
21namespace boost
22{
23 namespace range_detail
24 {
25 template<class T>
26 struct const_reference_type_generator
27 {
28 typedef typename mpl::if_<
29 typename is_reference<T>::type,
30 typename add_const<
31 typename remove_reference<T>::type
32 >::type&,
33 T
34 >::type type;
35 };
36
37 template<class T>
38 struct mutable_reference_type_generator
39 {
40 typedef typename mpl::if_<
41 typename mpl::and_<
42 typename is_const<T>::type,
43 typename mpl::not_<typename is_reference<T>::type>::type
44 >::type,
45 T,
46 typename add_reference<T>::type
47 >::type type;
48 };
49
50 template<
51 class Reference
52 , class Buffer
53 >
54 struct any_incrementable_iterator_interface
55 {
56 typedef typename mutable_reference_type_generator<
57 Reference
58 >::type reference;
59
60 typedef typename const_reference_type_generator<
61 Reference
62 >::type const_reference;
63
64 typedef typename remove_const<
65 typename remove_reference<Reference>::type
66 >::type reference_as_value_type;
67
68 typedef Buffer buffer_type;
69
70 virtual ~any_incrementable_iterator_interface() {}
71
72 virtual any_incrementable_iterator_interface*
73 clone(buffer_type& buffer) const = 0;
74
75 virtual any_incrementable_iterator_interface<const_reference, Buffer>*
76 clone_const_ref(buffer_type& buffer) const = 0;
77
78 virtual any_incrementable_iterator_interface<reference_as_value_type, Buffer>*
79 clone_reference_as_value(buffer_type& buffer) const = 0;
80
81 virtual void increment() = 0;
82 };
83
84 template<
85 class Reference
86 , class Buffer
87 >
88 struct any_single_pass_iterator_interface
89 : any_incrementable_iterator_interface<Reference, Buffer>
90 {
91 typedef typename any_incrementable_iterator_interface<Reference, Buffer>::reference reference;
92 typedef typename any_incrementable_iterator_interface<Reference, Buffer>::const_reference const_reference;
93 typedef typename any_incrementable_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
94 typedef typename any_incrementable_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
95
96 virtual any_single_pass_iterator_interface*
97 clone(buffer_type& buffer) const = 0;
98
99 virtual any_single_pass_iterator_interface<const_reference, Buffer>*
100 clone_const_ref(buffer_type& buffer) const = 0;
101
102 virtual any_single_pass_iterator_interface<reference_as_value_type, Buffer>*
103 clone_reference_as_value(buffer_type& buffer) const = 0;
104
105 virtual reference dereference() const = 0;
106
107 virtual bool equal(const any_single_pass_iterator_interface& other) const = 0;
108 };
109
110 template<
111 class Reference
112 , class Buffer
113 >
114 struct any_forward_iterator_interface
115 : any_single_pass_iterator_interface<Reference, Buffer>
116 {
117 typedef typename any_single_pass_iterator_interface<Reference, Buffer>::reference reference;
118 typedef typename any_single_pass_iterator_interface<Reference, Buffer>::const_reference const_reference;
119 typedef typename any_single_pass_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
120 typedef typename any_single_pass_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
121
122 virtual any_forward_iterator_interface*
123 clone(buffer_type& buffer) const = 0;
124
125 virtual any_forward_iterator_interface<const_reference, Buffer>*
126 clone_const_ref(buffer_type& buffer) const = 0;
127
128 virtual any_forward_iterator_interface<reference_as_value_type, Buffer>*
129 clone_reference_as_value(buffer_type& buffer) const = 0;
130 };
131
132 template<
133 class Reference
134 , class Buffer
135 >
136 struct any_bidirectional_iterator_interface
137 : any_forward_iterator_interface<Reference, Buffer>
138 {
139 typedef typename any_forward_iterator_interface<Reference, Buffer>::reference reference;
140 typedef typename any_forward_iterator_interface<Reference, Buffer>::const_reference const_reference;
141 typedef typename any_forward_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
142 typedef typename any_forward_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
143
144 virtual any_bidirectional_iterator_interface*
145 clone(buffer_type& buffer) const = 0;
146
147 virtual any_bidirectional_iterator_interface<const_reference, Buffer>*
148 clone_const_ref(buffer_type& buffer) const = 0;
149
150 virtual any_bidirectional_iterator_interface<reference_as_value_type, Buffer>*
151 clone_reference_as_value(buffer_type& buffer) const = 0;
152
153 virtual void decrement() = 0;
154 };
155
156 template<
157 class Reference
158 , class Difference
159 , class Buffer
160 >
161 struct any_random_access_iterator_interface
162 : any_bidirectional_iterator_interface<
163 Reference
164 , Buffer
165 >
166 {
167 typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::reference reference;
168 typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::const_reference const_reference;
169 typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::buffer_type buffer_type;
170 typedef typename any_bidirectional_iterator_interface<Reference, Buffer>::reference_as_value_type reference_as_value_type;
171 typedef Difference difference_type;
172
173 virtual any_random_access_iterator_interface*
174 clone(buffer_type& buffer) const = 0;
175
176 virtual any_random_access_iterator_interface<const_reference, Difference, Buffer>*
177 clone_const_ref(buffer_type& buffer) const = 0;
178
179 virtual any_random_access_iterator_interface<reference_as_value_type, Difference, Buffer>*
180 clone_reference_as_value(buffer_type& buffer) const = 0;
181
182 virtual void advance(Difference offset) = 0;
183
184 virtual Difference distance_to(const any_random_access_iterator_interface& other) const = 0;
185 };
186
187 template<
188 class Traversal
189 , class Reference
190 , class Difference
191 , class Buffer
192 >
193 struct any_iterator_interface_type_generator;
194
195 template<
196 class Reference
197 , class Difference
198 , class Buffer
199 >
200 struct any_iterator_interface_type_generator<
201 incrementable_traversal_tag
202 , Reference
203 , Difference
204 , Buffer
205 >
206 {
207 typedef any_incrementable_iterator_interface<Reference, Buffer> type;
208 };
209
210 template<
211 class Reference
212 , class Difference
213 , class Buffer
214 >
215 struct any_iterator_interface_type_generator<
216 single_pass_traversal_tag
217 , Reference
218 , Difference
219 , Buffer
220 >
221 {
222 typedef any_single_pass_iterator_interface<Reference, Buffer> type;
223 };
224
225 template<
226 class Reference
227 , class Difference
228 , class Buffer
229 >
230 struct any_iterator_interface_type_generator<
231 forward_traversal_tag
232 , Reference
233 , Difference
234 , Buffer
235 >
236 {
237 typedef any_forward_iterator_interface<Reference, Buffer> type;
238 };
239
240 template<
241 class Reference
242 , class Difference
243 , class Buffer
244 >
245 struct any_iterator_interface_type_generator<
246 bidirectional_traversal_tag
247 , Reference
248 , Difference
249 , Buffer
250 >
251 {
252 typedef any_bidirectional_iterator_interface<Reference, Buffer> type;
253 };
254
255 template<
256 class Reference
257 , class Difference
258 , class Buffer
259 >
260 struct any_iterator_interface_type_generator<
261 random_access_traversal_tag
262 , Reference
263 , Difference
264 , Buffer
265 >
266 {
267 typedef any_random_access_iterator_interface<
268 Reference
269 , Difference
270 , Buffer
271 > type;
272 };
273
274 } // namespace range_detail
275} // namespace boost
276
277#endif // include guard
278