stlab.adobe.com Adobe Systems Incorporated
any_iterator.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2007 Adobe Systems Incorporated
3  Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
4  or a copy at http://stlab.adobe.com/licenses.html)
5 */
6 
7 /*************************************************************************************************/
8 
9 #ifndef ADOBE_ANY_ITERATOR_HPP
10 #define ADOBE_ANY_ITERATOR_HPP
11 
12 #include <adobe/config.hpp>
13 
14 #include <boost/concept_check.hpp>
15 
16 #include <adobe/move.hpp>
17 #include <adobe/poly.hpp>
18 
19 /*************************************************************************************************/
20 
21 namespace adobe {
22 
23 /*************************************************************************************************/
24 
25 template < typename V, // T models Regular Type
26  typename R = V&, // R models Reference Type
27  typename D = std::ptrdiff_t // D models Signed Integer
28  >
30 {
31  virtual R dereference() const = 0;
32  virtual void increment() = 0;
33  virtual bool equals(const poly_iterator_interface &) const = 0;
34 };
35 
36 
37 
38 /*************************************************************************************************/
39 
40 template < typename V, // T models Regular Type
41  typename R = V&, // R models Reference Type
42  typename D = std::ptrdiff_t // D models Signed Integer
43  >
45  template <typename I>
46  struct type : optimized_storage_type<I, poly_iterator_interface<V, R, D> >::type
47  {
49 
50 // this is too restrictive check; need to make appropriate one
51 #ifndef NO_ASL_AI_CONCEPT_CHECK
52  BOOST_CLASS_REQUIRE(I, boost, ForwardIteratorConcept);
53 #endif
54 
55  type(const I& x) : base_t (x)
56  { }
57 
59  : base_t(move_from<base_t>(x.source))
60  { }
61 
62  type() : base_t()
63  { }
64 
65  R dereference() const
66  { return *this->get(); }
67 
68  void increment()
69  { ++this->get(); }
70 
72  {
73  return this->type_info() == x.type_info() && this->get() == *static_cast<const I*>(x.cast());
74  }
75  };
76 };
77 
78 /*************************************************************************************************/
79 
80 template < typename V, // T models Regular Type
81  typename R = V&, // R models Reference Type
82  typename D = std::ptrdiff_t // D models Signed Integer
83  >
84 struct iter : public poly_base<poly_iterator_interface<V, R, D>,
85  poly_iterator_instance<V, R, D>::template type>,
86  public boost::iterator_facade<iter<V, R, D>,
87  V, std::forward_iterator_tag, R, D
88  >
89 {
92 
93  template <typename Iter>
94  explicit iter(const Iter& s) : base(s)
95  { }
96 
97  iter(move_from<iter> x) : base(move_from<base>(x.source)) { }
98  iter& operator=(iter x) { static_cast<base&>(*this) = adobe::move(static_cast<base&>(x)); return *this; }
99 
100  R dereference() const
101  { return this->interface_ref().dereference(); }
102 
103  void increment()
104  { this->interface_ref().increment(); }
105 
106  bool equal(const iter& x) const
107  { return *this == x; }
108 
109  //disambiguate since iter adaptor and poly both try to provide operator==
110  friend bool operator==(const iter& x, const iter& y)
111  { return base(x) == base(y); }
112 };
113 
114 /*************************************************************************************************/
115 
116 
117 template < typename V, // T models Regular Type
118  typename R = V&, // R models Reference Type
119  typename D = std::ptrdiff_t // D models Signed Integer
120  >
122 {
123  virtual void decrement() = 0;
125 };
126 
127 /*************************************************************************************************/
128 
129 template < typename V, // T models Regular Type
130  typename R = V&, // R models Reference Type
131  typename D = std::ptrdiff_t // D models Signed Integer
132  >
134  template <typename I>
135  struct type : optimized_storage_type<I, any_bidirectional_iterator_interface<V, R, D> >::type
136  {
138 
139 #ifndef NO_ASL_AI_CONCEPT_CHECK
140  BOOST_CLASS_REQUIRE(I, boost, BidirectionalIteratorConcept);
141 #endif
142 
143  type(const I& x)
144  : base_t(x) {}
145 
147  : base_t(move_from<base_t>(x.source)) {}
148 
149  type()
150  : base_t() {}
151 
152  R dereference() const
153  { return *this->get(); }
154 
155  void increment()
156  { ++this->get(); }
157 
158  void decrement()
159  { --this->get(); }
160 
162  {
163  return this->type_info() == x.type_info() && this->get()
164  == *static_cast<const I*>(x.cast());
165  }
166 
168  {
169  return this->type_info() == x.type_info() && this->get()
170  == *static_cast<const I*>(x.cast());
171  }
172 
173  };
174 
175 
176 };
177 
178 /*************************************************************************************************/
179 
180 template < typename V, // T models Regular Type
181  typename R = V&, // R models Reference Type
182  typename D = std::ptrdiff_t // D models Signed Integer
183  >
185  public poly_base<any_bidirectional_iterator_interface<V, R, D>,
186  any_bidirectional_iterator_instance<V, R, D>::template type >,
187  public boost::iterator_facade<bidirectional_iter<V, R, D>,
188  V, std::bidirectional_iterator_tag, R, D>
189 
190 {
193 
194  template <typename Iter>
195  explicit bidirectional_iter(const Iter& s) : base (s) {}
196 
198 
199  bidirectional_iter& operator=(bidirectional_iter x) { static_cast<base&>(*this) = adobe::move(static_cast<base&>(x)); return *this; }
200 
201  R dereference() const
202  { return this->interface_ref().dereference(); }
203 
204  void increment()
205  { this->interface_ref().increment(); }
206 
207  void decrement()
208  { this->interface_ref().decrement(); }
209 
210  bool equal(const bidirectional_iter& x) const
211  { return *this == x; }
212 
213  //disambiguate since iter adaptor and poly both try to provide operator==
214  friend bool operator==(const bidirectional_iter& x, const bidirectional_iter& y)
215  { return x.interface_ref().equals(y.interface_ref()); }
216 };
217 
218 /*************************************************************************************************/
219 
220 template < typename V, // T models Regular Type
221  typename R = V&, // R models Reference Type
222  typename D = std::ptrdiff_t // D models Signed Integer
223  >
225 {
226  virtual void advance(D) = 0;
227  virtual D distance_to(const any_random_access_iterator_interface& x) const = 0;
229 };
230 
231 /*************************************************************************************************/
232 
233 template < typename V, // T models Regular Type
234  typename R = V&, // R models Reference Type
235  typename D = std::ptrdiff_t // D models Signed Integer
236  >
238  template <typename I> // I models Random Access Iterator
239  struct type : optimized_storage_type<I, any_random_access_iterator_interface<V, R, D> >::type
240  {
242 
243 #ifndef NO_ASL_AI_CONCEPT_CHECK
244  BOOST_CLASS_REQUIRE(I, boost, RandomAccessIteratorConcept);
245 #endif
246 
247  type(const I& x)
248  : base_t(x) {}
249 
251  : base_t(move_from<base_t>(x.source)) {}
252 
253  type()
254  : base_t() {}
255 
256  R dereference() const
257  { return *this->get(); }
258 
259  void increment()
260  { ++this->get(); }
261 
262  void decrement()
263  { --this->get(); }
264 
265  void advance(D d)
266  { std::advance(this->get(), d); }
267 
269  {
270  return std::distance(this->get(), *static_cast<const I*>(x.cast()));
271  }
272 
274  {
275  return this->type_info() == x.type_info() && this->get()
276  == *static_cast<const I*>(x.cast());
277  }
278 
280  {
281  return this->type_info() == x.type_info() && this->get()
282  == *static_cast<const I*>(x.cast());
283  }
284 
285 
287  {
288  return this->type_info() == x.type_info() && this->get()
289  == *static_cast<const I*>(x.cast());
290  }
291 
292  };
293 };
294 
295 
296 /*************************************************************************************************/
297 
298 template < typename V, // T models Regular Type
299  typename R = V&, // R models Reference Type
300  typename D = std::ptrdiff_t // D models Signed Integer
301  >
303  public poly_base<any_random_access_iterator_interface<V, R, D>,
304  any_random_access_iterator_instance<V, R, D>::template type>,
305  public boost::iterator_facade<random_access_iter<V, R, D>,
306  V, std::random_access_iterator_tag, R, D>
307 {
310 
311  template <typename Iter>
312  explicit random_access_iter(const Iter& s) : base(s) { }
313 
315 
316  random_access_iter& operator=(random_access_iter x) { static_cast<base&>(*this) = adobe::move(static_cast<base&>(x)); return *this; }
317 
318  R dereference() const
319  { return this->interface_ref().dereference(); }
320 
321  void increment()
322  { this->interface_ref().increment(); }
323 
324  void decrement()
325  { this->interface_ref().decrement(); }
326 
327  void advance(D d)
328  { this->interface_ref().advance(d); }
329 
330  D distance_to(const random_access_iter& x) const
331  {
332  return this->interface_ref().distance_to(x.interface_ref());
333  }
334 
335  bool equal(const random_access_iter& x) const
336  { return *this == x; }
337 
338  //disambiguate since iter adaptor and poly both try to provide operator==
339  friend bool operator==(const random_access_iter& x, const random_access_iter& y)
340  { return x.interface_ref().equals(y.interface_ref()); }
341 };
342 
343 
344 /*************************************************************************************************/
345 
346 } //namespace adobe
347 
348 /*************************************************************************************************/
349 
350 #endif
bidirectional_iter(move_from< bidirectional_iter > x)
friend bool operator==(const random_access_iter &x, const random_access_iter &y)
bool equals(const any_bidirectional_iterator_interface< V, R, D > &x) const
virtual R dereference() const =0
interface_type & interface_ref()
Definition: poly.hpp:382
bidirectional_iter(const Iter &s)
D distance_to(const random_access_iter &x) const
poly_base< any_bidirectional_iterator_interface< V, R, D >, any_bidirectional_iterator_instance< V, R, D >::template type > base
bool equals(const any_bidirectional_iterator_interface< V, R, D > &x) const
iter(move_from< iter > x)
move_from is used for move_ctors.
Definition: move.hpp:306
iter(const Iter &s)
random_access_iter(const Iter &s)
poly_base< poly_iterator_interface< V, R, D >, poly_iterator_instance< V, R, D >::template type > base
boost::difference_type< I >::type distance(I &range)
Definition: distance.hpp:29
friend bool operator==(const bidirectional_iter &x, const bidirectional_iter &y)
bool equal(const random_access_iter &x) const
bool equal(const bidirectional_iter &x) const
R dereference() const
bool equal(const iter &x) const
Authors of a Concept representative F, intended as a template parameter to adobe::poly, will inherit from adobe::poly_base. The first template parameter for adobe::poly_base provides the virtual interface for the concept representative. The second template parameter for adobe::poly_base must inherit from the Concept interface representative. The author&#39;s third duty is to provide forwarding functions in a their Concept representative. See the placeable_concept.hpp header file for details.
Definition: poly.hpp:259
random_access_iter & operator=(random_access_iter x)
optimized_storage_type< I, poly_iterator_interface< V, R, D > >::type base_t
bool equals(const poly_iterator_interface< V, R, D > &x) const
iter & operator=(iter x)
Abstract interface providing signatures needed to implement "handle" objects modeling a Value (Copyab...
Definition: poly.hpp:66
void increment()
bool equals(const poly_iterator_interface< V, R, D > &x) const
friend bool operator==(const iter &x, const iter &y)
optimized_storage_type< I, any_bidirectional_iterator_interface< V, R, D > >::type base_t
bool equals(const any_random_access_iterator_interface< V, R, D > &x) const
bidirectional_iter & operator=(bidirectional_iter x)
D distance_to(const any_random_access_iterator_interface< V, R, D > &x) const
Authors of adobe::poly concept representatives must derive their instance class from this...
Definition: poly.hpp:238
optimized_storage_type< I, any_random_access_iterator_interface< V, R, D > >::type base_t
virtual bool equals(const poly_iterator_interface &) const =0
poly_base< any_random_access_iterator_interface< V, R, D >, any_random_access_iterator_instance< V, R, D >::template type > base
random_access_iter(move_from< random_access_iter > x)
bool equals(const poly_iterator_interface< V, R, D > &x) const
virtual const std::type_info & type_info() const =0

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google