Chris@16
|
1 // (C) Copyright Jens Maurer 2001.
|
Chris@16
|
2 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
3 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 //
|
Chris@16
|
6 // Revision History:
|
Chris@16
|
7
|
Chris@16
|
8 // 15 Nov 2001 Jens Maurer
|
Chris@16
|
9 // created.
|
Chris@16
|
10
|
Chris@16
|
11 // See http://www.boost.org/libs/utility/iterator_adaptors.htm for documentation.
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
|
Chris@16
|
14 #define BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
17 #include <boost/ref.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost {
|
Chris@101
|
20 namespace iterators {
|
Chris@16
|
21
|
Chris@16
|
22 template<class Generator>
|
Chris@16
|
23 class generator_iterator
|
Chris@16
|
24 : public iterator_facade<
|
Chris@16
|
25 generator_iterator<Generator>
|
Chris@16
|
26 , typename Generator::result_type
|
Chris@16
|
27 , single_pass_traversal_tag
|
Chris@16
|
28 , typename Generator::result_type const&
|
Chris@16
|
29 >
|
Chris@16
|
30 {
|
Chris@16
|
31 typedef iterator_facade<
|
Chris@16
|
32 generator_iterator<Generator>
|
Chris@16
|
33 , typename Generator::result_type
|
Chris@16
|
34 , single_pass_traversal_tag
|
Chris@16
|
35 , typename Generator::result_type const&
|
Chris@16
|
36 > super_t;
|
Chris@101
|
37
|
Chris@16
|
38 public:
|
Chris@16
|
39 generator_iterator() {}
|
Chris@16
|
40 generator_iterator(Generator* g) : m_g(g), m_value((*m_g)()) {}
|
Chris@16
|
41
|
Chris@16
|
42 void increment()
|
Chris@16
|
43 {
|
Chris@16
|
44 m_value = (*m_g)();
|
Chris@16
|
45 }
|
Chris@16
|
46
|
Chris@16
|
47 const typename Generator::result_type&
|
Chris@16
|
48 dereference() const
|
Chris@16
|
49 {
|
Chris@16
|
50 return m_value;
|
Chris@16
|
51 }
|
Chris@16
|
52
|
Chris@16
|
53 bool equal(generator_iterator const& y) const
|
Chris@16
|
54 {
|
Chris@16
|
55 return this->m_g == y.m_g && this->m_value == y.m_value;
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 private:
|
Chris@16
|
59 Generator* m_g;
|
Chris@16
|
60 typename Generator::result_type m_value;
|
Chris@16
|
61 };
|
Chris@16
|
62
|
Chris@16
|
63 template<class Generator>
|
Chris@16
|
64 struct generator_iterator_generator
|
Chris@16
|
65 {
|
Chris@16
|
66 typedef generator_iterator<Generator> type;
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69 template <class Generator>
|
Chris@16
|
70 inline generator_iterator<Generator>
|
Chris@16
|
71 make_generator_iterator(Generator & gen)
|
Chris@16
|
72 {
|
Chris@16
|
73 typedef generator_iterator<Generator> result_t;
|
Chris@16
|
74 return result_t(&gen);
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@101
|
77 } // namespace iterators
|
Chris@101
|
78
|
Chris@101
|
79 using iterators::generator_iterator;
|
Chris@101
|
80 using iterators::generator_iterator_generator;
|
Chris@101
|
81 using iterators::make_generator_iterator;
|
Chris@101
|
82
|
Chris@16
|
83 } // namespace boost
|
Chris@16
|
84
|
Chris@16
|
85 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
|